Final versions working for Lake and Sumter
This commit is contained in:
86
threaded.py
86
threaded.py
@@ -367,34 +367,59 @@ class RoadComparator:
|
||||
# 1. The uncovered portion is above minimum threshold, AND
|
||||
# 2. More than 10% of the road is uncovered
|
||||
if uncovered_ratio > 0.1:
|
||||
#uncovered_length >= min_length_deg and
|
||||
#uncovered_length >= min_length_deg and
|
||||
# Include entire original road with all original metadata
|
||||
|
||||
#
|
||||
# For Sumter County Roads
|
||||
#
|
||||
properties = {
|
||||
'surface': 'asphalt'
|
||||
}
|
||||
|
||||
for key, value in original_properties.items():
|
||||
if key == 'NAME':
|
||||
properties['name'] = titlecase(qgisfunctions.formatstreet(value,None,None)) if value is not None else None
|
||||
elif key == 'SpeedLimit':
|
||||
properties['maxspeed'] = f"{value} mph" if value is not None else None
|
||||
elif key == 'RoadClass':
|
||||
if value is None:
|
||||
properties['highway'] = 'residential'
|
||||
elif value.startswith('PRIMARY'):
|
||||
properties['highway'] = 'trunk'
|
||||
elif value.startswith('MAJOR'):
|
||||
properties['highway'] = 'primary'
|
||||
#elif value.startswith('MINOR'):
|
||||
else:
|
||||
properties['highway'] = 'residential'
|
||||
# else:
|
||||
# # Keep other properties as-is, or transform them as needed
|
||||
# properties[key] = value
|
||||
# Detect county format based on available fields
|
||||
is_lake_county = 'FullStreet' in original_properties
|
||||
is_sumter_county = 'NAME' in original_properties and 'RoadClass' in original_properties
|
||||
|
||||
if is_lake_county:
|
||||
# Lake County field mappings
|
||||
for key, value in original_properties.items():
|
||||
if key == 'FullStreet':
|
||||
properties['name'] = titlecase(qgisfunctions.formatstreet(value,None,None)) if value is not None else None
|
||||
elif key == 'SpeedLimit':
|
||||
properties['maxspeed'] = f"{value} mph" if value is not None else None
|
||||
elif key == 'NumberOfLa':
|
||||
try:
|
||||
num_value = int(float(value)) if value is not None else 0
|
||||
if num_value > 0:
|
||||
properties['lanes'] = str(num_value)
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
elif key == 'StreetClas':
|
||||
highway_type = qgisfunctions.gethighwaytype(value, None, None)
|
||||
properties['highway'] = highway_type if highway_type else 'residential'
|
||||
elif is_sumter_county:
|
||||
# Sumter County field mappings
|
||||
for key, value in original_properties.items():
|
||||
if key == 'NAME':
|
||||
properties['name'] = titlecase(qgisfunctions.formatstreet(value,None,None)) if value is not None else None
|
||||
elif key == 'SpeedLimit':
|
||||
properties['maxspeed'] = f"{value} mph" if value is not None else None
|
||||
elif key == 'RoadClass':
|
||||
if value is None:
|
||||
properties['highway'] = 'residential'
|
||||
elif value.startswith('PRIMARY'):
|
||||
properties['highway'] = 'trunk'
|
||||
elif value.startswith('MAJOR'):
|
||||
properties['highway'] = 'primary'
|
||||
else:
|
||||
properties['highway'] = 'residential'
|
||||
else:
|
||||
# Unknown format - try common field names
|
||||
name = original_properties.get('NAME') or original_properties.get('FullStreet') or original_properties.get('name')
|
||||
if name:
|
||||
properties['name'] = titlecase(qgisfunctions.formatstreet(name,None,None))
|
||||
speed = original_properties.get('SpeedLimit')
|
||||
if speed:
|
||||
properties['maxspeed'] = f"{speed} mph"
|
||||
properties['highway'] = 'residential'
|
||||
|
||||
added_roads.append({
|
||||
'geometry': geom,
|
||||
@@ -461,9 +486,20 @@ class RoadComparator:
|
||||
print("Saving results...")
|
||||
results_gdf = gpd.GeoDataFrame(all_results)
|
||||
|
||||
# Save to file with optimization
|
||||
results_gdf.to_file(output_path, driver='GeoJSON', engine='pyogrio')
|
||||
print(f"Results saved to: {output_path}")
|
||||
# Save to file with optimization, with fallback for locked files
|
||||
try:
|
||||
results_gdf.to_file(output_path, driver='GeoJSON', engine='pyogrio')
|
||||
print(f"Results saved to: {output_path}")
|
||||
except (PermissionError, OSError) as e:
|
||||
# File is locked, try with a timestamp suffix
|
||||
from datetime import datetime
|
||||
timestamp = datetime.now().strftime("%H%M%S")
|
||||
base = Path(output_path)
|
||||
fallback_path = str(base.parent / f"{base.stem}_{timestamp}{base.suffix}")
|
||||
print(f"Warning: Could not save to {output_path}: {e}")
|
||||
print(f"Saving to fallback: {fallback_path}")
|
||||
results_gdf.to_file(fallback_path, driver='GeoJSON', engine='pyogrio')
|
||||
print(f"Results saved to: {fallback_path}")
|
||||
|
||||
def print_summary(self, removed: List[Dict], added: List[Dict], file1_name: str, file2_name: str):
|
||||
"""Print a summary of the comparison results."""
|
||||
|
||||
Reference in New Issue
Block a user