-
Notifications
You must be signed in to change notification settings - Fork 697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SEDONA-333] Implement ST_GeomFromEWKT #937
Changes from 9 commits
8d1f9c8
4ea2cda
e35222a
8c1520e
b16fe07
1abc5c5
e4b4408
ebf36be
9abcbbc
1fbd46d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,6 +230,26 @@ Output: | |
POINT(40.7128 -74.006) | ||
``` | ||
|
||
## ST_GeomFromEWKT | ||
|
||
Introduction: Construct a Geometry from OGC Extended WKT | ||
|
||
Format: | ||
`ST_GeomFromEWKT (EWkt:string)` | ||
|
||
Since: `v1.5.0` | ||
|
||
SQL example: | ||
```sql | ||
SELECT ST_GeomFromEWKT('SRID=4269;POINT(40.7128 -74.0060)') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please print the result using ST_AsEWKT or ST_AsText . This will print SRID |
||
``` | ||
|
||
Output: | ||
|
||
``` | ||
POINT(40.7128 -74.006) | ||
``` | ||
|
||
## ST_LineFromText | ||
|
||
Introduction: Construct a LineString from Text | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
"ST_GeomFromText", | ||
"ST_GeomFromWKB", | ||
"ST_GeomFromWKT", | ||
"ST_GeomFromEWKT", | ||
"ST_LineFromText", | ||
"ST_LineStringFromText", | ||
"ST_Point", | ||
|
@@ -132,6 +133,17 @@ def ST_GeomFromWKT(wkt: ColumnOrName) -> Column: | |
""" | ||
return _call_constructor_function("ST_GeomFromWKT", wkt) | ||
|
||
@validate_argument_types | ||
def ST_GeomFromEWKT(ewkt: ColumnOrName) -> Column: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is not tested. |
||
"""Generate a geometry column from a OGC Extended Well-Known Text (WKT) string column. | ||
|
||
:param ewkt: OGC Extended WKT string column to generate from. | ||
:type ewkt: ColumnOrName | ||
:return: Geometry column representing the EWKT string. | ||
:rtype: Column | ||
""" | ||
return _call_constructor_function("ST_GeomFromEWKT", ewkt) | ||
|
||
|
||
@validate_argument_types | ||
def ST_LineFromText(wkt: ColumnOrName) -> Column: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,12 @@ def test_st_geom_from_wkt(self): | |
polygon_df.show(10) | ||
assert polygon_df.count() == 100 | ||
|
||
def test_st_geom_from_ewkt(self): | ||
input_df = self.spark.createDataFrame([("SRID=4269;LineString(1 2, 3 4)",)], ["ewkt"]) | ||
input_df.createOrReplaceTempView("input_ewkt") | ||
line_df = self.spark.sql("select ST_LineFromText(ewkt) as geom from input_ewkt") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is not using ST_GeomFromEWKT |
||
assert line_df.count() == 1 | ||
|
||
def test_st_geom_from_wkt_3d(self): | ||
input_df = self.spark.createDataFrame([ | ||
("Point(21 52 87)",), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,13 @@ class dataFrameAPITestScala extends TestBaseScala { | |
assert(actualResult.getSRID == 4326) | ||
} | ||
|
||
it("passed st_geomfromewkt") { | ||
val df = sparkSession.sql("SELECT ST_GeomFromEWKT('SRID=4269;POINT(0.0 1.0)')") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test didn't test the DataFrame API |
||
val actualResult = df.take(1)(0).get(0).asInstanceOf[Geometry] | ||
assert(actualResult.toText == "POINT (0 1)") | ||
assert(actualResult.getSRID == 4269) | ||
} | ||
|
||
it("passed st_geomfromtext") { | ||
val df = sparkSession.sql("SELECT 'POINT(0.0 1.0)' AS wkt").select(ST_GeomFromText("wkt")) | ||
val actualResult = df.take(1)(0).get(0).asInstanceOf[Geometry].toText() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add one more test case
SRID=4269;POINT (1 1)
(no space between semicolon and the wkt string)