Skip to content

Commit

Permalink
[SEDONA-533] Add ST_Polygonize (#1342)
Browse files Browse the repository at this point in the history
* [TASK-19] Add ST_Polygonize (#142)

* add ST_Polygonize

* add docs

* Fix python test

* Fix tests

* fix python test

* fix python test

* fix tests

* Update docs

* fix test

* fix test

* fix test

* fix test

* fix tests

* fix tests

* fix test

* fix test

* fix test

* fix test

* Fix test

* Fix typo

* Fix docs

---------

Co-authored-by: Jia Yu <jiayu@wherobots.com>

* Update ST_Polygonize version to OSS Sedona 1.6.0

---------

Co-authored-by: Pranav Toggi <prantogg@gmail.com>
  • Loading branch information
jiayuasu and prantogg committed Apr 18, 2024
1 parent 1a17933 commit d9153d2
Show file tree
Hide file tree
Showing 20 changed files with 274 additions and 0 deletions.
28 changes: 28 additions & 0 deletions common/src/main/java/org/apache/sedona/common/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.locationtech.jts.operation.distance3d.Distance3DOp;
import org.locationtech.jts.operation.linemerge.LineMerger;
import org.locationtech.jts.operation.overlay.snap.GeometrySnapper;
import org.locationtech.jts.operation.polygonize.Polygonizer;
import org.locationtech.jts.operation.valid.IsSimpleOp;
import org.locationtech.jts.operation.valid.IsValidOp;
import org.locationtech.jts.operation.valid.TopologyValidationError;
Expand Down Expand Up @@ -1661,4 +1662,31 @@ public static String isValidReason(Geometry geom, int flag) {
return error.toString();
}
}

/**
* This method takes a GeometryCollection and returns another GeometryCollection
* containing the polygons formed by the linework of a set of geometries.
* @param geometry A collection of Geometry objects that should contain only linestrings.
* @return A GeometryCollection containing the resultant polygons.
*/
public static Geometry polygonize(Geometry geometry) {
if (geometry == null || geometry.isEmpty()) {
return GEOMETRY_FACTORY.createGeometryCollection(null);
}

if (geometry instanceof GeometryCollection) {
Polygonizer polygonizer = new Polygonizer();

for (int i = 0; i < geometry.getNumGeometries(); i++) {
polygonizer.add(geometry.getGeometryN(i));
}

Collection polygons = polygonizer.getPolygons();
Geometry[] polyArray = (Geometry[]) polygons.toArray(new Geometry[0]);

return GEOMETRY_FACTORY.createGeometryCollection(polyArray);
} else {
return GEOMETRY_FACTORY.createGeometryCollection(null);
}
}
}
48 changes: 48 additions & 0 deletions common/src/test/java/org/apache/sedona/common/FunctionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,54 @@ public void spheroidArea() {
assertEquals(4.036497016235249E11, Spheroid.area(geometryCollection), 0.1);
}

@Test
public void pologonize() throws ParseException {
LineString line1 = GEOMETRY_FACTORY.createLineString(coordArray(180, 40, 30, 20, 20, 90));
LineString line2 = GEOMETRY_FACTORY.createLineString(coordArray(180, 40, 160, 160));
LineString line3 = GEOMETRY_FACTORY.createLineString(coordArray(80, 60, 120, 130, 150, 80));
LineString line4 = GEOMETRY_FACTORY.createLineString(coordArray(80, 60, 150, 80));
LineString line5 = GEOMETRY_FACTORY.createLineString(coordArray(20, 90, 70, 70, 80, 130));
LineString line6 = GEOMETRY_FACTORY.createLineString(coordArray(80, 130, 160, 160));
LineString line7 = GEOMETRY_FACTORY.createLineString(coordArray(20, 90, 20, 160, 70 ,190));
LineString line8 = GEOMETRY_FACTORY.createLineString(coordArray(70, 190, 80, 130));
LineString line9 = GEOMETRY_FACTORY.createLineString(coordArray(70, 190, 160, 160));

LineString line10 = GEOMETRY_FACTORY.createLineString(coordArray(0,0,0,1,0,2));
LineString line11 = GEOMETRY_FACTORY.createLineString(coordArray(4,2,4,1,4,0));
LineString line12 = GEOMETRY_FACTORY.createLineString(coordArray(4,0,3,0,2,0,1,0,0,0));
LineString line13 = GEOMETRY_FACTORY.createLineString(coordArray(2,0,2,1,2,2));
LineString line14 = GEOMETRY_FACTORY.createLineString(coordArray(2,2,2,3,2,4));
LineString line15 = GEOMETRY_FACTORY.createLineString(coordArray(0,2,1,2,2,2));
LineString line16 = GEOMETRY_FACTORY.createLineString(coordArray(2,2,3,2,4,2));
LineString line17 = GEOMETRY_FACTORY.createLineString(coordArray(0,2,1,3,2,4));
LineString line18 = GEOMETRY_FACTORY.createLineString(coordArray(2,4,3,3,4,2));

GeometryCollection geometryCollection1 = GEOMETRY_FACTORY.createGeometryCollection(new Geometry[] {line1, line2, line3, line4, line5, line6, line7, line8, line9});
GeometryCollection geometryCollection2 = GEOMETRY_FACTORY.createGeometryCollection(new Geometry[] {line10, line11, line12, line13, line14, line15, line16, line17, line18});
GeometryCollection geometryCollection3 = GEOMETRY_FACTORY.createGeometryCollection(new Geometry[] {line10, line11, line12, line13, line15, line16});
GeometryCollection geometryCollection4 = GEOMETRY_FACTORY.createGeometryCollection(new Geometry[] {line13, line14, line15, line16, line17, line18});

Geometry expected1 = geomFromEWKT("GEOMETRYCOLLECTION (POLYGON ((20 90, 20 160, 70 190, 80 130, 70 70, 20 90)), POLYGON ((20 90, 70 70, 80 130, 160 160, 180 40, 30 20, 20 90), (80 60, 150 80, 120 130, 80 60)), POLYGON ((70 190, 160 160, 80 130, 70 190)), POLYGON ((80 60, 120 130, 150 80, 80 60)))");
Geometry result1 = Functions.polygonize(geometryCollection1);
result1.normalize();
assertEquals(expected1, result1);

Geometry expected2 = geomFromEWKT("GEOMETRYCOLLECTION (POLYGON ((0 0, 0 1, 0 2, 1 2, 2 2, 3 2, 4 2, 4 1, 4 0, 3 0, 2 0, 1 0, 0 0)), POLYGON ((0 2, 1 3, 2 4, 2 3, 2 2, 1 2, 0 2)), POLYGON ((2 2, 2 3, 2 4, 3 3, 4 2, 3 2, 2 2)))");
Geometry result2 = Functions.polygonize(geometryCollection2);
result2.normalize();
assertEquals(expected2, result2);

Geometry expected3 = geomFromEWKT("GEOMETRYCOLLECTION (POLYGON ((0 0, 0 1, 0 2, 1 2, 2 2, 3 2, 4 2, 4 1, 4 0, 3 0, 2 0, 1 0, 0 0)))");
Geometry result3 = Functions.polygonize(geometryCollection3);
result3.normalize();
assertEquals(expected3, result3);

Geometry expected4 = geomFromEWKT("GEOMETRYCOLLECTION (POLYGON ((0 2, 1 3, 2 4, 2 3, 2 2, 1 2, 0 2)), POLYGON ((2 2, 2 3, 2 4, 3 3, 4 2, 3 2, 2 2)))");
Geometry result4 = Functions.polygonize(geometryCollection4);
result4.normalize();
assertEquals(expected4, result4);
}

@Test
public void spheroidLength() {
Point point = GEOMETRY_FACTORY.createPoint(new Coordinate(90, 0));
Expand Down
23 changes: 23 additions & 0 deletions docs/api/flink/Function.md
Original file line number Diff line number Diff line change
Expand Up @@ -2405,6 +2405,29 @@ Output:
POLYGON((75 29 1, 77 29 2, 77 29 3, 75 29 1))
```

## ST_Polygonize

Introduction: Generates a GeometryCollection composed of polygons that are formed from the linework of an input GeometryCollection. When the input does not contain any linework that forms a polygon, the function will return an empty GeometryCollection.

!!!note
`ST_Polygonize` function assumes that the input geometries form a valid and simple closed linestring that can be turned into a polygon. If the input geometries are not noded or do not form such linestrings, the resulting GeometryCollection may be empty or may not contain the expected polygons.

Format: `ST_Polygonize(geom: Geometry)`

Since: `v1.6.0`

Example:

```sql
SELECT ST_AsText(ST_Polygonize(ST_GeomFromEWKT('GEOMETRYCOLLECTION (LINESTRING (2 0, 2 1, 2 2), LINESTRING (2 2, 2 3, 2 4), LINESTRING (0 2, 1 2, 2 2), LINESTRING (2 2, 3 2, 4 2), LINESTRING (0 2, 1 3, 2 4), LINESTRING (2 4, 3 3, 4 2))')));
```

Output:

```
GEOMETRYCOLLECTION (POLYGON ((0 2, 1 3, 2 4, 2 3, 2 2, 1 2, 0 2)), POLYGON ((2 2, 2 3, 2 4, 3 3, 4 2, 3 2, 2 2)))
```

## ST_ReducePrecision

Introduction: Reduce the decimals places in the coordinates of the geometry to the given number of decimal places. The last decimal place will be rounded.
Expand Down
21 changes: 21 additions & 0 deletions docs/api/snowflake/vector-data/Function.md
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,27 @@ Output:
POLYGON((75 29 1, 77 29 2, 77 29 3, 75 29 1))
```

## ST_Polygonize

Introduction: Generates a GeometryCollection composed of polygons that are formed from the linework of an input GeometryCollection. When the input does not contain any linework that forms a polygon, the function will return an empty GeometryCollection.

!!!note
`ST_Polygonize` function assumes that the input geometries form a valid and simple closed linestring that can be turned into a polygon. If the input geometries are not noded or do not form such linestrings, the resulting GeometryCollection may be empty or may not contain the expected polygons.

Format: `ST_Polygonize(geom: Geometry)`

Example:

```sql
SELECT ST_AsText(ST_Polygonize(ST_GeomFromEWKT('GEOMETRYCOLLECTION (LINESTRING (2 0, 2 1, 2 2), LINESTRING (2 2, 2 3, 2 4), LINESTRING (0 2, 1 2, 2 2), LINESTRING (2 2, 3 2, 4 2), LINESTRING (0 2, 1 3, 2 4), LINESTRING (2 4, 3 3, 4 2))')));
```

Output:

```
GEOMETRYCOLLECTION (POLYGON ((0 2, 1 3, 2 4, 2 3, 2 2, 1 2, 0 2)), POLYGON ((2 2, 2 3, 2 4, 3 3, 4 2, 3 2, 2 2)))
```

## ST_ReducePrecision

Introduction: Reduce the decimals places in the coordinates of the geometry to the given number of decimal places. The last decimal place will be rounded. This function was called ST_PrecisionReduce in versions prior to v1.5.0.
Expand Down
23 changes: 23 additions & 0 deletions docs/api/sql/Function.md
Original file line number Diff line number Diff line change
Expand Up @@ -2413,6 +2413,29 @@ Output:
POLYGON((75 29 1, 77 29 2, 77 29 3, 75 29 1))
```

## ST_Polygonize

Introduction: Generates a GeometryCollection composed of polygons that are formed from the linework of an input GeometryCollection. When the input does not contain any linework that forms a polygon, the function will return an empty GeometryCollection.

!!!note
`ST_Polygonize` function assumes that the input geometries form a valid and simple closed linestring that can be turned into a polygon. If the input geometries are not noded or do not form such linestrings, the resulting GeometryCollection may be empty or may not contain the expected polygons.

Format: `ST_Polygonize(geom: Geometry)`

Since: `v1.6.0`

Example:

```sql
SELECT ST_AsText(ST_Polygonize(ST_GeomFromEWKT('GEOMETRYCOLLECTION (LINESTRING (2 0, 2 1, 2 2), LINESTRING (2 2, 2 3, 2 4), LINESTRING (0 2, 1 2, 2 2), LINESTRING (2 2, 3 2, 4 2), LINESTRING (0 2, 1 3, 2 4), LINESTRING (2 4, 3 3, 4 2))')));
```

Output:

```
GEOMETRYCOLLECTION (POLYGON ((0 2, 1 3, 2 4, 2 3, 2 2, 1 2, 0 2)), POLYGON ((2 2, 2 3, 2 4, 3 3, 4 2, 3 2, 2 2)))
```

## ST_ReducePrecision

Introduction: Reduce the decimals places in the coordinates of the geometry to the given number of decimal places. The last decimal place will be rounded. This function was called ST_PrecisionReduce in versions prior to v1.5.0.
Expand Down
1 change: 1 addition & 0 deletions flink/src/main/java/org/apache/sedona/flink/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public static UserDefinedFunction[] getFuncs() {
new Functions.ST_LineSubstring(),
new Functions.ST_MakeLine(),
new Functions.ST_Polygon(),
new Functions.ST_Polygonize(),
new Functions.ST_MakePolygon(),
new Functions.ST_MakeValid(),
new Functions.ST_MinimumBoundingCircle(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,14 @@ public Geometry eval(@DataTypeHint(value = "RAW", bridgedTo = org.locationtech.j
}
}

public static class ST_Polygonize extends ScalarFunction {
@DataTypeHint(value = "RAW", bridgedTo = org.locationtech.jts.geom.Geometry.class)
public Geometry eval(@DataTypeHint(value = "RAW", bridgedTo = org.locationtech.jts.geom.Geometry.class) Object o1) {
Geometry geom = (Geometry) o1;
return org.apache.sedona.common.Functions.polygonize(geom);
}
}

public static class ST_MakeValid extends ScalarFunction {
@DataTypeHint(value = "RAW", bridgedTo = org.locationtech.jts.geom.Geometry.class)
public Geometry eval(@DataTypeHint(value = "RAW", bridgedTo = org.locationtech.jts.geom.Geometry.class) Object o,
Expand Down
12 changes: 12 additions & 0 deletions flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.commons.lang3.tuple.Pair;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.planner.expressions.In;
import org.apache.sedona.flink.expressions.Constructors;
import org.apache.sedona.flink.expressions.Functions;
import org.apache.sedona.flink.expressions.FunctionsGeoTools;
import org.geotools.referencing.CRS;
Expand All @@ -28,6 +29,7 @@
import org.locationtech.jts.operation.buffer.BufferParameters;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import scala.collection.immutable.Stream;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -935,6 +937,16 @@ public void testPolygon() {
assertEquals(4236, result.getSRID());
}

@Test
public void testPolygonize() {
Table table = tableEnv.sqlQuery("SELECT ST_GeomFromEWKT('GEOMETRYCOLLECTION (LINESTRING (180 40, 30 20, 20 90), LINESTRING (180 40, 160 160), LINESTRING (80 60, 120 130, 150 80), LINESTRING (80 60, 150 80), LINESTRING (20 90, 70 70, 80 130), LINESTRING (80 130, 160 160), LINESTRING (20 90, 20 160, 70 190), LINESTRING (70 190, 80 130), LINESTRING (70 190, 160 160))') AS geom");
table = table.select(call(Functions.ST_Polygonize.class.getSimpleName(), $("geom")));
Geometry result = (Geometry) first(table).getField(0);
result.normalize();
String expected = "GEOMETRYCOLLECTION (POLYGON ((20 90, 20 160, 70 190, 80 130, 70 70, 20 90)), POLYGON ((20 90, 70 70, 80 130, 160 160, 180 40, 30 20, 20 90), (80 60, 150 80, 120 130, 80 60)), POLYGON ((70 190, 160 160, 80 130, 70 190)), POLYGON ((80 60, 120 130, 150 80, 80 60)))";
assertEquals(expected, result.toString());
}

@Test
public void testMakePolygon() {
Table table = tableEnv.sqlQuery("SELECT ST_GeomFromWKT('LINESTRING (0 0, 1 0, 1 1, 0 0)') AS line");
Expand Down
12 changes: 12 additions & 0 deletions python/sedona/sql/st_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"ST_LineSubstring",
"ST_MakeLine",
"ST_Polygon"
"ST_Polygonize"
"ST_MakePolygon",
"ST_MakeValid",
"ST_MinimumBoundingCircle",
Expand Down Expand Up @@ -996,6 +997,17 @@ def ST_Polygon(line_string: ColumnOrName, srid: ColumnOrNameOrNumber) -> Column:
"""
return _call_st_function("ST_Polygon", (line_string, srid))

@validate_argument_types
def ST_Polygonize(geometry: ColumnOrName) -> Column:
"""Generates a GeometryCollection composed of polygons that are formed from the linework of a set of input geometries.
:param geometry: input geometry of type GeometryCollection
:type geometry: ColumnOrName
:return: GeometryCollection geometry column created from the input geometry.
:rtype: Column
"""
return _call_st_function("ST_Polygonize", (geometry))

@validate_argument_types
def ST_MakePolygon(line_string: ColumnOrName, holes: Optional[ColumnOrName] = None) -> Column:
"""Create a polygon geometry from a linestring describing the exterior ring as well as an array of linestrings describing holes.
Expand Down
3 changes: 3 additions & 0 deletions python/tests/sql/test_dataframe_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
(stf.ST_MakeValid, ("geom",), "invalid_geom", "", "MULTIPOLYGON (((1 5, 3 3, 1 1, 1 5)), ((5 3, 7 5, 7 1, 5 3)))"),
(stf.ST_MakeLine, ("line1", "line2"), "two_lines", "", "LINESTRING (0 0, 1 1, 0 0, 3 2)"),
(stf.ST_Polygon, ("geom", 4236), "closed_linestring_geom", "", "POLYGON ((0 0, 1 0, 1 1, 0 0))"),
(stf.ST_Polygonize, ("geom",), "noded_linework", "ST_Normalize(geom)", "GEOMETRYCOLLECTION (POLYGON ((0 2, 1 3, 2 4, 2 3, 2 2, 1 2, 0 2)), POLYGON ((2 2, 2 3, 2 4, 3 3, 4 2, 3 2, 2 2)))"),
(stf.ST_MakePolygon, ("geom",), "closed_linestring_geom", "", "POLYGON ((0 0, 1 0, 1 1, 0 0))"),
(stf.ST_MinimumBoundingCircle, ("line", 8), "linestring_geom", "ST_ReducePrecision(geom, 2)", "POLYGON ((4.95 -0.49, 4.81 -0.96, 4.58 -1.39, 4.27 -1.77, 3.89 -2.08, 3.46 -2.31, 2.99 -2.45, 2.5 -2.5, 2.01 -2.45, 1.54 -2.31, 1.11 -2.08, 0.73 -1.77, 0.42 -1.39, 0.19 -0.96, 0.05 -0.49, 0 0, 0.05 0.49, 0.19 0.96, 0.42 1.39, 0.73 1.77, 1.11 2.08, 1.54 2.31, 2.01 2.45, 2.5 2.5, 2.99 2.45, 3.46 2.31, 3.89 2.08, 4.27 1.77, 4.58 1.39, 4.81 0.96, 4.95 0.49, 5 0, 4.95 -0.49))"),
(stf.ST_MinimumBoundingCircle, ("line", 2), "linestring_geom", "ST_ReducePrecision(geom, 2)", "POLYGON ((4.27 -1.77, 2.5 -2.5, 0.73 -1.77, 0 0, 0.73 1.77, 2.5 2.5, 4.27 1.77, 5 0, 4.27 -1.77))"),
Expand Down Expand Up @@ -467,6 +468,8 @@ def base_df(self, request):
return TestDataFrameAPI.spark.sql("SELECT array(ST_GeomFromWKT('POLYGON ((-3 -3, 3 -3, 3 3, -3 3, -3 -3))'), ST_GeomFromWKT('POLYGON ((-2 1, 2 1, 2 4, -2 4, -2 1))')) as polys")
elif request.param == "poly_and_line":
return TestDataFrameAPI.spark.sql("SELECT ST_GeomFromWKT('POLYGON((2.6 12.5, 2.6 20.0, 12.6 20.0, 12.6 12.5, 2.6 12.5 ))') as poly, ST_GeomFromWKT('LINESTRING (0.5 10.7, 5.4 8.4, 10.1 10.0)') as line")
elif request.param == "noded_linework":
return TestDataFrameAPI.spark.sql("SELECT ST_GeomFromWKT('GEOMETRYCOLLECTION (LINESTRING (2 0, 2 1, 2 2), LINESTRING (2 2, 2 3, 2 4), LINESTRING (0 2, 1 2, 2 2), LINESTRING (2 2, 3 2, 4 2), LINESTRING (0 2, 1 3, 2 4), LINESTRING (2 4, 3 3, 4 2))') as geom")
raise ValueError(f"Invalid base_df name passed: {request.param}")

def _id_test_configuration(val):
Expand Down
24 changes: 24 additions & 0 deletions python/tests/sql/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,30 @@ def test_st_polygon(self):
for actual, expected in result:
assert actual == expected

def test_st_polygonize(self):
# Given
geometry_df = self.spark.createDataFrame(
[
# Adding only the input that will result in a non-null polygon
["GEOMETRYCOLLECTION (LINESTRING (2 0, 2 1, 2 2), LINESTRING (2 2, 2 3, 2 4), LINESTRING (0 2, 1 2, 2 2), LINESTRING (2 2, 3 2, 4 2), LINESTRING (0 2, 1 3, 2 4), LINESTRING (2 4, 3 3, 4 2))", "GEOMETRYCOLLECTION (POLYGON ((0 2, 1 3, 2 4, 2 3, 2 2, 1 2, 0 2)), POLYGON ((2 2, 2 3, 2 4, 3 3, 4 2, 3 2, 2 2)))"]
]
).selectExpr("ST_GeomFromText(_1) AS geom", "_2 AS expected")

# When calling st_polygonize
geom_poly = geometry_df.withColumn("actual", expr("st_normalize(st_polygonize(geom))"))

# Then only based on closed linestring geom is created
geom_poly.filter("actual IS NOT NULL").selectExpr("ST_AsText(actual)", "expected"). \
show()
result = geom_poly.filter("actual IS NOT NULL").selectExpr("ST_AsText(actual)", "expected"). \
collect()

assert result.__len__() == 1

for actual, expected in result:
assert actual == expected


def test_st_make_polygon(self):
# Given
geometry_df = self.spark.createDataFrame(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,16 @@ public void test_ST_Polygon() {
);
}

@Test
public void test_ST_Polygonize() {
registerUDF("ST_Polygonize", byte[].class);
registerUDF("ST_Area", byte[].class);
verifySqlSingleRes(
"select sedona.ST_Area(sedona.ST_Polygonize(sedona.ST_GeomFromText('GEOMETRYCOLLECTION (LINESTRING (2 0, 2 1, 2 2), LINESTRING (2 2, 2 3, 2 4), LINESTRING (0 2, 1 2, 2 2), LINESTRING (2 2, 3 2, 4 2), LINESTRING (0 2, 1 3, 2 4), LINESTRING (2 4, 3 3, 4 2))')))",
4.0
);
}

@Test
public void test_ST_PrecisionReduce() {
registerUDF("ST_PrecisionReduce", byte[].class, int.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,16 @@ public void test_ST_Polygon() {
);
}

@Test
public void test_ST_Polygonize() {
registerUDFV2("ST_Polygonize", String.class);
registerUDFV2("ST_Area", String.class);
verifySqlSingleRes(
"select ST_Area(sedona.ST_Polygonize(ST_GeometryFromWKT('GEOMETRYCOLLECTION (LINESTRING (2 0, 2 1, 2 2), LINESTRING (2 2, 2 3, 2 4), LINESTRING (0 2, 1 2, 2 2), LINESTRING (2 2, 3 2, 4 2), LINESTRING (0 2, 1 3, 2 4), LINESTRING (2 4, 3 3, 4 2))')))",
4.0
);
}

@Test
public void test_ST_PrecisionReduce() {
registerUDFV2("ST_PrecisionReduce", String.class, int.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,15 @@ public static byte[] ST_Polygon(byte[] geometry, int srid) {
);
}

@UDFAnnotations.ParamMeta(argNames = {"geometry"})
public static byte[] ST_Polygonize(byte[] geometry) {
return GeometrySerde.serialize(
Functions.polygonize(
GeometrySerde.deserialize(geometry)
)
);
}

@UDFAnnotations.ParamMeta(argNames = {"minX", "minY", "maxX", "maxY"})
public static byte[] ST_PolygonFromEnvelope(double minX, double minY, double maxX, double maxY) {
return GeometrySerde.serialize(
Expand Down
Loading

0 comments on commit d9153d2

Please sign in to comment.