-
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-238] Implement OGC GeometryType #873
Changes from 11 commits
20142bf
03c1623
8a0eb59
cf58922
8931e2a
32a8ad6
62946eb
94f2694
0e4370d
bcb53af
291c08e
94738d2
eeb6847
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 |
---|---|---|
|
@@ -1078,6 +1078,34 @@ public void affine2DHybridGeomCollection() { | |
assertEquals(expectedPolygon2.toText(), actualGeomCollection.getGeometryN(0).getGeometryN(1).getGeometryN(1).toText()); | ||
} | ||
|
||
@Test | ||
public void geometryTypeWithMeasured() { | ||
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. There is already a static object GEOMETRY_FACTORY to create geometries, there's no need to created new GeometryFactory() objects during the tests. |
||
String expected = "POINT"; | ||
String actual = Functions.geometryTypeWithMeasured(GEOMETRY_FACTORY.createPoint(new Coordinate(10, 5))); | ||
assertEquals(expected, actual); | ||
|
||
// Create a point with measure value | ||
CoordinateXYM coords = new CoordinateXYM(2, 3, 4); | ||
Point measuredPoint = new GeometryFactory().createPoint(coords); | ||
String expected2 = "POINTM"; | ||
String actual2 = Functions.geometryTypeWithMeasured(measuredPoint); | ||
assertEquals(expected2, actual2); | ||
|
||
// 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"; | ||
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 add test case testing geometry collections |
||
String actual3 = Functions.geometryTypeWithMeasured(measuredLineString); | ||
assertEquals(expected3, actual3); | ||
|
||
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. Have you checked for XYZM coordinate geometries? I see that PostGIS does not implement that properly even though documentation says otherwise. 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. Our function can return POINTM for POINT with XYZM coordinates. But it seems that PostGIS can't return that:
Should I need to add test for this file? 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. 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 polygon with measure value | ||
CoordinateXYM[] coordsPolygon = new CoordinateXYM[] {new CoordinateXYM(0, 0, 0), new CoordinateXYM(1, 1, 0), new CoordinateXYM(0, 1, 0), new CoordinateXYM(0, 0, 0)}; | ||
Polygon measuredPolygon = new GeometryFactory().createPolygon(coordsPolygon); | ||
String expected4 = "POLYGONM"; | ||
String actual4 = Functions.geometryTypeWithMeasured(measuredPolygon); | ||
assertEquals(expected4, actual4); | ||
} | ||
|
||
@Test | ||
public void hausdorffDistanceDefaultGeom2D() throws Exception { | ||
Polygon polygon1 = GEOMETRY_FACTORY.createPolygon(coordArray3d(1, 0, 1, 1, 1, 2, 2, 1, 5, 2, 0, 1, 1, 0, 1)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,25 @@ | ||
## GeometryType | ||
|
||
Introduction: Returns the type of the geometry as a string. Eg: 'LINESTRING', 'POLYGON', 'MULTIPOINT', etc. | ||
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 add measured geometry explanation in the documentation along with examples |
||
|
||
Format: `GeometryType (A:geometry)` | ||
|
||
Since: `v1.5.0` | ||
|
||
Example: | ||
|
||
```sql | ||
SELECT GeometryType(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)')); | ||
``` | ||
|
||
Result: | ||
|
||
``` | ||
geometrytype | ||
-------------- | ||
LINESTRING | ||
``` | ||
|
||
## ST_3DDistance | ||
|
||
Introduction: Return the 3-dimensional minimum cartesian distance between A and B | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,25 @@ | ||
## GeometryType | ||
|
||
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 add measured geometry explanation in the documentation along with examples |
||
Introduction: Returns the type of the geometry as a string. Eg: 'LINESTRING', 'POLYGON', 'MULTIPOINT', etc. | ||
|
||
Format: `GeometryType (A:geometry)` | ||
|
||
Since: `v1.5.0` | ||
|
||
Example: | ||
|
||
```sql | ||
SELECT GeometryType(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)')); | ||
``` | ||
|
||
Result: | ||
|
||
``` | ||
geometrytype | ||
-------------- | ||
LINESTRING | ||
``` | ||
|
||
## ST_3DDistance | ||
|
||
Introduction: Return the 3-dimensional minimum cartesian distance between A and B | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
|
||
|
||
__all__ = [ | ||
"GeometryType", | ||
"ST_3DDistance", | ||
"ST_AddPoint", | ||
"ST_Area", | ||
|
@@ -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. | ||
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 add measured geometry explanation in the documentation |
||
|
||
:param geometry: Geometry column to calculate the dimension for. | ||
:type geometry: ColumnOrName | ||
:return: Type of geometry as a string column. | ||
:rtype: Column | ||
""" | ||
return _call_st_function("GeometryType", geometry) | ||
|
||
@validate_argument_types | ||
def ST_3DDistance(a: ColumnOrName, b: ColumnOrName) -> Column: | ||
|
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.
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.