Skip to content
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-238] Implement OGC GeometryType #873

Merged
merged 13 commits into from
Jun 27, 2023
Merged

[SEDONA-238] Implement OGC GeometryType #873

merged 13 commits into from
Jun 27, 2023

Conversation

yyy1000
Copy link
Contributor

@yyy1000 yyy1000 commented Jun 26, 2023

Did you read the Contributor Guide?

Is this PR related to a JIRA ticket?

What changes were proposed in this PR?

Add ST_Dimension function to sedona-common, sedona-sql, sedona-flink, and the dataframe/python API.

How was this patch tested?

  1. Comprehensive unit tests in sedona-common
  2. Integration unit tests in sedona-sql, sedona-flink, and python.

Did this PR include necessary documentation updates?

  • Yes, I have updated the documentation update.

@@ -120,6 +121,16 @@

_call_st_function = partial(call_sedona_function, "st_functions")

@validate_argument_types
def GeometryType(geometry: ColumnOrName):
"""Return the type of the geometry as a string.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add measured geometry explanation in the documentation

@@ -1,3 +1,25 @@
## GeometryType

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add measured geometry explanation in the documentation along with examples

@@ -1,3 +1,25 @@
## GeometryType

Introduction: Returns the type of the geometry as a string. Eg: 'LINESTRING', 'POLYGON', 'MULTIPOINT', etc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add measured geometry explanation in the documentation along with examples

@@ -1078,6 +1078,34 @@ public void affine2DHybridGeomCollection() {
assertEquals(expectedPolygon2.toText(), actualGeomCollection.getGeometryN(0).getGeometryN(1).getGeometryN(1).toText());
}

@Test
public void geometryTypeWithMeasured() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a static object GEOMETRY_FACTORY to create geometries, there's no need to created new GeometryFactory() objects during the tests.
Please use GEOMETRY_FACTORY here


public static Boolean isMeasuredGeometry(Geometry geom) {
Coordinate[] coordinates = geom.getCoordinates();
GeometryFactory geometryFactory = new GeometryFactory();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sedona will not support creating geometryCollections with hybrid dimensions. Hence, to check for measure availability, it is better to poll 1 coordinate using getCoordinate, and check for presence of M by checking !Double.isNan(coordinate.getM()). This avoids having to create a geometryFactory, and a coordinate sequence everytime.

String expected3 = "LINESTRINGM";
String actual3 = Functions.geometryTypeWithMeasured(measuredLineString);
assertEquals(expected3, actual3);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked for XYZM coordinate geometries? I see that PostGIS does not implement that properly even though documentation says otherwise.
Does our function return say POINTM for POINT with XYZM coordinates? Please add testcases testing that

Copy link
Contributor Author

@yyy1000 yyy1000 Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our function can return POINTM for POINT with XYZM coordinates. But it seems that PostGIS can't return that:

postgres=# SELECT GeometryType(ST_GeomFromText('POINTM(0 0 1 0)'));
ERROR:  can not mix dimensionality in a geometry
HINT:  "POINTM(0 0 1 0)" <-- parse error at position 20 within geometry

Should I need to add test for this file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try POINT (0 0 1 0) or POINT ZM (0 0 1 0) on PostGIS, they dont throw error, but return POINT.

In our case, yes please add test cases testing XYZM

// Create a linestring with measure value
CoordinateXYM[] coordsLineString = new CoordinateXYM[] {new CoordinateXYM(1, 2, 3), new CoordinateXYM(4, 5, 6)};
LineString measuredLineString = new GeometryFactory().createLineString(coordsLineString);
String expected3 = "LINESTRINGM";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add test case testing geometry collections

@jiayuasu jiayuasu added this to the sedona-1.5.0 milestone Jun 27, 2023
@jiayuasu jiayuasu merged commit a768abd into apache:master Jun 27, 2023
39 checks passed
@yyy1000 yyy1000 deleted the dev branch June 28, 2023 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants