private boolean computeSimple(Geometry geom) { this.nonSimpleLocation = null; if (geom.isEmpty()) { return true; } if (geom instanceof LineString) { return this.isSimpleLinearGeometry(geom); } if (geom instanceof MultiLineString) { return this.isSimpleLinearGeometry(geom); } if (geom instanceof MultiPoint) { return this.isSimpleMultiPoint((MultiPoint) geom); } if (geom instanceof Polygonal) { return this.isSimplePolygonal(geom); } if (geom instanceof GeometryCollection) { return this.isSimpleGeometryCollection(geom); } // all other geometry types are simple by definition return true; }
public Geometry reduce(Geometry geom) { Geometry reducePW = this.reducePointwise(geom); if (this.isPointwise) { return reducePW; } //TODO: handle GeometryCollections containing polys if (!(reducePW instanceof Polygonal)) { return reducePW; } // Geometry is polygonal - test if topology needs to be fixed if (reducePW.isValid()) { return reducePW; } // hack to fix topology. // TODO: implement snap-rounding and use that. return this.fixPolygonalTopology(reducePW); }
/** * Creates a new {@link PreparedGeometry} appropriate for the argument {@link Geometry}. * * @param geom the geometry to prepare * @return the prepared geometry */ public PreparedGeometry create(Geometry geom) { if (geom instanceof Polygonal) { return new PreparedPolygon((Polygonal) geom); } if (geom instanceof Lineal) { return new PreparedLineString((Lineal) geom); } if (geom instanceof Puntal) { return new PreparedPoint((Puntal) geom); } /** * Default representation. */ return new BasicPreparedGeometry(geom); }
private boolean isProperIntersectionImpliesNotContainedSituation(Geometry testGeom) { /** * If the test geometry is polygonal we have the A/A situation. * In this case, a proper intersection indicates that * the Epsilon-Neighbourhood Exterior Intersection condition exists. * This condition means that in some small * area around the intersection point, there must exist a situation * where the interior of the test intersects the exterior of the target. * This implies the test is NOT contained in the target. */ if (testGeom instanceof Polygonal) { return true; } /** * A single shell with no holes allows concluding that * a proper intersection implies not contained * (due to the Epsilon-Neighbourhood Exterior Intersection condition) */ return isSingleShell(prepPoly.getGeometry()); }
private LatLon findCenterPoint() { try { Geometry geom = JTSConst.toGeometry(this); if(!geom.isValid()) return null; if(geom instanceof Polygonal) { return JTSConst.toLatLon(geom.getInteriorPoint()); } else if(geom instanceof Lineal) { LengthIndexedLine lil = new LengthIndexedLine(geom); return JTSConst.toLatLon(lil.extractPoint(geom.getLength() / 2.0)); } } catch (Exception e) { // unable to create proper geometry... return null; } return null; }
public Geometry reduce(Geometry geom) { Geometry reducePW = reducePointwise(geom); if (isPointwise) return reducePW; //TODO: handle GeometryCollections containing polys if (!(reducePW instanceof Polygonal)) return reducePW; // Geometry is polygonal - test if topology needs to be fixed if (reducePW.isValid()) return reducePW; // hack to fix topology. // TODO: implement snap-rounding and use that. return fixPolygonalTopology(reducePW); }
private boolean isProperIntersectionImpliesNotContainedSituation(Geometry testGeom) { /** * If the test geometry is polygonal we have the A/A situation. * In this case, a proper intersection indicates that * the Epsilon-Neighbourhood Exterior Intersection condition exists. * This condition means that in some small * area around the intersection point, there must exist a situation * where the interior of the test intersects the exterior of the target. * This implies the test is NOT contained in the target. */ if (testGeom instanceof Polygonal) return true; /** * A single shell with no holes allows concluding that * a proper intersection implies not contained * (due to the Epsilon-Neighbourhood Exterior Intersection condition) */ if (isSingleShell(prepPoly.getGeometry())) return true; return false; }
/** * Converts a JTS polygonal geometry to an EAD polygon. EAD polygons are * converted to GDX polygons before use, and therefore share limitations. * * @param g * geometry to convert (must be a closed polygon) * @return a schema polygon */ public static es.eucm.ead.schema.data.shape.Polygon jtsToSchemaPolygon( Geometry g) { if (!(g instanceof Polygonal)) { throw new IllegalArgumentException( "Can only convert JTS Polygons, but supplied a " + g); } Coordinate[] cs = g.getCoordinates(); Array<Float> resultVertices = new Array<Float>(cs.length); for (Coordinate c : cs) { resultVertices.add((float) c.x); resultVertices.add((float) c.y); } // remove the last point, as it is the same as the first resultVertices.removeIndex(resultVertices.size - 1); resultVertices.removeIndex(resultVertices.size - 1); es.eucm.ead.schema.data.shape.Polygon result = new es.eucm.ead.schema.data.shape.Polygon(); result.setPoints(resultVertices); return result; }
public static LinkedList<PreparedPolygon> load() throws IOException { URL krajeShp = Kraje.class .getResource("kraje/hranice_krajov_simpl.shp"); FileDataStore store = FileDataStoreFinder.getDataStore(krajeShp); FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = store .getFeatureSource(); FeatureCollection<SimpleFeatureType, SimpleFeature> fC = featureSource .getFeatures(); FeatureIterator<SimpleFeature> iter = fC.features(); LinkedList<PreparedPolygon> list = new LinkedList<PreparedPolygon>(); try { while (iter.hasNext()) { Feature f = iter.next(); GeometryAttribute geomAttr = f.getDefaultGeometryProperty(); list.add(new PreparedPolygon((Polygonal) geomAttr.getValue())); } } finally { iter.close(); } return list; }
/** * Snaps the vertices in the component {@link LineString}s * of the source geometry * to the vertices of the given snap geometry. * * @param snapTolerance the snapping tolerance * @param cleanResult whether the result should be made valid * @return a new snapped Geometry */ public Geometry snapToSelf(double snapTolerance, boolean cleanResult) { Coordinate[] snapPts = this.extractTargetCoordinates(this.srcGeom); SnapTransformer snapTrans = new SnapTransformer(snapTolerance, snapPts, true); Geometry snappedGeom = snapTrans.transform(this.srcGeom); Geometry result = snappedGeom; if (cleanResult && result instanceof Polygonal) { // TODO: use better cleaning approach result = snappedGeom.buffer(0); } return result; }
/** * Creates a new locator for a given {@link Geometry} * * @param g the Geometry to locate in */ public IndexedPointInAreaLocator(Geometry g) { if (!(g instanceof Polygonal)) { throw new IllegalArgumentException("Argument must be Polygonal"); } this.buildIndex(g); }
/** * Determines the {@link Location} of the given {@link Coordinate} * in this geometry. * * @param p the point to test * @return the location of the point in the geometry */ public int locate(Coordinate pt) { if (this.parentGeom instanceof Polygonal && this.parentGeom.getNumGeometries() > 50) { // lazily init point locator if (this.areaPtLocator == null) { this.areaPtLocator = new IndexedPointInAreaLocator(this.parentGeom); } return this.areaPtLocator.locate(pt); } return this.ptLocator.locate(pt, this.parentGeom); }
/** * Tests whether this PreparedPolygon containsProperly a given geometry. * * @param geom the test geometry * @return true if the test geometry is contained properly */ public boolean containsProperly(Geometry geom) { /** * Do point-in-poly tests first, since they are cheaper and may result * in a quick negative result. * * If a point of any test components does not lie in the target interior, result is false */ boolean isAllInPrepGeomAreaInterior = this.isAllTestComponentsInTargetInterior(geom); if (!isAllInPrepGeomAreaInterior) { return false; } /** * If any segments intersect, result is false. */ List lineSegStr = SegmentStringUtil.extractSegmentStrings(geom); boolean segsIntersect = this.prepPoly.getIntersectionFinder().intersects(lineSegStr); if (segsIntersect) { return false; } /** * Given that no segments intersect, if any vertex of the target * is contained in some test component. * the test is NOT properly contained. */ if (geom instanceof Polygonal) { // TODO: generalize this to handle GeometryCollections boolean isTargetGeomInTestArea = this.isAnyTargetComponentInAreaTest(geom, this.prepPoly.getRepresentativePoints()); if (isTargetGeomInTestArea) { return false; } } return true; }
/** * Sets a polygonal mask. * * @param mask * @throws IllegalArgumentException if the mask is not polygonal */ public void setExtent(Geometry mask) { if (!(mask instanceof Polygonal)) { throw new IllegalArgumentException("Only polygonal extents are supported"); } this.maskPoly = mask; this.setExtent(mask.getEnvelopeInternal()); this.extentLocator = new IndexedPointInAreaLocator(mask); }
/** * Creates a new {@link PreparedGeometry} appropriate for the argument {@link Geometry}. * * @param geom the geometry to prepare * @return the prepared geometry */ public PreparedGeometry create(Geometry geom) { if (geom instanceof Polygonal) return new PreparedPolygon((Polygonal) geom); if (geom instanceof Lineal) return new PreparedLineString((Lineal) geom); if (geom instanceof Puntal) return new PreparedPoint((Puntal) geom); /** * Default representation. */ return new BasicPreparedGeometry(geom); }
/** * Tests whether this PreparedPolygon containsProperly a given geometry. * * @param geom the test geometry * @return true if the test geometry is contained properly */ public boolean containsProperly(Geometry geom) { /** * Do point-in-poly tests first, since they are cheaper and may result * in a quick negative result. * * If a point of any test components does not lie in the target interior, result is false */ boolean isAllInPrepGeomAreaInterior = isAllTestComponentsInTargetInterior(geom); if (!isAllInPrepGeomAreaInterior) return false; /** * If any segments intersect, result is false. */ List lineSegStr = SegmentStringUtil.extractSegmentStrings(geom); boolean segsIntersect = prepPoly.getIntersectionFinder().intersects(lineSegStr); if (segsIntersect) return false; /** * Given that no segments intersect, if any vertex of the target * is contained in some test component. * the test is NOT properly contained. */ if (geom instanceof Polygonal) { // TODO: generalize this to handle GeometryCollections boolean isTargetGeomInTestArea = isAnyTargetComponentInAreaTest(geom, prepPoly.getRepresentativePoints()); if (isTargetGeomInTestArea) return false; } return true; }
static Rank getRank(Geometry geometry) { if (geometry instanceof Puntal) { return Rank.POINT; } else if (geometry instanceof Lineal) { return Rank.LINE; } else if (geometry instanceof Polygonal) { return Rank.AREA; } else { return Rank.NOT_SPECIFIED; } }
public PredicateEvaluatorPrepared(Geometry geometry) { this.factory = new GeometryFactory(); this.preparedPolygon = new PreparedPolygon((Polygonal) geometry); }
public PreparedPolygon(Polygonal poly) { super((Geometry) poly); this.isRectangle = this.getGeometry().isRectangle(); }
public PreparedPolygon(Polygonal poly) { super((Geometry) poly); isRectangle = getGeometry().isRectangle(); }
private void importGeometry(final SnapApp snapApp, final File file) { final Product product = snapApp.getSelectedProduct(AUTO); if (product == null) { return; } final GeoCoding geoCoding = product.getSceneGeoCoding(); if (geoCoding == null || !geoCoding.canGetPixelPos()) { Dialogs.showError(dialogTitle, "Failed to import vector data.\n" + "Current geo-coding cannot convert from geographic to pixel coordinates."); /* I18N */ return; } VectorDataNode vectorDataNode; try { vectorDataNode = readGeometry(snapApp, file, product); if (vectorDataNode == null) { return; } } catch (Exception e) { Dialogs.showError(dialogTitle, "Failed to import vector data.\n" + "An I/O Error occurred:\n" + e.getMessage()); /* I18N */ Debug.trace(e); return; } if (vectorDataNode.getFeatureCollection().isEmpty()) { Dialogs.showError(dialogTitle, "The vector data was loaded successfully,\n" + "but no part is located within the scene boundaries."); /* I18N */ return; } boolean individualShapes = false; String attributeName = null; GeometryDescriptor geometryDescriptor = vectorDataNode.getFeatureType().getGeometryDescriptor(); int featureCount = vectorDataNode.getFeatureCollection().size(); if (featureCount > 1 && geometryDescriptor != null && Polygonal.class.isAssignableFrom(geometryDescriptor.getType().getBinding())) { String text = "<html>" + "The vector data set contains <b>" + featureCount + "</b> polygonal shapes.<br>" + "Shall they be imported separately?<br>" + "<br>" + "If you select <b>Yes</b>, the polygons can be used as individual masks<br>" + "and they will be displayed on individual layers.</i>"; SeparateGeometriesDialog dialog = new SeparateGeometriesDialog(snapApp.getMainFrame(), vectorDataNode, helpId, text); int response = dialog.show(); if (response == ModalDialog.ID_CANCEL) { return; } individualShapes = response == ModalDialog.ID_YES; attributeName = dialog.getSelectedAttributeName(); } VectorDataNode[] vectorDataNodes = VectorDataNodeIO.getVectorDataNodes(vectorDataNode, individualShapes, attributeName); for (VectorDataNode vectorDataNode1 : vectorDataNodes) { product.getVectorDataGroup().add(vectorDataNode1); } setLayersVisible(vectorDataNodes); }
/** * Computes a {@link Geometry} containing only {@link Polygonal} components. * Extracts the {@link Polygon}s from the input * and returns them as an appropriate {@link Polygonal} geometry. * <p> * If the input is already <tt>Polygonal</tt>, it is returned unchanged. * <p> * A particular use case is to filter out non-polygonal components * returned from an overlay operation. * * @param g the geometry to filter * @return a Polygonal geometry */ private static Geometry restrictToPolygons(Geometry g) { if (g instanceof Polygonal) { return g; } List polygons = PolygonExtracter.getPolygons(g); if (polygons.size() == 1) { return (Polygon) polygons.get(0); } return g.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons)); }
public static boolean isPolygonal(Geometry geom) { return geom instanceof Polygonal; }