Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add category value to xml output and more JOSM compatibilities fixes #2389

Merged
merged 9 commits into from
Aug 19, 2024
26 changes: 19 additions & 7 deletions scripts/convert_xml.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import io
import xml.etree.cElementTree as ET
from shapely.geometry import shape, Polygon, MultiPolygon
from shapely import get_num_geometries, get_num_coordinates

root = ET.Element("imagery")
root = ET.Element("imagery", {"xmlns" :"http://josm.openstreetmap.de/maps-1.0"})

sources = []
for file in sys.argv[1:]:
Expand All @@ -19,14 +20,20 @@ def add_source(source):
name = ET.SubElement(entry, "name")
name.text = props["name"]

name = ET.SubElement(entry, "id")
name.text = props["id"]
id = ET.SubElement(entry, "id")
id.text = props["id"]

type = ET.SubElement(entry, "type")
type.text = props["type"]

url = ET.SubElement(entry, "url")
url.text = props["url"]

category = ET.SubElement(entry, "category")
if "category" in props:
category.text = props["category"]
else:
category.text = "photo"

if props.get("overlay"):
entry.set("overlay", "true")
Expand Down Expand Up @@ -70,7 +77,7 @@ def add_source(source):
icon = ET.SubElement(entry, "icon")
icon.text = props["icon"]

if "country_code" in props:
if "country_code" in props and props["country_code"].upper() not in ["XN", "ZZ"]:
country_code = ET.SubElement(entry, "country-code")
country_code.text = props["country_code"]

Expand All @@ -81,14 +88,15 @@ def add_source(source):
if "description" in props:
description = ET.SubElement(entry, "description")
description.text = props["description"]
description.set("lang", "en")

if "min_zoom" in props:
min_zoom = ET.SubElement(entry, "min-zoom")
min_zoom.text = str(props["min_zoom"])

if "max_zoom" in props:
max_zoom = ET.SubElement(entry, "max-zoom")
max_zoom.text = str(props["max_zoom"])
max_zoom.text = str(min(24, props["max_zoom"]))

geometry = source.get("geometry")
if geometry:
Expand All @@ -105,14 +113,18 @@ def coord_str(coord):
bounds.set("max-lon", coord_str(maxx))
bounds.set("max-lat", coord_str(maxy))

if isinstance(geom, Polygon):
if isinstance(geom, Polygon) and get_num_coordinates(geom) <= 999:
shape_element = ET.SubElement(bounds, "shape")
for lon, lat in geom.exterior.coords:
point = ET.SubElement(shape_element, "point")
point.set("lon", coord_str(lon))
point.set("lat", coord_str(lat))

if isinstance(geom, MultiPolygon):
if isinstance(geom, MultiPolygon) and get_num_geometries(geom) <= 100:
# check size of polygons first
for poly in geom.geoms:
if get_num_coordinates(poly) > 999:
return
for poly in geom.geoms:
shape_element = ET.SubElement(bounds, "shape")
for lon, lat in poly.exterior.coords:
Expand Down
Loading