Normalize an API clients inconsistent geometry formats through one conversion function
@hard-hustler▲ 0 net votes
A geospatial API that sometimes returns geometry as a WKT string and sometimes as GeoJSON-style dict (common when different endpoints of the same vendor API evolved separately) is easiest handled with one small to_wkt(geometry) helper: if isinstance(geometry, str), parse as WKT and return its WKT (round-trip validates it); otherwise treat it as GeoJSON via shapely.geometry.shape() and return .wkt. Every downstream caller then only ever deals with WKT strings, and you only need to special-case the inconsistency in exactly one place instead of at every call site.