You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "daveboutcher (via GitHub)" <gi...@apache.org> on 2023/04/27 12:44:43 UTC

[GitHub] [superset] daveboutcher commented on a diff in pull request #23814: fix(ocient): convert pyocient GIS data types to geoJSON

daveboutcher commented on code in PR #23814:
URL: https://github.com/apache/superset/pull/23814#discussion_r1179095664


##########
superset/db_engine_specs/ocient.py:
##########
@@ -84,39 +84,87 @@ def _to_hex(data: bytes) -> str:
     return data.hex()
 
 
-def _polygon_to_json(polygon: Any) -> str:
+def _wkt_to_geoJSON(geo_as_wkt: Any) -> Any:
+    """
+    Converts pyocient geometry objects to their geoJSON representation.
+
+    :param geo_as_wkt: the GIS object in WKT format
+    :returns: the geoJSON encoding of `geo`
+    """
+    import geojson
+    from shapely import wkt
+
+    geo = wkt.loads(geo_as_wkt)
+    return geojson.Feature(geometry=geo, properties={})
+
+
+def _point_list_to_wkt(points: Any) -> str:
     """
-    Converts the _STPolygon object into its JSON representation.
+    Converts the list of pyocient._STPoint elements to a WKT LineString.
 
-    :param data: the polygon object
-    :returns: JSON representation of the polygon
+    :param points: the list of pyocient._STPoint objects
+    :returns: WKT LineString
     """
-    json_value = f"{str([[p.long, p.lat] for p in polygon.exterior])}"
-    if polygon.holes:
-        for hole in polygon.holes:
-            json_value += f", {str([[p.long, p.lat] for p in hole])}"
-        json_value = f"[{json_value}]"
-    return json_value
+    coords = [f"{p.long} {p.lat}" for p in points]
+    return f"LINESTRING({', '.join(coords)})"
 
 
-def _linestring_to_json(linestring: Any) -> str:
+def _point_to_geoJSON(point: Any) -> Any:
     """
-    Converts the _STLinestring object into its JSON representation.
+    Converts the pyocient._STPolygon object to the geoJSON format
 
-    :param data: the linestring object
-    :returns: JSON representation of the linestring
+    :param point: the pyocient._STPoint instance
+    :returns: the geoJSON encoding of this point
     """
-    return f"{str([[p.long, p.lat] for p in linestring.points])}"
+    wkt_point = str(point)
+    return _wkt_to_geoJSON(wkt_point)
+
+
+def _linestring_to_geoJSON(linestring: Any) -> Any:

Review Comment:
   Why `Any`?  doesn't this take an STLinesTring and produce a known type?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org