Kontinuation commented on code in PR #2283:
URL: https://github.com/apache/sedona/pull/2283#discussion_r2278006575


##########
common/src/main/java/org/apache/sedona/common/geography/Constructors.java:
##########
@@ -70,6 +70,48 @@ public static Geography geogCollFromText(String wkt, int 
srid) throws ParseExcep
     return geogFromWKT(wkt, srid);
   }
 
+  public static Geography tryToGeography(String geogString) {
+    try {
+      return toGeography(geogString);
+    } catch (Exception e) {
+      return null;
+    }
+  }
+
+  public static Geography toGeography(String geogString) throws ParseException 
{
+    if (geogString == null || geogString.trim().isEmpty()) {
+      return null;
+    }
+    geogString = geogString.trim();
+
+    // EWKT format (e.g., "SRID=4326;POINT(...)")
+    if (geogString.toUpperCase().startsWith("SRID")) {
+      return Constructors.geogFromEWKT(geogString);
+    }
+    // WKB hex string (only hex digits)
+    if (isHex(geogString)) {
+      byte[] wkbBytes = WKBReader.hexToBytes(geogString);
+      return Constructors.geogFromWKB(wkbBytes);
+    }
+    // GeoHash (short alphanumeric string without spaces)
+    if (isGeoHash(geogString)) {
+      return Constructors.geogFromGeoHash(geogString, 16);
+    }

Review Comment:
   I'm not sure whether we should support GeoHash. A GeoHash value could happen 
to only contain hex characters, we'll interpret such data as WKB hex string and 
get errors or silently get unwanted data.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to