|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "bf2e1318", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "import requests\n", |
| 11 | + "import json\n", |
| 12 | + "import shapely\n", |
| 13 | + "from shapely.geometry import Polygon\n", |
| 14 | + "from shapely import wkt\n", |
| 15 | + "import folium\n", |
| 16 | + "import geojson" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "code", |
| 21 | + "execution_count": 2, |
| 22 | + "id": "4b8ebea8", |
| 23 | + "metadata": {}, |
| 24 | + "outputs": [], |
| 25 | + "source": [ |
| 26 | + "#Utility functions\n", |
| 27 | + "def visualize_field(wkt):\n", |
| 28 | + " try:\n", |
| 29 | + " p=shapely.wkt.loads(wkt)\n", |
| 30 | + " lon = p.centroid.xy[0][0]\n", |
| 31 | + " lat = p.centroid.xy[1][0]\n", |
| 32 | + " c = [lat,lon]\n", |
| 33 | + " gs=geojson.Feature(geometry=p, properties={}).geometry\n", |
| 34 | + " fgs = folium.GeoJson(gs)\n", |
| 35 | + "\n", |
| 36 | + " #create the folium map\n", |
| 37 | + " m = folium.Map(location=c,\n", |
| 38 | + " tiles='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',\n", |
| 39 | + " projection=4326,\n", |
| 40 | + " attr='Rendered by AgStack using ESRI & GeoEye Basemaps',\n", |
| 41 | + " max_zoom=22,\n", |
| 42 | + " zoom_start = 15) #<--- modify as needed\n", |
| 43 | + " #add the geojson to the map\n", |
| 44 | + " fgs.add_to(m)\n", |
| 45 | + " \n", |
| 46 | + " return m\n", |
| 47 | + " except Exception as e:\n", |
| 48 | + " print(e)\n", |
| 49 | + " " |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "code", |
| 54 | + "execution_count": 3, |
| 55 | + "id": "787e8d4c", |
| 56 | + "metadata": {}, |
| 57 | + "outputs": [], |
| 58 | + "source": [ |
| 59 | + "#sample field\n", |
| 60 | + "field_wkt = 'POLYGON ((145.31107 -17.09577, 145.31135 -17.09441, 145.30881 -17.09391, 145.30852 -17.09528, 145.31107 -17.09577))'" |
| 61 | + ] |
| 62 | + }, |
| 63 | + { |
| 64 | + "cell_type": "code", |
| 65 | + "execution_count": 4, |
| 66 | + "id": "02290384", |
| 67 | + "metadata": {}, |
| 68 | + "outputs": [ |
| 69 | + { |
| 70 | + "data": { |
| 71 | + "text/html": [ |
| 72 | + "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><span style=\"color:#565656\">Make this Notebook Trusted to load map: File -> Trust Notebook</span><iframe src=\"about:blank\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" data-html=%3C%21DOCTYPE%20html%3E%0A%3Chead%3E%20%20%20%20%0A%20%20%20%20%3Cmeta%20http-equiv%3D%22content-type%22%20content%3D%22text/html%3B%20charset%3DUTF-8%22%20/%3E%0A%20%20%20%20%0A%20%20%20%20%20%20%20%20%3Cscript%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20L_NO_TOUCH%20%3D%20false%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20L_DISABLE_3D%20%3D%20false%3B%0A%20%20%20%20%20%20%20%20%3C/script%3E%0A%20%20%20%20%0A%20%20%20%20%3Cstyle%3Ehtml%2C%20body%20%7Bwidth%3A%20100%25%3Bheight%3A%20100%25%3Bmargin%3A%200%3Bpadding%3A%200%3B%7D%3C/style%3E%0A%20%20%20%20%3Cstyle%3E%23map%20%7Bposition%3Aabsolute%3Btop%3A0%3Bbottom%3A0%3Bright%3A0%3Bleft%3A0%3B%7D%3C/style%3E%0A%20%20%20%20%3Cscript%20src%3D%22https%3A//cdn.jsdelivr.net/npm/leaflet%401.6.0/dist/leaflet.js%22%3E%3C/script%3E%0A%20%20%20%20%3Cscript%20src%3D%22https%3A//code.jquery.com/jquery-1.12.4.min.js%22%3E%3C/script%3E%0A%20%20%20%20%3Cscript%20src%3D%22https%3A//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js%22%3E%3C/script%3E%0A%20%20%20%20%3Cscript%20src%3D%22https%3A//cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.js%22%3E%3C/script%3E%0A%20%20%20%20%3Clink%20rel%3D%22stylesheet%22%20href%3D%22https%3A//cdn.jsdelivr.net/npm/leaflet%401.6.0/dist/leaflet.css%22/%3E%0A%20%20%20%20%3Clink%20rel%3D%22stylesheet%22%20href%3D%22https%3A//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css%22/%3E%0A%20%20%20%20%3Clink%20rel%3D%22stylesheet%22%20href%3D%22https%3A//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css%22/%3E%0A%20%20%20%20%3Clink%20rel%3D%22stylesheet%22%20href%3D%22https%3A//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css%22/%3E%0A%20%20%20%20%3Clink%20rel%3D%22stylesheet%22%20href%3D%22https%3A//cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css%22/%3E%0A%20%20%20%20%3Clink%20rel%3D%22stylesheet%22%20href%3D%22https%3A//cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/leaflet.awesome.rotate.min.css%22/%3E%0A%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cmeta%20name%3D%22viewport%22%20content%3D%22width%3Ddevice-width%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20initial-scale%3D1.0%2C%20maximum-scale%3D1.0%2C%20user-scalable%3Dno%22%20/%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cstyle%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23map_82a5f3b1a1bf4ef1b15c20dec5a8d890%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20position%3A%20relative%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20width%3A%20100.0%25%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20height%3A%20100.0%25%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20left%3A%200.0%25%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20top%3A%200.0%25%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C/style%3E%0A%20%20%20%20%20%20%20%20%0A%3C/head%3E%0A%3Cbody%3E%20%20%20%20%0A%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22folium-map%22%20id%3D%22map_82a5f3b1a1bf4ef1b15c20dec5a8d890%22%20%3E%3C/div%3E%0A%20%20%20%20%20%20%20%20%0A%3C/body%3E%0A%3Cscript%3E%20%20%20%20%0A%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20map_82a5f3b1a1bf4ef1b15c20dec5a8d890%20%3D%20L.map%28%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22map_82a5f3b1a1bf4ef1b15c20dec5a8d890%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20center%3A%20%5B-17.094842492946057%2C%20145.30993564555095%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20crs%3A%20L.CRS.EPSG3857%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20zoom%3A%2015%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20zoomControl%3A%20true%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20preferCanvas%3A%20false%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20projection%3A%204326%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%29%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20tile_layer_e9088b5ed89b45c1889e14dcce11abd6%20%3D%20L.tileLayer%28%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22https%3A//server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/%7Bz%7D/%7By%7D/%7Bx%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%22attribution%22%3A%20%22Rendered%20by%20AgStack%20using%20ESRI%20%5Cu0026%20GeoEye%20Basemaps%22%2C%20%22detectRetina%22%3A%20false%2C%20%22maxNativeZoom%22%3A%2022%2C%20%22maxZoom%22%3A%2022%2C%20%22minZoom%22%3A%200%2C%20%22noWrap%22%3A%20false%2C%20%22opacity%22%3A%201%2C%20%22subdomains%22%3A%20%22abc%22%2C%20%22tms%22%3A%20false%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%29.addTo%28map_82a5f3b1a1bf4ef1b15c20dec5a8d890%29%3B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%0A%0A%20%20%20%20%20%20%20%20function%20geo_json_251fd03b655341fe9ef79c1e825a79ae_onEachFeature%28feature%2C%20layer%29%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20layer.on%28%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%29%3B%0A%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20var%20geo_json_251fd03b655341fe9ef79c1e825a79ae%20%3D%20L.geoJson%28null%2C%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20onEachFeature%3A%20geo_json_251fd03b655341fe9ef79c1e825a79ae_onEachFeature%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%7D%29%3B%0A%0A%20%20%20%20%20%20%20%20function%20geo_json_251fd03b655341fe9ef79c1e825a79ae_add%20%28data%29%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20geo_json_251fd03b655341fe9ef79c1e825a79ae%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.addData%28data%29%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.addTo%28map_82a5f3b1a1bf4ef1b15c20dec5a8d890%29%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20geo_json_251fd03b655341fe9ef79c1e825a79ae_add%28%7B%22coordinates%22%3A%20%5B%5B%5B145.31107%2C%20-17.09577%5D%2C%20%5B145.31135%2C%20-17.09441%5D%2C%20%5B145.30881%2C%20-17.09391%5D%2C%20%5B145.30852%2C%20-17.09528%5D%2C%20%5B145.31107%2C%20-17.09577%5D%5D%5D%2C%20%22type%22%3A%20%22Polygon%22%7D%29%3B%0A%0A%20%20%20%20%20%20%20%20%0A%3C/script%3E onload=\"this.contentDocument.open();this.contentDocument.write( decodeURIComponent(this.getAttribute('data-html')));this.contentDocument.close();\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>" |
| 73 | + ], |
| 74 | + "text/plain": [ |
| 75 | + "<folium.folium.Map at 0x7facfc156d90>" |
| 76 | + ] |
| 77 | + }, |
| 78 | + "execution_count": 4, |
| 79 | + "metadata": {}, |
| 80 | + "output_type": "execute_result" |
| 81 | + } |
| 82 | + ], |
| 83 | + "source": [ |
| 84 | + "visualize_field(field_wkt)" |
| 85 | + ] |
| 86 | + }, |
| 87 | + { |
| 88 | + "cell_type": "code", |
| 89 | + "execution_count": null, |
| 90 | + "id": "c07ad14e", |
| 91 | + "metadata": {}, |
| 92 | + "outputs": [], |
| 93 | + "source": [] |
| 94 | + }, |
| 95 | + { |
| 96 | + "cell_type": "code", |
| 97 | + "execution_count": null, |
| 98 | + "id": "2ba1d47e", |
| 99 | + "metadata": {}, |
| 100 | + "outputs": [], |
| 101 | + "source": [] |
| 102 | + } |
| 103 | + ], |
| 104 | + "metadata": { |
| 105 | + "kernelspec": { |
| 106 | + "display_name": "Python 3 (ipykernel)", |
| 107 | + "language": "python", |
| 108 | + "name": "python3" |
| 109 | + }, |
| 110 | + "language_info": { |
| 111 | + "codemirror_mode": { |
| 112 | + "name": "ipython", |
| 113 | + "version": 3 |
| 114 | + }, |
| 115 | + "file_extension": ".py", |
| 116 | + "mimetype": "text/x-python", |
| 117 | + "name": "python", |
| 118 | + "nbconvert_exporter": "python", |
| 119 | + "pygments_lexer": "ipython3", |
| 120 | + "version": "3.8.0" |
| 121 | + } |
| 122 | + }, |
| 123 | + "nbformat": 4, |
| 124 | + "nbformat_minor": 5 |
| 125 | +} |
0 commit comments