diff --git a/original data/Lake/Addresspoints.zip b/original data/Lake/Addresspoints.zip index 34d1672..db28d7b 100644 Binary files a/original data/Lake/Addresspoints.zip and b/original data/Lake/Addresspoints.zip differ diff --git a/original data/Sumter/Addresses8_19.zip b/original data/Sumter/Addresses8_19.zip deleted file mode 100644 index fb2ae55..0000000 Binary files a/original data/Sumter/Addresses8_19.zip and /dev/null differ diff --git a/original data/Sumter/RoadCenterlines8_19.zip b/original data/Sumter/RoadCenterlines8_19.zip deleted file mode 100644 index e530f61..0000000 Binary files a/original data/Sumter/RoadCenterlines8_19.zip and /dev/null differ diff --git a/shp-to-geojson.py b/shp-to-geojson.py index f886597..2334327 100644 --- a/shp-to-geojson.py +++ b/shp-to-geojson.py @@ -1,95 +1,5 @@ -import geopandas as gpd -from shapely.geometry import LineString, MultiLineString, Polygon, MultiPolygon -import pandas as pd - -df = gpd.read_file('original data/Sumter/RoadCenterlines_041125.shp.zip') #, crs=2237 NAD83 / Florida West (ftUS) +import geopandas +df = geopandas.read_file('original data/Sumter/RoadCenterlines_041125.shp.zip') df = df.to_crs(4326) # Convert to WGS 84 - -def convert_to_linestrings(geom): - """Convert any geometry to a list of LineStrings""" - linestrings = [] - - if geom is None or geom.is_empty: - return [] - - # If it's already a LineString, just return it - if isinstance(geom, LineString): - linestrings.append(geom) - - # If it's a MultiLineString, extract all LineStrings - elif isinstance(geom, MultiLineString): - for line in geom.geoms: - linestrings.append(line) - - # If it's a Polygon, convert boundary to LineString(s) - elif isinstance(geom, Polygon): - # Exterior boundary - if not geom.exterior.is_empty: - linestrings.append(LineString(geom.exterior.coords)) - # Interior boundaries (holes) - for interior in geom.interiors: - if not interior.is_empty: - linestrings.append(LineString(interior.coords)) - - # If it's a MultiPolygon, process each polygon - elif isinstance(geom, MultiPolygon): - for poly in geom.geoms: - # Exterior boundary - if not poly.exterior.is_empty: - linestrings.append(LineString(poly.exterior.coords)) - # Interior boundaries (holes) - for interior in poly.interiors: - if not interior.is_empty: - linestrings.append(LineString(interior.coords)) - - return linestrings - -def explode_linestring(linestring): - """Convert a LineString into individual segments""" - if linestring is None or linestring.is_empty: - return [] - - coords = list(linestring.coords) - segments = [] - - for i in range(len(coords) - 1): - segment = LineString([coords[i], coords[i + 1]]) - segments.append(segment) - - return segments - -# Convert all geometries to LineStrings first -df['linestrings'] = df.geometry.apply(convert_to_linestrings) - -# Explode to get one row per LineString -df_exploded = df.explode('linestrings') - -# Filter out rows with empty linestrings -df_exploded = df_exploded[df_exploded['linestrings'].notna()] -df_exploded = df_exploded[~df_exploded['linestrings'].apply(lambda x: x.is_empty if x is not None else True)] - -# Now explode each LineString into segments -df_exploded['segments'] = df_exploded['linestrings'].apply(explode_linestring) - -# Explode segments -df_final = df_exploded.explode('segments') - -# Filter out empty segments -df_final = df_final[df_final['segments'].notna()] -df_final = df_final[~df_final['segments'].apply(lambda x: x.is_empty if x is not None else True)] - -# Create final GeoDataFrame with segments as geometry -dfline = gpd.GeoDataFrame( - data=df_final.drop(['geometry', 'linestrings', 'segments'], axis=1), - geometry=df_final['segments'], - crs=df.crs -) - -# Reset index -dfline = dfline.reset_index(drop=True) - -# Save to GeoJSON -dfline.to_file('original data/Sumter/RoadCenterlines_041125.geojson', driver='GeoJSON') - -print(f"Converted {len(df)} original features to {len(dfline)} line segments") -print(f"Geometry types in output: {dfline.geometry.geom_type.value_counts()}") \ No newline at end of file +exploded = df.explode() +exploded.to_file('original data/Sumter/RoadCenterlines_041125.geojson', driver='GeoJSON') \ No newline at end of file diff --git a/threaded.py b/threaded.py index b60040c..b0ffaef 100644 --- a/threaded.py +++ b/threaded.py @@ -321,7 +321,9 @@ class RoadComparator: elif key == 'SpeedLimit': properties['maxspeed'] = f"{value} mph" if value is not None else None elif key == 'RoadClass': - if value.startswith('PRIMARY'): + if value is None: + properties['highway'] = 'residential' + elif value.startswith('PRIMARY'): properties['highway'] = 'trunk' elif value.startswith('MAJOR'): properties['highway'] = 'primary' @@ -431,7 +433,6 @@ class RoadComparator: if field in segment and pd.notna(segment[field]): road_name = str(segment[field]) break - if road_name not in removed_by_road: removed_by_road[road_name] = [] removed_by_road[road_name].append(length_feet)