Fix marshaling of shapefile geometry to GeoJSON

This commit is contained in:
XANTRONIX Industrial 2025-02-17 23:01:33 -05:00
parent cc3e058d2e
commit c9889388a3

View file

@ -5,19 +5,13 @@ import shapely
import shapefile import shapefile
from nexrad.db import DatabaseTable from nexrad.db import DatabaseTable
from nexrad.coord import COORD_SYSTEM
def parse_timestamp(timestamp: str): def parse_timestamp(timestamp: str):
return datetime.datetime.strptime(timestamp, '%Y%m%d%H%M%S').astimezone(datetime.UTC) return datetime.datetime.strptime(timestamp, '%Y%m%d%H%M%S').astimezone(datetime.UTC)
def shape_to_geojson(shape: shapefile.Shape): def shape_to_geojson(shape: shapefile.Shape):
ret = json.dumps({ return json.dumps(shape.__geo_interface__)
'type': 'Polygon',
'coordinates': shape.points
})
print(f"Got a kitty: {ret}")
return ret
class VTECType(enum.StrEnum): class VTECType(enum.StrEnum):
OPERATIONAL = 'O' OPERATIONAL = 'O'
@ -46,7 +40,7 @@ class VTEC(DatabaseTable):
} }
__columns_write__ = { __columns_write__ = {
'poly': 'GeomFromGeoJSON(:poly)' 'poly': 'SetSRID(GeomFromGeoJSON(:poly), {crs})'.format(crs=COORD_SYSTEM)
} }
__values_write__ = { __values_write__ = {