Skip to content

Commit

Permalink
Debug add_tileset
Browse files Browse the repository at this point in the history
  • Loading branch information
docuracy committed Dec 28, 2024
1 parent 2fa7bfe commit d958d22
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tileserver/repository/api/utils/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ def build_attribution(citation_data: Dict[str, Any]) -> str:
return " ".join(attribution_parts)


def decimal_default(obj):
"""
Custom serialization for Decimal types.
Converts Decimal to float for JSON serialization.
"""
if isinstance(obj, Decimal):
return float(obj)
raise TypeError(f"Type {obj.__class__.__name__} not serializable")


def split_geojson(f, geojson_path, table_path):
"""
Streams GeoJSON data from a file, saving unmodified features to `geojson_path`
Expand All @@ -142,15 +152,15 @@ def split_geojson(f, geojson_path, table_path):
# Write unmodified feature to geojson_path
if not first_geojson_feature:
geojson_file.write(",\n")
geojson_file.write(json.dumps(feature))
geojson_file.write(json.dumps(feature, default=decimal_default))
first_geojson_feature = False

# Process and write reduced feature to table_path
if "geometry" in feature and feature["geometry"]:
feature["geometry"] = {"type": feature["geometry"].get("type")}
if not first_table_feature:
table_file.write(",\n")
table_file.write(json.dumps(feature))
table_file.write(json.dumps(feature, default=decimal_default))
first_table_feature = False

except ijson.common.JSONError as e:
Expand Down

0 comments on commit d958d22

Please sign in to comment.