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-223] Add ST_Split #742

Merged
merged 17 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from 16 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
14 changes: 10 additions & 4 deletions common/src/main/java/org/apache/sedona/common/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.apache.sedona.common.geometryObjects.Circle;
import org.apache.sedona.common.utils.GeomUtils;
import org.apache.sedona.common.utils.GeometryGeoHashEncoder;
import org.apache.sedona.common.utils.GeometrySplitter;
import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;
import org.locationtech.jts.algorithm.MinimumBoundingCircle;
Expand Down Expand Up @@ -128,7 +129,7 @@ public static double xMin(Geometry geometry) {
}
return min;
}

public static double xMax(Geometry geometry) {
Coordinate[] points = geometry.getCoordinates();
double max = - Double.MAX_VALUE;
Expand All @@ -146,7 +147,7 @@ public static double yMin(Geometry geometry) {
}
return min;
}

public static double yMax(Geometry geometry) {
Coordinate[] points = geometry.getCoordinates();
double max = - Double.MAX_VALUE;
Expand Down Expand Up @@ -214,7 +215,7 @@ public static Geometry flipCoordinates(Geometry geometry) {
}

public static String geohash(Geometry geometry, int precision) {
return GeometryGeoHashEncoder.calculate(geometry, precision);
return GeometryGeoHashEncoder.calculate(geometry, precision);
}

public static Geometry pointOnSurface(Geometry geometry) {
Expand Down Expand Up @@ -431,7 +432,7 @@ public static Geometry lineFromMultiPoint(Geometry geometry) {
}
List<Coordinate> coordinates = new ArrayList<>();
for(Coordinate c : geometry.getCoordinates()){
coordinates.add(c);
coordinates.add(c);
}
return GEOMETRY_FACTORY.createLineString(coordinates.toArray(new Coordinate[0]));
}
Expand Down Expand Up @@ -537,4 +538,9 @@ public static Geometry difference(Geometry leftGeometry, Geometry rightGeometry)
return leftGeometry.difference(rightGeometry);
}
}

public static Geometry split(Geometry input, Geometry blade) {
// check input geometry
return new GeometrySplitter(GEOMETRY_FACTORY).split(input, blade);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,76 @@ public static int getDimension(Geometry geometry) {
return geometry.getCoordinate() != null && !java.lang.Double.isNaN(geometry.getCoordinate().getZ()) ? 3 : 2;
}

/**
* Checks if the geometry only contains geometry of
* the same dimension. By dimension this refers to whether the
* geometries are all, for example, lines (1D).
*
* @param geometry geometry to check
* @return true iff geometry is homogeneous
*/
public static boolean geometryIsHomogeneous(Geometry geometry) {
int dimension = geometry.getDimension();

if (!geometry.isEmpty()) {
for (int i = 0; i < geometry.getNumGeometries(); i++) {
if (dimension != geometry.getGeometryN(i).getDimension()) {
return false;
}
}
}

return true;
}

/**
* Checks if either the geometry is, or contains, only point geometry.
* GeometryCollections that only contain points will return true.
*
* @param geometry geometry to check
* @return true iff geometry is puntal
*/
public static boolean geometryIsPuntal(Geometry geometry) {
if (geometry instanceof Puntal) {
return true;
} else if (geometryIsHomogeneous(geometry) && geometry.getDimension() == 0) {
return true;
}
return false;
}

/**
* Checks if either the geometry is, or contains, only line geometry.
* GeometryCollections that only contain lines will return true.
*
* @param geometry geometry to check
* @return true iff geometry is lineal
*/
public static boolean geometryIsLineal(Geometry geometry) {
if (geometry instanceof Lineal) {
return true;
} else if (geometryIsHomogeneous(geometry) && geometry.getDimension() == 1) {
return true;
}
return false;
}

/**
* Checks if either the geometry is, or contains, only polygon geometry.
* GeometryCollections that only contain polygons will return true.
*
* @param geometry geometry to check
* @return true iff geometry is polygonal
*/
public static boolean geometryIsPolygonal(Geometry geometry) {
if (geometry instanceof Polygonal) {
return true;
} else if (geometryIsHomogeneous(geometry) && geometry.getDimension() == 2) {
return true;
}
return false;
}

private static Map<Polygon, Polygon> findFaceHoles(List<Polygon> faces) {
Map<Polygon, Polygon> parentMap = new HashMap<>();
faces.sort(Comparator.comparing((Polygon p) -> p.getEnvelope().getArea()).reversed());
Expand Down Expand Up @@ -250,4 +320,4 @@ private static int countParents(Map<Polygon, Polygon> parentMap, Polygon face) {
}
return pCount;
}
}
}
Loading