jiayuasu commented on code in PR #1530:
URL: https://github.com/apache/sedona/pull/1530#discussion_r1695980865


##########
common/src/main/java/org/apache/sedona/common/Functions.java:
##########
@@ -664,11 +666,39 @@ public static byte[] asWKB(Geometry geometry) {
   }
 
   public static String asGeoJson(Geometry geometry) {
+    return asGeoJson(geometry, "simple");
+  }
+
+  public static String asGeoJson(Geometry geometry, String type) {
     if (geometry == null) {
       return null;
     }
+
     GeoJSONWriter writer = new GeoJSONWriter();
-    return writer.write(geometry).toString();
+    org.wololo.geojson.Geometry geoJson = writer.write(geometry);
+
+    switch (type.toLowerCase()) {
+      case "simple":
+        return geoJson.toString();
+
+      case "feature":
+        Map<String, Object> properties = new HashMap<>();
+        Feature feature = new Feature(geoJson, properties);
+        return feature.toString();
+
+      case "featurecollection":
+        List<Feature> features = new ArrayList<>();
+        features.add(new Feature(geoJson, new HashMap<>()));
+        FeatureCollection featureCollection =
+            new FeatureCollection(features.toArray(new Feature[0]));
+        return featureCollection.toString();
+
+      default:
+        throw new IllegalArgumentException(
+            "Unknown type: "
+                + type
+                + ". Valid types are: 'geometry', 'feature', 
'featurecollection'.");

Review Comment:
   Shouldn't this be `simple` instead of `geometry`?



##########
common/src/main/java/org/apache/sedona/common/Functions.java:
##########
@@ -664,11 +666,39 @@ public static byte[] asWKB(Geometry geometry) {
   }
 
   public static String asGeoJson(Geometry geometry) {
+    return asGeoJson(geometry, "simple");
+  }
+
+  public static String asGeoJson(Geometry geometry, String type) {
     if (geometry == null) {
       return null;
     }
+
     GeoJSONWriter writer = new GeoJSONWriter();
-    return writer.write(geometry).toString();
+    org.wololo.geojson.Geometry geoJson = writer.write(geometry);
+
+    switch (type.toLowerCase()) {
+      case "simple":
+        return geoJson.toString();
+
+      case "feature":
+        Map<String, Object> properties = new HashMap<>();
+        Feature feature = new Feature(geoJson, properties);
+        return feature.toString();
+
+      case "featurecollection":
+        List<Feature> features = new ArrayList<>();
+        features.add(new Feature(geoJson, new HashMap<>()));
+        FeatureCollection featureCollection =
+            new FeatureCollection(features.toArray(new Feature[0]));
+        return featureCollection.toString();
+
+      default:
+        throw new IllegalArgumentException(

Review Comment:
   Please add tests for this function



##########
docs/api/sql/Function.md:
##########
@@ -371,7 +371,17 @@ POINT ZM(1 1 1 1)
 
 Introduction: Return the [GeoJSON](https://geojson.org/) string representation 
of a geometry
 
-Format: `ST_AsGeoJSON (A: Geometry)`
+The type parameter (Since: `v1.6.1`) takes the following options -
+
+- "Simple" (default): Returns a simple GeoJSON geometry.

Review Comment:
   Can you add an example below for the Feature and FeatureCollection



-- 
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: issues-unsubscr...@sedona.apache.org

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

Reply via email to