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