public boolean intersects(Geometry g) { return polygon.intersects(g); }
protected List<EnterpriseGeocoderResult> filterResultsByWktPolygon(List<EnterpriseGeocoderResult> input) { if(_wktFilterPolygon == null) { return input; } List<EnterpriseGeocoderResult> output = new ArrayList<EnterpriseGeocoderResult>(); for(EnterpriseGeocoderResult result : input) { Coordinate coordinate = new Coordinate(result.getLongitude(), result.getLatitude()); Geometry point = _geometryFactory.createPoint(coordinate); if(_wktFilterPolygon.intersects(point)) { output.add(result); } } return output; }
private void many2ManyJoin(JSONObject object, Polygon polyg, Map<JSONObject, List<JSONObject>> result, SpatialIndex index) { Envelope polygonEnvelop = polyg.getEnvelopeInternal(); for (Object entry : index.query(polygonEnvelop)) { JSONArray pntg = ((JSONObject)entry).getJSONObject(GeoJsonWriter.GEOMETRY).getJSONArray(GeoJsonWriter.COORDINATES); Coordinate pnt = new Coordinate(pntg.getDouble(0), pntg.getDouble(1)); JSONObject obj = (JSONObject) entry; if(polyg.intersects(factory.createPoint(pnt))) { if(result.get(obj) == null) { result.put(obj, new ArrayList<JSONObject>()); } result.get(obj).add(object); } } }
/** * Cut a MultiPolygon with a Polygon. * * @param multiPolygon * @param extrudePolygon * @return */ public static MultiPolygon cutMultiPolygonWithPolygon(MultiPolygon multiPolygon, Polygon extrudePolygon) { ArrayList<Polygon> polygons = new ArrayList<Polygon>(); for (int i = 0; i < multiPolygon.getNumGeometries(); i++) { Polygon subGeom = (Polygon) multiPolygon.getGeometryN(i); if (extrudePolygon.intersects(subGeom)) { List<Polygon> result = cutPolygonWithPolygon(subGeom, extrudePolygon); polygons.addAll(result); } else { polygons.add(subGeom); } } return FACTORY.createMultiPolygon(polygons.toArray(new Polygon[polygons.size()])); }
/** * Query country boundaries which cover/partially cover given {@link PolyLine} * * @param polyLine * Any {@link PolyLine} or {@link Polygon} * @return a list of {@link CountryBoundary} */ public List<CountryBoundary> boundaries(final PolyLine polyLine) { return this.boundariesHelper(() -> this.query(polyLine.bounds().asEnvelope()), boundary -> boundary.intersects(JTS_POLYLINE_CONVERTER.convert(polyLine))); }
private static MultiPolygon substract(MultiPolygon outer, MultiPolygon inner) { List<Polygon> polygons = new ArrayList<Polygon>(); if(inner != null && !inner.isEmpty()) { for(int j = 0; j < outer.getNumGeometries(); j++) { Polygon outerN = (Polygon) outer.getGeometryN(j); for(int i = 0; i < inner.getNumGeometries(); i++) { Polygon innerN = (Polygon) inner.getGeometryN(i); if(outerN.intersects(innerN)) { outerN = (Polygon) outerN.difference(innerN); } } if(!outerN.isEmpty()) { polygons.add(outerN); } } } Polygon[] ps = polygons.toArray(new Polygon[polygons.size()]); MultiPolygon mp = geometryFactory.createMultiPolygon(ps); if(mp.isValid()) { return mp; } return null; }
.filter(polygon -> polygon.intersects(target)).collect(Collectors.toList()); boolean usingNearestNeighbor = false; if (polygons.size() == 1 || isSameCountry(polygons)) .filter(polygon -> polygon.intersects(target)) .map(polygon -> getGeometryProperty(polygon, ISOCountryTag.KEY)) .findFirst(); polygons.stream().filter(polygon -> polygon.intersects(target)) .map(polygon -> getGeometryProperty(polygon, ISOCountryTag.KEY)) .collect(Collectors.toList()));
/** * Query country boundaries which cover/partially cover given {@link PolyLine}, with an * extension square box * * @param polyLine * Any {@link PolyLine} or {@link Polygon} * @param extension * Extension {@link Distance} * @return a list of {@link CountryBoundary} */ public List<CountryBoundary> boundaries(final PolyLine polyLine, final Distance extension) { return this.boundariesHelper( () -> this.query(polyLine.bounds().expand(extension).asEnvelope()), boundary -> boundary.intersects(JTS_POLYLINE_CONVERTER.convert(polyLine))); }
/** * Tests the currently selected label position for intersection with the current selection of another label position. * If both labels are not rotated, an efficient AABB test is used, otherwise a polygon intersection is done * * @param labelPosOption * Another {@link PointLabelPositionOptions} to intersect with * */ boolean intersectsSelection( PointLabelPositionOptions labelPosOption ){ if( label.getStyling().rotation != 0 || labelPosOption.label.getStyling().rotation != 0 ){ return selectedPolygon.intersects( labelPosOption.selectedPolygon); }else return ((selMinX < labelPosOption.getSelectedMaxX()) && (selMaxX > labelPosOption.getSelectedMinX()) && (selMinY < labelPosOption.getSelectedMaxY()) && (selMaxY > labelPosOption.getSelectedMinY())); }
/** * Tests if the bounding rectangle of all possible positions intersects with the bounding rectangle of another PointLabelPositionOptions-object * If both labels are not rotated, an efficient AABB test is used, otherwise a polygon intersection is done * * @param labelPosOption * Another {@link PointLabelPositionOptions} to intersect with * */ boolean intersectsAny( PointLabelPositionOptions labelPosOption ){ if( label.getStyling().rotation != 0 || labelPosOption.label.getStyling().rotation != 0 ){ return totalPolygon.intersects( labelPosOption.totalPolygon); }else return ((totalMinX < labelPosOption.getMaxX()) && (totalMaxX > labelPosOption.getMinX()) && (totalMinY < labelPosOption.getMaxY()) && (totalMaxY > labelPosOption.getMinY())); }
final Polygon geoBox = buildGeoBox(currentX, currentX + incrementValue, currentY, currentY + incrementValue); if (geoBox.intersects(polygon))
final Polygon geoBox = buildGeoBox(minX, maxX, minY, maxY); if (!geoBox.intersects(polygon))
Polygon inner = f.createPolygon(interior); if (inner.intersects(outer)) { Polygon difference = (Polygon) outer.difference(inner); if (difference.isValid()) {
Point point = pm.createPoint(new Coordinate(xy[0], xy[1])); for (int j = 0; j < pairs.size(); j++) { if (pairs.get(j).getFirst().intersects(point)) { index[i] = (short) (j + 1); break;
@Test public void touchesFilter() throws Exception { Envelope bounds = testNode.bounds().get(); bounds.translate(-1 * bounds.getWidth(), 0); Polygon touching = JTS.toGeometry(bounds); // just a preflight test assertTrue(JTS.toGeometry(bounds).intersects(touching)); Touches filter; Filter pre; Filter post; filter = (Touches) toFilter(String.format("Touches(the_geom, %s)", touching)); pre = ff.intersects(ff.property("@bounds"), ff.literal(touching)); post = filter; assertFilter(filter, pre, post); }