-
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 all 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,90 @@ public void affine2DHybridGeomCollection() { | |
assertEquals(expectedPolygon2.toText(), actualGeomCollection.getGeometryN(0).getGeometryN(1).getGeometryN(1).toText()); | ||
} | ||
|
||
@Test | ||
public void geometryTypeWithMeasured2D() { | ||
String expected1 = "POINT"; | ||
String actual1 = Functions.geometryTypeWithMeasured(GEOMETRY_FACTORY.createPoint(new Coordinate(10, 5))); | ||
assertEquals(expected1, actual1); | ||
|
||
// Create a point with measure value | ||
CoordinateXYM coords = new CoordinateXYM(2, 3, 4); | ||
Point measuredPoint = GEOMETRY_FACTORY.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 = GEOMETRY_FACTORY.createLineString(coordsLineString); | ||
String expected3 = "LINESTRINGM"; | ||
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 = GEOMETRY_FACTORY.createPolygon(coordsPolygon); | ||
String expected4 = "POLYGONM"; | ||
String actual4 = Functions.geometryTypeWithMeasured(measuredPolygon); | ||
assertEquals(expected4, actual4); | ||
} | ||
|
||
@Test | ||
public void geometryTypeWithMeasured3D() { | ||
String expected1 = "POINT"; | ||
String actual1 = Functions.geometryTypeWithMeasured(GEOMETRY_FACTORY.createPoint(new Coordinate(10, 5, 1))); | ||
assertEquals(expected1, actual1); | ||
|
||
// Create a point with measure value | ||
CoordinateXYZM coordsPoint = new CoordinateXYZM(2, 3, 4, 0); | ||
Point measuredPoint = GEOMETRY_FACTORY.createPoint(coordsPoint); | ||
String expected2 = "POINTM"; | ||
String actual2 = Functions.geometryTypeWithMeasured(measuredPoint); | ||
assertEquals(expected2, actual2); | ||
|
||
// Create a linestring with measure value | ||
CoordinateXYZM[] coordsLineString = new CoordinateXYZM[] {new CoordinateXYZM(1, 2, 3, 0), new CoordinateXYZM(4, 5, 6, 0)}; | ||
LineString measuredLineString = GEOMETRY_FACTORY.createLineString(coordsLineString); | ||
String expected3 = "LINESTRINGM"; | ||
String actual3 = Functions.geometryTypeWithMeasured(measuredLineString); | ||
assertEquals(expected3, actual3); | ||
|
||
// Create a polygon with measure value | ||
CoordinateXYZM[] coordsPolygon = new CoordinateXYZM[] {new CoordinateXYZM(0, 0, 0, 0), new CoordinateXYZM(1, 1, 0, 0), new CoordinateXYZM(0, 1, 0, 0), new CoordinateXYZM(0, 0, 0, 0)}; | ||
Polygon measuredPolygon = GEOMETRY_FACTORY.createPolygon(coordsPolygon); | ||
String expected4 = "POLYGONM"; | ||
String actual4 = Functions.geometryTypeWithMeasured(measuredPolygon); | ||
assertEquals(expected4, actual4); | ||
} | ||
|
||
@Test | ||
public void geometryTypeWithMeasuredCollection() { | ||
String expected1 = "GEOMETRYCOLLECTION"; | ||
String actual1 = Functions.geometryTypeWithMeasured(GEOMETRY_FACTORY.createGeometryCollection(new Geometry[] {GEOMETRY_FACTORY.createPoint(new Coordinate(10, 5))})); | ||
assertEquals(expected1, actual1); | ||
|
||
// Create a geometrycollection with measure value | ||
CoordinateXYM coords = new CoordinateXYM(2, 3, 4); | ||
Point measuredPoint = GEOMETRY_FACTORY.createPoint(coords); | ||
String expected2 = "GEOMETRYCOLLECTIONM"; | ||
String actual2 = Functions.geometryTypeWithMeasured(GEOMETRY_FACTORY.createGeometryCollection(new Geometry[] {measuredPoint})); | ||
assertEquals(expected2, actual2); | ||
|
||
// Create a geometrycollection with measure value | ||
CoordinateXYM[] coordsLineString = new CoordinateXYM[] {new CoordinateXYM(1, 2, 3), new CoordinateXYM(4, 5, 6)}; | ||
LineString measuredLineString = GEOMETRY_FACTORY.createLineString(coordsLineString); | ||
String expected3 = "GEOMETRYCOLLECTIONM"; | ||
String actual3 = Functions.geometryTypeWithMeasured(GEOMETRY_FACTORY.createGeometryCollection(new Geometry[] {measuredLineString})); | ||
assertEquals(expected3, actual3); | ||
|
||
// Create a geometrycollection 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 = GEOMETRY_FACTORY.createPolygon(coordsPolygon); | ||
String expected4 = "GEOMETRYCOLLECTIONM"; | ||
String actual4 = Functions.geometryTypeWithMeasured(GEOMETRY_FACTORY.createGeometryCollection(new Geometry[] {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,37 @@ | ||
## 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. This function also indicates if the geometry is measured, by returning a string of the form 'POINTM'. | ||
|
||
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 | ||
``` | ||
|
||
```sql | ||
SELECT GeometryType(ST_GeomFromText('POINTM(0 0 1)')); | ||
``` | ||
|
||
Result: | ||
|
||
``` | ||
geometrytype | ||
-------------- | ||
POINTM | ||
``` | ||
|
||
## 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,17 @@ | |
|
||
_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 |
||
This function also indicates if the geometry is measured, by returning a string of the form 'POINTM'. | ||
|
||
: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.
Please add test case testing geometry collections