Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -70,35 +70,28 @@ def geocode(address):
|
|
70 |
location = geolocator.geocode(address)
|
71 |
lat, lon = location.latitude, location.longitude
|
72 |
return lat, lon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
def extract_vertices(gdf):
|
75 |
-
g = [i for i in gdf.geometry]
|
76 |
all_data = []
|
77 |
-
for
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
try:
|
87 |
-
for j in range(len(g[i])):
|
88 |
-
try:
|
89 |
-
x, y = g[i][j].exterior.coords.xy
|
90 |
-
except:
|
91 |
-
x, y = g[i][j].coords.xy
|
92 |
-
all_data2.append(pd.DataFrame({'Lat': y, 'Lon': x}))
|
93 |
-
df = pd.concat(all_data2)
|
94 |
-
except:
|
95 |
-
for i in g.geometry:
|
96 |
-
x=np.concatenate([poly.exterior.coords.xy[0] for poly in i.geoms])
|
97 |
-
y=np.concatenate([poly.exterior.coords.xy[1] for poly in i.geoms])
|
98 |
-
df = pd.DataFrame({'Lat': y,
|
99 |
-
'Lon': x, })
|
100 |
-
df['index_gdf'] = i
|
101 |
all_data.append(df)
|
|
|
102 |
return pd.concat(all_data).query('Lat==Lat').reset_index(drop=1).drop(columns='index_gdf')
|
103 |
|
104 |
|
|
|
70 |
location = geolocator.geocode(address)
|
71 |
lat, lon = location.latitude, location.longitude
|
72 |
return lat, lon
|
73 |
+
def extract_vertices_1(multipolygon):
|
74 |
+
vertices = []
|
75 |
+
for polygon in multipolygon.geoms: # Access the individual polygons
|
76 |
+
x, y = polygon.exterior.xy # Get exterior coordinates
|
77 |
+
vertices.extend(zip(x, y)) # Combine x and y coordinates
|
78 |
+
return vertices
|
79 |
+
|
80 |
+
|
81 |
|
82 |
def extract_vertices(gdf):
|
|
|
83 |
all_data = []
|
84 |
+
for idx, geom in enumerate(gdf.geometry):
|
85 |
+
if geom.geom_type == 'MultiPolygon':
|
86 |
+
vertices = extract_vertices_1(geom)
|
87 |
+
else:
|
88 |
+
x, y = geom.exterior.xy # Handle single polygons
|
89 |
+
vertices = list(zip(x, y))
|
90 |
+
|
91 |
+
df = pd.DataFrame(vertices, columns=['Lon', 'Lat'])
|
92 |
+
df['index_gdf'] = idx # Add index from GeoDataFrame
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
all_data.append(df)
|
94 |
+
|
95 |
return pd.concat(all_data).query('Lat==Lat').reset_index(drop=1).drop(columns='index_gdf')
|
96 |
|
97 |
|