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


##########
docs/api/sql/Raster-Operators/RS_CRS.md:
##########
@@ -0,0 +1,103 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+
+# RS_CRS
+
+Introduction: Returns the coordinate reference system (CRS) of a raster as a 
string in the specified format. If no format is specified, the CRS is returned 
in PROJJSON format. Returns null if the raster has no CRS defined.
+
+Format:
+
+```
+RS_CRS (raster: Raster)
+```
+
+```
+RS_CRS (raster: Raster, format: String)
+```
+
+Since: `v1.9.0`
+
+## Supported output formats
+
+| Format | Description |
+| :--- | :--- |
+| `'projjson'` | PROJJSON format (default). Modern, lossless, machine-readable 
JSON representation. |

Review Comment:
   Fixed.



##########
common/src/main/java/org/apache/sedona/common/raster/RasterAccessors.java:
##########
@@ -359,4 +362,67 @@ public static RasterMetadata rasterMetadata(GridCoverage2D 
raster) throws Factor
         (int) meta[10],
         (int) meta[11]);
   }
+
+  /**
+   * Returns the CRS of a raster as PROJJSON string.
+   *
+   * @param raster The input raster.
+   * @return The CRS definition as PROJJSON string, or null if no CRS is set.
+   */
+  public static String crs(GridCoverage2D raster) {
+    return crs(raster, "projjson");
+  }
+
+  /**
+   * Returns the CRS of a raster in the specified format.
+   *
+   * @param raster The input raster.
+   * @param format The desired output format: "projjson", "wkt2", "wkt1", or 
"proj".
+   * @return The CRS definition string in the requested format, or null if no 
CRS is set.
+   */
+  public static String crs(GridCoverage2D raster, String format) {
+    CoordinateReferenceSystem crsDef = raster.getCoordinateReferenceSystem();
+    if (crsDef instanceof DefaultEngineeringCRS) {
+      if (((DefaultEngineeringCRS) crsDef).isWildcard()) {
+        return null;
+      }
+    }
+
+    // Get WKT1 representation from GeoTools (native, no conversion needed)
+    String wkt1;
+    if (crsDef instanceof Formattable) {
+      wkt1 = ((Formattable) crsDef).toWKT(2, false);
+    } else {
+      wkt1 = crsDef.toWKT();
+    }
+
+    String fmt = format.toLowerCase(Locale.ROOT).trim();
+    if ("wkt1".equals(fmt) || "wkt".equals(fmt)) {

Review Comment:
   Fixed.



-- 
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