Skip to content

Commit

Permalink
Add TestBuilder Selection functions for prep geoms
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Jan 19, 2024
1 parent a790382 commit 3467e23
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@
import java.util.List;

import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.prep.PreparedGeometry;
import org.locationtech.jts.geom.prep.PreparedGeometryFactory;
import org.locationtech.jts.operation.distance.IndexedFacetDistance;



public class SelectionFunctions
{

public static Geometry intersectsPrep(Geometry a, final Geometry mask)
{
PreparedGeometry prep = PreparedGeometryFactory.prepare(mask);
return select(a, new GeometryPredicate() {
public boolean isTrue(Geometry g) {
return prep.intersects(g);
}
});
}

public static Geometry intersects(Geometry a, final Geometry mask)
{
return select(a, new GeometryPredicate() {
Expand All @@ -35,7 +46,17 @@ public static Geometry covers(Geometry a, final Geometry mask)
{
return select(a, new GeometryPredicate() {
public boolean isTrue(Geometry g) {
return g.covers(mask);
return mask.covers(g);
}
});
}

public static Geometry coversPrep(Geometry a, final Geometry mask)
{
PreparedGeometry prep = PreparedGeometryFactory.prepare(mask);
return select(a, new GeometryPredicate() {
public boolean isTrue(Geometry g) {
return prep.covers(g);
}
});
}
Expand Down Expand Up @@ -168,7 +189,7 @@ public boolean isTrue(Geometry g) {
});
}

private static Geometry select(Geometry geom, GeometryPredicate pred)
public static Geometry select(Geometry geom, GeometryPredicate pred)
{
List selected = new ArrayList();
for (int i = 0; i < geom.getNumGeometries(); i++ ) {
Expand Down

0 comments on commit 3467e23

Please sign in to comment.