File size: 17,656 Bytes
62dd0f3
 
99b822c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62dd0f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<iframe srcdoc=\"&lt;!DOCTYPE html&gt;\n",
       "&lt;html&gt;\n",
       "&lt;head&gt;\n",
       "    \n",
       "    &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;\n",
       "    \n",
       "        &lt;script&gt;\n",
       "            L_NO_TOUCH = false;\n",
       "            L_DISABLE_3D = false;\n",
       "        &lt;/script&gt;\n",
       "    \n",
       "    &lt;style&gt;html, body {width: 100%;height: 100%;margin: 0;padding: 0;}&lt;/style&gt;\n",
       "    &lt;style&gt;#map {position:absolute;top:0;bottom:0;right:0;left:0;}&lt;/style&gt;\n",
       "    &lt;script src=&quot;https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.js&quot;&gt;&lt;/script&gt;\n",
       "    &lt;script src=&quot;https://code.jquery.com/jquery-3.7.1.min.js&quot;&gt;&lt;/script&gt;\n",
       "    &lt;script src=&quot;https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js&quot;&gt;&lt;/script&gt;\n",
       "    &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.js&quot;&gt;&lt;/script&gt;\n",
       "    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.css&quot;/&gt;\n",
       "    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css&quot;/&gt;\n",
       "    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css&quot;/&gt;\n",
       "    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css&quot;/&gt;\n",
       "    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css&quot;/&gt;\n",
       "    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/leaflet.awesome.rotate.min.css&quot;/&gt;\n",
       "    \n",
       "            &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width,\n",
       "                initial-scale=1.0, maximum-scale=1.0, user-scalable=no&quot; /&gt;\n",
       "            &lt;style&gt;\n",
       "                #map_f1ce6eb921b4d7b11d49de3df8093d9e {\n",
       "                    position: relative;\n",
       "                    width: 100.0%;\n",
       "                    height: 100.0%;\n",
       "                    left: 0.0%;\n",
       "                    top: 0.0%;\n",
       "                }\n",
       "                .leaflet-container { font-size: 1rem; }\n",
       "            &lt;/style&gt;\n",
       "        \n",
       "    &lt;script src=&quot;https://cdn.jsdelivr.net/npm/[email protected]/Control.FullScreen.min.js&quot;&gt;&lt;/script&gt;\n",
       "    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/[email protected]/Control.FullScreen.css&quot;/&gt;\n",
       "    &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.2/leaflet.draw.js&quot;&gt;&lt;/script&gt;\n",
       "    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.2/leaflet.draw.css&quot;/&gt;\n",
       "    &lt;script src=&quot;https://cdn.jsdelivr.net/gh/ljagis/[email protected]/dist/leaflet-measure.min.js&quot;&gt;&lt;/script&gt;\n",
       "    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/gh/ljagis/[email protected]/dist/leaflet-measure.min.css&quot;/&gt;\n",
       "    &lt;script src=&quot;https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.js&quot;&gt;&lt;/script&gt;\n",
       "    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.css&quot;/&gt;\n",
       "&lt;/head&gt;\n",
       "&lt;body&gt;\n",
       "    \n",
       "    \n",
       "            &lt;div class=&quot;folium-map&quot; id=&quot;map_f1ce6eb921b4d7b11d49de3df8093d9e&quot; &gt;&lt;/div&gt;\n",
       "        \n",
       "&lt;/body&gt;\n",
       "&lt;script&gt;\n",
       "    \n",
       "    \n",
       "            var map_f1ce6eb921b4d7b11d49de3df8093d9e = L.map(\n",
       "                &quot;map_f1ce6eb921b4d7b11d49de3df8093d9e&quot;,\n",
       "                {\n",
       "                    center: [20.0, 0.0],\n",
       "                    crs: L.CRS.EPSG3857,\n",
       "                    zoom: 2,\n",
       "                    zoomControl: true,\n",
       "                    preferCanvas: false,\n",
       "                    drawExport: false,\n",
       "                    layersControl: true,\n",
       "                }\n",
       "            );\n",
       "            L.control.scale().addTo(map_f1ce6eb921b4d7b11d49de3df8093d9e);\n",
       "\n",
       "            \n",
       "\n",
       "        \n",
       "    \n",
       "            var tile_layer_625eed014e405c2ee851b9417f647dec = L.tileLayer(\n",
       "                &quot;https://tile.openstreetmap.org/{z}/{x}/{y}.png&quot;,\n",
       "                {&quot;attribution&quot;: &quot;\\u0026copy; \\u003ca href=\\&quot;https://www.openstreetmap.org/copyright\\&quot;\\u003eOpenStreetMap\\u003c/a\\u003e contributors&quot;, &quot;detectRetina&quot;: false, &quot;maxNativeZoom&quot;: 19, &quot;maxZoom&quot;: 24, &quot;minZoom&quot;: 0, &quot;noWrap&quot;: false, &quot;opacity&quot;: 1, &quot;subdomains&quot;: &quot;abc&quot;, &quot;tms&quot;: false}\n",
       "            );\n",
       "        \n",
       "    \n",
       "            tile_layer_625eed014e405c2ee851b9417f647dec.addTo(map_f1ce6eb921b4d7b11d49de3df8093d9e);\n",
       "        \n",
       "    \n",
       "            L.control.fullscreen(\n",
       "                {&quot;forceSeparateButton&quot;: false, &quot;position&quot;: &quot;topleft&quot;, &quot;title&quot;: &quot;Full Screen&quot;, &quot;titleCancel&quot;: &quot;Exit Full Screen&quot;}\n",
       "            ).addTo(map_f1ce6eb921b4d7b11d49de3df8093d9e);\n",
       "        \n",
       "    \n",
       "            var options = {\n",
       "              position: &quot;topleft&quot;,\n",
       "              draw: {},\n",
       "              edit: {},\n",
       "            }\n",
       "            // FeatureGroup is to store editable layers.\n",
       "            var drawnItems_draw_control_9dd44c4d87fa4af03ae29411df47a757 = new L.featureGroup().addTo(\n",
       "                map_f1ce6eb921b4d7b11d49de3df8093d9e\n",
       "            );\n",
       "            options.edit.featureGroup = drawnItems_draw_control_9dd44c4d87fa4af03ae29411df47a757;\n",
       "            var draw_control_9dd44c4d87fa4af03ae29411df47a757 = new L.Control.Draw(\n",
       "                options\n",
       "            ).addTo( map_f1ce6eb921b4d7b11d49de3df8093d9e );\n",
       "            map_f1ce6eb921b4d7b11d49de3df8093d9e.on(L.Draw.Event.CREATED, function(e) {\n",
       "                var layer = e.layer,\n",
       "                    type = e.layerType;\n",
       "                var coords = JSON.stringify(layer.toGeoJSON());\n",
       "                layer.on(&#x27;click&#x27;, function() {\n",
       "                    alert(coords);\n",
       "                    console.log(coords);\n",
       "                });\n",
       "                drawnItems_draw_control_9dd44c4d87fa4af03ae29411df47a757.addLayer(layer);\n",
       "             });\n",
       "            map_f1ce6eb921b4d7b11d49de3df8093d9e.on(&#x27;draw:created&#x27;, function(e) {\n",
       "                drawnItems_draw_control_9dd44c4d87fa4af03ae29411df47a757.addLayer(e.layer);\n",
       "            });\n",
       "            \n",
       "        \n",
       "    \n",
       "            var measure_control_cd8157b3b01df939f478306bae2624de = new L.Control.Measure(\n",
       "                {&quot;position&quot;: &quot;bottomleft&quot;, &quot;primaryAreaUnit&quot;: &quot;sqmeters&quot;, &quot;primaryLengthUnit&quot;: &quot;meters&quot;, &quot;secondaryAreaUnit&quot;: &quot;acres&quot;, &quot;secondaryLengthUnit&quot;: &quot;miles&quot;});\n",
       "            map_f1ce6eb921b4d7b11d49de3df8093d9e.addControl(measure_control_cd8157b3b01df939f478306bae2624de);\n",
       "\n",
       "            // Workaround for using this plugin with Leaflet&gt;=1.8.0\n",
       "            // https://github.com/ljagis/leaflet-measure/issues/171\n",
       "            L.Control.Measure.include({\n",
       "                _setCaptureMarkerIcon: function () {\n",
       "                    // disable autopan\n",
       "                    this._captureMarker.options.autoPanOnFocus = false;\n",
       "                    // default function\n",
       "                    this._captureMarker.setIcon(\n",
       "                        L.divIcon({\n",
       "                            iconSize: this._map.getSize().multiplyBy(2)\n",
       "                        })\n",
       "                    );\n",
       "                },\n",
       "            });\n",
       "\n",
       "        \n",
       "    \n",
       "\n",
       "            var geocoderOpts_geocoder_c3c41f24bdc9ab7c647dd5f6e71755d2 = {&quot;collapsed&quot;: true, &quot;defaultMarkGeocode&quot;: true, &quot;position&quot;: &quot;topleft&quot;, &quot;provider&quot;: &quot;nominatim&quot;, &quot;providerOptions&quot;: {}, &quot;zoom&quot;: 11};\n",
       "\n",
       "            // note: geocoder name should start with lowercase\n",
       "            var geocoderName_geocoder_c3c41f24bdc9ab7c647dd5f6e71755d2 = geocoderOpts_geocoder_c3c41f24bdc9ab7c647dd5f6e71755d2[&quot;provider&quot;];\n",
       "\n",
       "            var customGeocoder_geocoder_c3c41f24bdc9ab7c647dd5f6e71755d2 = L.Control.Geocoder[ geocoderName_geocoder_c3c41f24bdc9ab7c647dd5f6e71755d2 ](\n",
       "                geocoderOpts_geocoder_c3c41f24bdc9ab7c647dd5f6e71755d2[&#x27;providerOptions&#x27;]\n",
       "            );\n",
       "            geocoderOpts_geocoder_c3c41f24bdc9ab7c647dd5f6e71755d2[&quot;geocoder&quot;] = customGeocoder_geocoder_c3c41f24bdc9ab7c647dd5f6e71755d2;\n",
       "\n",
       "            L.Control.geocoder(\n",
       "                geocoderOpts_geocoder_c3c41f24bdc9ab7c647dd5f6e71755d2\n",
       "            ).on(&#x27;markgeocode&#x27;, function(e) {\n",
       "                var zoom = geocoderOpts_geocoder_c3c41f24bdc9ab7c647dd5f6e71755d2[&#x27;zoom&#x27;] || map_f1ce6eb921b4d7b11d49de3df8093d9e.getZoom();\n",
       "                map_f1ce6eb921b4d7b11d49de3df8093d9e.setView(e.geocode.center, zoom);\n",
       "            }).addTo(map_f1ce6eb921b4d7b11d49de3df8093d9e);\n",
       "\n",
       "        \n",
       "    \n",
       "            map_f1ce6eb921b4d7b11d49de3df8093d9e.fitBounds(\n",
       "                [[20, 0], [20, 0]],\n",
       "                {&quot;maxZoom&quot;: 2}\n",
       "            );\n",
       "        \n",
       "    \n",
       "            var macro_element_3831fc723f2cfc11a7f3230a34b4b9f6 = L.tileLayer.wms(\n",
       "                &quot;https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2016_Land_Cover_L48/wms?&quot;,\n",
       "                {&quot;attribution&quot;: &quot;&quot;, &quot;format&quot;: &quot;image/png&quot;, &quot;layers&quot;: &quot;NLCD_2016_Land_Cover_L48&quot;, &quot;styles&quot;: &quot;&quot;, &quot;transparent&quot;: true, &quot;version&quot;: &quot;1.1.1&quot;}\n",
       "            );\n",
       "        \n",
       "    \n",
       "            macro_element_3831fc723f2cfc11a7f3230a34b4b9f6.addTo(map_f1ce6eb921b4d7b11d49de3df8093d9e);\n",
       "        \n",
       "    \n",
       "            var layer_control_293101c4cdf231dcd55e9b691be121de_layers = {\n",
       "                base_layers : {\n",
       "                    &quot;openstreetmap&quot; : tile_layer_625eed014e405c2ee851b9417f647dec,\n",
       "                },\n",
       "                overlays :  {\n",
       "                    &quot;NLCD 2016 CONUS Land Cover&quot; : macro_element_3831fc723f2cfc11a7f3230a34b4b9f6,\n",
       "                },\n",
       "            };\n",
       "            let layer_control_293101c4cdf231dcd55e9b691be121de = L.control.layers(\n",
       "                layer_control_293101c4cdf231dcd55e9b691be121de_layers.base_layers,\n",
       "                layer_control_293101c4cdf231dcd55e9b691be121de_layers.overlays,\n",
       "                {&quot;autoZIndex&quot;: true, &quot;collapsed&quot;: true, &quot;position&quot;: &quot;topright&quot;}\n",
       "            ).addTo(map_f1ce6eb921b4d7b11d49de3df8093d9e);\n",
       "\n",
       "        \n",
       "&lt;/script&gt;\n",
       "&lt;/html&gt;\" width=\"100%\" height=\"600\"style=\"border:none !important;\" \"allowfullscreen\" \"webkitallowfullscreen\" \"mozallowfullscreen\"></iframe>"
      ],
      "text/plain": [
       "<leafmap.foliumap.Map at 0x7f2341d2cca0>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import leafmap as leafmap\n",
    "import leafmap.foliumap as leaf_folium\n",
    "import leafmap.toolbar\n",
    "# import leafmap.toolbar as toolbar\n",
    "\n",
    "tmp_map = leafmap.Map()\n",
    "\n",
    "Map = leaf_folium.Map()\n",
    "\n",
    "url = \"https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2016_Land_Cover_L48/wms?\"\n",
    "Map.add_wms_layer(\n",
    "    url,\n",
    "    layers=\"NLCD_2016_Land_Cover_L48\",\n",
    "    name=\"NLCD 2016 CONUS Land Cover\",\n",
    "    format=\"image/png\",\n",
    "    transparent=True,\n",
    ")\n",
    "# Map.add_legend(builtin_legend=\"NLCD\", draggable=False)\n",
    "Map.sandbox_path = \"/home/patel_zeel/bhuvan\"\n",
    "# toolbar.tool_template(Map)\n",
    "\n",
    "Map.toolbar = tmp_map.toolbar\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import geopandas as gpd\n",
    "from tqdm.notebook import tqdm\n",
    "from joblib import Parallel, delayed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e90c443ceec74b3e9bf223587db76898",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "  0%|          | 0/15 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://drive.google.com/open?id=1skBV8miaZN3gE2lPVnHQQG-n-RwbMH2d has 5 geometries\n",
      "https://drive.google.com/open?id=12OJzdi0RE5BDdMHzBovnYK_QhC5jIiSy has 6 geometries\n",
      "https://drive.google.com/open?id=1lge4nZKw7gxuDbQtM_v7D8eBHzUsLoBI has 3 geometries\n"
     ]
    }
   ],
   "source": [
    "files = \"\"\"https://drive.google.com/open?id=1QHbcxHRw3EQWsw5-UN6AUnVI-bhmhCQ5\n",
    "https://drive.google.com/open?id=1skBV8miaZN3gE2lPVnHQQG-n-RwbMH2d\n",
    "https://drive.google.com/open?id=1jyG_D6UudyAgicZjsvEfNLT_vNK1G3EB\n",
    "https://drive.google.com/open?id=1NxO399MvzufeT6-xigq3qi79psA40rkQ\n",
    "https://drive.google.com/open?id=1P2ZPMsxX82P12m460EBjpYMrdXUkZ05l\n",
    "https://drive.google.com/open?id=1Pc4sIYbRcu761fuXV5HVDG3EaqQC-uiz\n",
    "https://drive.google.com/open?id=1xskOyh888HrxCrB0Ue9bNGG6r1CvlH3J\n",
    "https://drive.google.com/open?id=12OJzdi0RE5BDdMHzBovnYK_QhC5jIiSy\n",
    "https://drive.google.com/open?id=18bDqdNIZOlp97GHpEOaYsCLSTML--aEA\n",
    "https://drive.google.com/open?id=1lge4nZKw7gxuDbQtM_v7D8eBHzUsLoBI\n",
    "https://drive.google.com/open?id=1XzzPh1q0uU3eMPoSC5stCLC7r8oMtgok\n",
    "https://drive.google.com/open?id=1JGmGCVYjdcUeFVmcoa7LcJE36HH0MGoF\n",
    "https://drive.google.com/open?id=1EPp6DZUGFcUESQSeMjQ9famygnWM-3BM\n",
    "https://drive.google.com/open?id=1XY7HbmY0fakAaZaxvUFF5UYk7Qovnit2\n",
    "https://drive.google.com/open?id=1VSVOpw9TFAxPKClHGPFXI_anBSHZOIi-\"\"\"\n",
    "\n",
    "df = pd.DataFrame(columns=['Failed URL', '# of geometries'])\n",
    "i = 0\n",
    "def get_gdf(link):\n",
    "    link = link.strip()\n",
    "    original_link = link\n",
    "    if link.startswith('https://drive.google.com/open?id='):\n",
    "        link = 'https://drive.google.com/uc?id=' + link.split('=')[-1]\n",
    "    gdf = gpd.read_file(link)\n",
    "    if len(gdf) != 1:\n",
    "        print(f\"{original_link} has {len(gdf)} geometries\")\n",
    "        # df.loc[i, ['Failed URL', '# of geometries']] = [original_link, len(gdf)]\n",
    "        # i += 1\n",
    "        \n",
    "# df.to_csv('failed_links.csv', index=False)\n",
    "_ = Parallel(n_jobs=32)(delayed(get_gdf)(link) for link in tqdm(files.split('\\n')))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "zeel_py310",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}