Update app.py
Browse files
app.py
CHANGED
@@ -82,9 +82,41 @@ def download_road_shapefile(coordinates_upper_left, coordinates_bottom_right):
|
|
82 |
|
83 |
return name if name else ref if ref else ''
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
gdf_edges = gdf_edges[gdf_edges['name'].notnull()]
|
86 |
# Apply the processing to create a combined name field
|
87 |
-
gdf_edges['
|
88 |
|
89 |
# Clean and abbreviate the display names
|
90 |
gdf_edges['display_name'] = gdf_edges['display_name'].apply(abbreviate_address)
|
@@ -95,7 +127,7 @@ def download_road_shapefile(coordinates_upper_left, coordinates_bottom_right):
|
|
95 |
gdf_edges = gdf_edges[gdf_edges['display_name'].str.len() > 0]
|
96 |
|
97 |
# Select final columns
|
98 |
-
gdf_edges = gdf_edges[['display_name', 'geometry']]
|
99 |
gdf_edges = gdf_edges.to_crs(epsg=4326)
|
100 |
|
101 |
# Save the file
|
|
|
82 |
|
83 |
return name if name else ref if ref else ''
|
84 |
|
85 |
+
# Process road names and numbers
|
86 |
+
def process_highway_name(row):
|
87 |
+
# Safely get values, converting NaN to empty string
|
88 |
+
#print(row['name'])
|
89 |
+
#name = row.get('name', '')
|
90 |
+
ref = row.get('ref', '')
|
91 |
+
highway = row.get('highway', '')
|
92 |
+
|
93 |
+
# Handle lists
|
94 |
+
#if isinstance(name, list): name = name[0] if name else ''
|
95 |
+
if isinstance(ref, list): ref = ref[0] if ref else None
|
96 |
+
if isinstance(highway, list): highway = highway[0] if highway else None
|
97 |
+
|
98 |
+
# Process interstate highways
|
99 |
+
if highway == 'motorway' and ref:
|
100 |
+
ref = ref.split(';')
|
101 |
+
try:
|
102 |
+
ref = ref[0]
|
103 |
+
except:
|
104 |
+
#print('here', ref[0])
|
105 |
+
ref = ref[0]
|
106 |
+
|
107 |
+
if ref.startswith('I'):
|
108 |
+
#print(ref)
|
109 |
+
#print(f"I-{ref.replace('I', '').strip()}")
|
110 |
+
return f"I-{ref.replace('I', '').strip()}"
|
111 |
+
return ref
|
112 |
+
|
113 |
+
|
114 |
+
return ref
|
115 |
+
|
116 |
+
|
117 |
gdf_edges = gdf_edges[gdf_edges['name'].notnull()]
|
118 |
# Apply the processing to create a combined name field
|
119 |
+
gdf_edges['highway'] = gdf_edges.apply(process_road_name, axis = 1)
|
120 |
|
121 |
# Clean and abbreviate the display names
|
122 |
gdf_edges['display_name'] = gdf_edges['display_name'].apply(abbreviate_address)
|
|
|
127 |
gdf_edges = gdf_edges[gdf_edges['display_name'].str.len() > 0]
|
128 |
|
129 |
# Select final columns
|
130 |
+
gdf_edges = gdf_edges[['display_name', 'highway', 'geometry']]
|
131 |
gdf_edges = gdf_edges.to_crs(epsg=4326)
|
132 |
|
133 |
# Save the file
|