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-626] Make ST functions return geometries with correct SRIDs #1521

Merged
merged 5 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions common/src/main/java/org/apache/sedona/common/Constructors.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,40 @@ public static Geometry geomFromEWKT(String ewkt) throws ParseException {
}

public static Geometry geomFromWKB(byte[] wkb) throws ParseException {
return new WKBReader().read(wkb);
return geomFromWKB(wkb, -1);
}

public static Geometry geomFromWKB(byte[] wkb, int SRID) throws ParseException {
Geometry geom = new WKBReader().read(wkb);
if (geom.getFactory().getSRID() != geom.getSRID() || (SRID >= 0 && geom.getSRID() != SRID)) {
// Make sure that the geometry and the geometry factory have the correct SRID
if (SRID < 0) {
SRID = geom.getSRID();
}
return Functions.setSRID(geom, SRID);
} else {
return geom;
}
}

public static Geometry pointFromWKB(byte[] wkb) throws ParseException {
return pointFromWKB(wkb, 0);
return pointFromWKB(wkb, -1);
}

public static Geometry pointFromWKB(byte[] wkb, int srid) throws ParseException {
GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), srid);
Geometry geom = new WKBReader(geometryFactory).read(wkb);
Geometry geom = geomFromWKB(wkb, srid);
if (!(geom instanceof Point)) {
return null;
}
return geom;
}

public static Geometry lineFromWKB(byte[] wkb) throws ParseException {
return lineFromWKB(wkb, 0);
return lineFromWKB(wkb, -1);
}

public static Geometry lineFromWKB(byte[] wkb, int srid) throws ParseException {
GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), srid);
Geometry geom = new WKBReader(geometryFactory).read(wkb);
Geometry geom = geomFromWKB(wkb, srid);
if (!(geom instanceof LineString)) {
return null;
}
Expand Down Expand Up @@ -141,17 +152,15 @@ public static Geometry geomCollFromText(String wkt, int srid) throws ParseExcept
*/
public static Geometry point(double x, double y) {
// See srid parameter discussion in https://issues.apache.org/jira/browse/SEDONA-234
GeometryFactory geometryFactory = new GeometryFactory();
return geometryFactory.createPoint(new Coordinate(x, y));
return GEOMETRY_FACTORY.createPoint(new Coordinate(x, y));
}

public static Geometry makePointM(double x, double y, double m) {
GeometryFactory geometryFactory = new GeometryFactory();
return geometryFactory.createPoint(new CoordinateXYM(x, y, m));
return GEOMETRY_FACTORY.createPoint(new CoordinateXYM(x, y, m));
}

public static Geometry makePoint(Double x, Double y, Double z, Double m) {
GeometryFactory geometryFactory = new GeometryFactory();
GeometryFactory geometryFactory = GEOMETRY_FACTORY;
if (x == null || y == null) {
return null;
}
Expand Down
Loading
Loading