Skip to content

Commit

Permalink
add constructor function signatures to accept SRIDs, fix docs to add …
Browse files Browse the repository at this point in the history
…the new signature and remove redundant docs
  • Loading branch information
furqaankhan committed Aug 15, 2024
1 parent 43cab48 commit da8a7eb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 72 deletions.
52 changes: 14 additions & 38 deletions docs/api/flink/Constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ Introduction: Construct a Geometry from WKT. Alias of [ST_GeomFromWKT](#st_geom
Format:
`ST_GeomFromText (Wkt: String)`

`ST_GeomFromText (Wkt: String, srid: Integer)`

Since: `v1.2.1`

Example:
Expand All @@ -249,42 +251,6 @@ Output:
POINT(40.7128 -74.006)
```

## ST_GeomFromEWKB

Introduction: Construct a Geometry from EWKB string or Binary. This function is an alias of [ST_GeomFromWKB](#st_geomfromwkb).

Format:

`ST_GeomFromEWKB (Wkb: String)`

`ST_GeomFromEWKB (Wkb: Binary)`

Since: `v1.6.1`

SQL Example

```sql
SELECT ST_GeomFromEWKB([01 02 00 00 00 02 00 00 00 00 00 00 00 84 D6 00 C0 00 00 00 00 80 B5 D6 BF 00 00 00 60 E1 EF F7 BF 00 00 00 80 07 5D E5 BF])
```

Output:

```
LINESTRING (-2.1047439575195312 -0.354827880859375, -1.49606454372406 -0.6676061153411865)
```

SQL Example

```sql
SELECT ST_asEWKT(ST_GeomFromEWKB('01010000a0e6100000000000000000f03f000000000000f03f000000000000f03f'))
```

Output:

```
SRID=4326;POINT Z(1 1 1)
```

## ST_GeomFromWKB

Introduction: Construct a Geometry from WKB string or Binary. This function also supports EWKB format.
Expand Down Expand Up @@ -340,6 +306,8 @@ Introduction: Construct a Geometry from WKT
Format:
`ST_GeomFromWKT (Wkt: String)`

`ST_GeomFromWKT (Wkt: String, srid: Integer)`

Since: `v1.2.0`

Example:
Expand Down Expand Up @@ -484,7 +452,11 @@ LINESTRING (-2.1047439575195312 -0.354827880859375, -1.49606454372406 -0.6676061

Introduction: Construct a MultiLineString from Text and Optional SRID

Format: `ST_MLineFromText (Text: String, Srid: Integer)`
Format:

`ST_MLineFromText (Wkt: String)`

`ST_MLineFromText (Wkt: String, Srid: Integer)`

Since: `1.3.1`

Expand Down Expand Up @@ -528,7 +500,11 @@ MULTIPOINT ((10 10), (20 20), (30 30))

Introduction: Construct a MultiPolygon from Text and Optional SRID

Format: `ST_MPolyFromText (Text: String, Srid: Integer)`
Format:

`ST_MPolyFromText (Wkt: String)`

`ST_MPolyFromText (Wkt: String, Srid: Integer)`

Since: `1.3.1`

Expand Down
34 changes: 0 additions & 34 deletions docs/api/snowflake/vector-data/Constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,40 +237,6 @@ Output:
POINT(40.7128 -74.006)
```

## ST_GeomFromEWKB

Introduction: Construct a Geometry from EWKB string or Binary. This function is an alias of [ST_GeomFromWKB](#st_geomfromwkb).

Format:

`ST_GeomFromEWKB (Wkb: String)`

`ST_GeomFromEWKB (Wkb: Binary)`

SQL Example

```sql
SELECT ST_GeomFromEWKB([01 02 00 00 00 02 00 00 00 00 00 00 00 84 D6 00 C0 00 00 00 00 80 B5 D6 BF 00 00 00 60 E1 EF F7 BF 00 00 00 80 07 5D E5 BF])
```

Output:

```
LINESTRING (-2.1047439575195312 -0.354827880859375, -1.49606454372406 -0.6676061153411865)
```

SQL Example

```sql
SELECT ST_asEWKT(ST_GeomFromEWKB('01010000a0e6100000000000000000f03f000000000000f03f000000000000f03f'))
```

Output:

```
SRID=4326;POINT Z(1 1 1)
```

## ST_GeomFromWKB

Introduction: Construct a Geometry from WKB string or Binary. This function also supports EWKB format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ public static class ST_GeomFromWKT extends ScalarFunction {
public Geometry eval(@DataTypeHint("String") String wktString) throws ParseException {
return org.apache.sedona.common.Constructors.geomFromWKT(wktString, 0);
}

@DataTypeHint(value = "RAW", bridgedTo = org.locationtech.jts.geom.Geometry.class)
public Geometry eval(@DataTypeHint("String") String wktString, @DataTypeHint("Int") Integer srid) throws ParseException {
return org.apache.sedona.common.Constructors.geomFromWKT(wktString, srid);
}
}

public static class ST_GeomFromEWKT extends ScalarFunction {
Expand Down Expand Up @@ -269,6 +274,11 @@ public static class ST_GeomFromText extends ScalarFunction {
public Geometry eval(@DataTypeHint("String") String wktString) throws ParseException {
return org.apache.sedona.common.Constructors.geomFromWKT(wktString, 0);
}

@DataTypeHint(value = "RAW", bridgedTo = org.locationtech.jts.geom.Geometry.class)
public Geometry eval(@DataTypeHint("String") String wktString, @DataTypeHint("Int") Integer srid) throws ParseException {
return org.apache.sedona.common.Constructors.geomFromWKT(wktString, srid);
}
}

public static class ST_GeomFromWKB extends ScalarFunction {
Expand Down
16 changes: 16 additions & 0 deletions flink/src/test/java/org/apache/sedona/flink/ConstructorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ public void testGeomFromWKT() {
$(polygonColNames[1]));
Row result = last(geomTable);
assertEquals(data.get(data.size() - 1).getField(0).toString(), result.getField(0).toString());

geomTable =
wktTable.select(
call(Constructors.ST_GeomFromWKT.class.getSimpleName(), $(polygonColNames[0]), 1111)
.as(polygonColNames[0]),
$(polygonColNames[1]));
int sridActual = (int) last(geomTable.select(call(Functions.ST_SRID.class.getSimpleName(), $(polygonColNames[0])))).getField(0);
assertEquals(1111, sridActual);
}

@Test
Expand Down Expand Up @@ -316,6 +324,14 @@ public void testGeomFromText() {
$(polygonColNames[1]));
Row result = last(geomTable);
assertEquals(data.get(data.size() - 1).getField(0).toString(), result.getField(0).toString());

geomTable =
wktTable.select(
call(Constructors.ST_GeomFromText.class.getSimpleName(), $(polygonColNames[0]), 1111)
.as(polygonColNames[0]),
$(polygonColNames[1]));
int sridActual = (int) last(geomTable.select(call(Functions.ST_SRID.class.getSimpleName(), $(polygonColNames[0])))).getField(0);
assertEquals(1111, sridActual);
}

@Test
Expand Down

0 comments on commit da8a7eb

Please sign in to comment.