From 5fd4223e361dc8b318d793c6989a46b3556e3799 Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Mon, 14 Jul 2025 20:08:23 -0700 Subject: [PATCH] update scripts --- download.py | 3 ++- threaded.py | 16 +++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/download.py b/download.py index 4700275..bd85c76 100644 --- a/download.py +++ b/download.py @@ -3,12 +3,13 @@ import json api = overpass.API() +# ~"^(motorway|trunk|primary|secondary|tertiary|residential|unclassified|motorway_link|trunk_link|primary_link|secondary_link|tertiary_link)$" res = api.get(""" area[name="Florida"]; rel[name="Sumter County"](area); map_to_area; ( - nwr[highway~"^(motorway|trunk|primary|secondary|tertiary|residential|unclassified|motorway_link|trunk_link|primary_link|secondary_link|tertiary_link)$"](area); + nwr[highway](area); ); (._;>;); """, responseformat="geojson") diff --git a/threaded.py b/threaded.py index ff70cb4..6b21739 100644 --- a/threaded.py +++ b/threaded.py @@ -12,6 +12,8 @@ Optimized for performance with parallel processing and spatial indexing. TODO: - put properties properly on removed roads, so they're visible in JOSM - handle polygons properly (on previous geojson step?) for circular roads +- ignore roads that aren't LIFECYCLE ACTV or Active +- include OneWay=Y """ import json @@ -19,7 +21,7 @@ import argparse from pathlib import Path from typing import List, Dict, Any, Tuple import geopandas as gpd -from shapely.geometry import LineString, MultiLineString, Point +from shapely.geometry import LineString, MultiLineString, Point, Polygon from shapely.ops import unary_union from shapely.strtree import STRtree import pandas as pd @@ -39,7 +41,7 @@ warnings.filterwarnings('ignore') import re def titlecase(s): return re.sub( - r"[A-Za-z]+('[A-Za-z]+)?", + r"[A-Za-z0-9]+('[A-Za-z0-9]+)?", lambda word: word.group(0).capitalize(), s) @@ -74,8 +76,8 @@ class RoadComparator: # Use pyogr engine for faster loading of large files gdf = gpd.read_file(filepath, engine='pyogrio') - # Filter only LineString and MultiLineString geometries - line_types = ['LineString', 'MultiLineString'] + # Filter only LineString, MultiLineString, and Polygon geometries + line_types = ['LineString', 'MultiLineString', 'Polygon'] gdf = gdf[gdf.geometry.type.isin(line_types)].copy() if len(gdf) == 0: @@ -206,7 +208,7 @@ class RoadComparator: if isinstance(geom, MultiLineString): lines = list(geom.geoms) else: - lines = [geom] + lines = [geom] # Polygon and Line can be accessed directly for line in lines: try: @@ -306,8 +308,8 @@ class RoadComparator: # Include the entire road if: # 1. The uncovered portion is above minimum threshold, AND - # 2. More than 50% of the road is uncovered - if uncovered_ratio > 0.5: + # 2. More than 10% of the road is uncovered + if uncovered_ratio > 0.1: #uncovered_length >= min_length_deg and # Include entire original road with all original metadata original_properties = dict(row.drop('geometry'))