adding sea polygons successful
This commit is contained in:
parent
ab270ebc9a
commit
cdabeb730b
2 changed files with 82 additions and 229 deletions
52
plot.py
52
plot.py
|
|
@ -6,6 +6,34 @@ import geopandas as gpd
|
|||
import matplotlib.pyplot as plt
|
||||
from pathlib import Path
|
||||
|
||||
def get_color(tags, geom_type):
|
||||
"""
|
||||
Determine the color based on the tags and geometry type.
|
||||
"""
|
||||
if isinstance(tags, dict):
|
||||
if "natural" in tags:
|
||||
if tags["natural"] == "water":
|
||||
return "blue" if geom_type == "Polygon" else "darkblue"
|
||||
if tags["natural"] in ["brush", "forest"]:
|
||||
return "darkgreen"
|
||||
if tags["natural"] == "coastline":
|
||||
return "red"
|
||||
if "landuse" in tags:
|
||||
if tags["landuse"] == "farmland":
|
||||
return "green"
|
||||
if tags["landuse"] in ["residential", "commercial"]:
|
||||
return "orange"
|
||||
if tags["landuse"] == "industrial":
|
||||
return "darkgrey"
|
||||
return "yellow"
|
||||
if "military" in tags:
|
||||
return "lightred"
|
||||
if "waterway" in tags:
|
||||
return "darkblue"
|
||||
if "railway" in tags:
|
||||
return "black"
|
||||
return "grey" # Default color
|
||||
|
||||
def plot_geometries(parquet_file: str, save_as: str):
|
||||
"""
|
||||
Plots the geometries inside a GeoParquet file and saves the image instead of showing it.
|
||||
|
|
@ -24,16 +52,28 @@ def plot_geometries(parquet_file: str, save_as: str):
|
|||
# Ensure it has a valid geometry column
|
||||
if "geometry" not in gdf.columns:
|
||||
raise ValueError("❌ No 'geometry' column found in the file.")
|
||||
|
||||
# Plot the geometries
|
||||
|
||||
# Drop rows with empty geometries
|
||||
gdf = gdf[gdf.geometry.notnull()]
|
||||
|
||||
# Create a figure
|
||||
fig, ax = plt.subplots(figsize=(8, 8))
|
||||
gdf.plot(ax=ax, edgecolor="black", facecolor="lightblue", alpha=0.5)
|
||||
|
||||
|
||||
# Classify colors efficiently
|
||||
gdf["color"] = gdf.apply(lambda row: get_color(row.tags, row.geometry.geom_type), axis=1)
|
||||
|
||||
# Separate by geometry types for efficient plotting
|
||||
for geom_type, sub_gdf in gdf.groupby(gdf.geometry.geom_type):
|
||||
sub_gdf.plot(ax=ax, edgecolor="black" if geom_type in ["Polygon", "MultiPolygon"] else None,
|
||||
facecolor=sub_gdf["color"] if geom_type in ["Polygon", "MultiPolygon"] else None,
|
||||
color=sub_gdf["color"] if geom_type in ["LineString", "MultiLineString"] else None,
|
||||
alpha=0.5, linewidth=2 if geom_type in ["LineString", "MultiLineString"] else None)
|
||||
|
||||
# Add labels
|
||||
ax.set_title(f"Geometries in {parquet_file}")
|
||||
ax.set_xlabel("Longitude")
|
||||
ax.set_ylabel("Latitude")
|
||||
|
||||
|
||||
# Save the figure instead of showing it
|
||||
plt.savefig(save_as, dpi=300)
|
||||
print(f"✅ Plot saved as {save_as}")
|
||||
|
|
@ -51,4 +91,4 @@ def main():
|
|||
print(f"❌ Error: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue