Java Code Examples for com.vividsolutions.jts.geom.Geometry#getDimension()
The following examples show how to use
com.vividsolutions.jts.geom.Geometry#getDimension() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoordinateUtil.java From geowe-core with GNU General Public License v3.0 | 5 votes |
public void addCoordinateArrays(final Geometry geometry, final boolean orientPolygons, final List<Coordinate[]> coordArrayList) { if (geometry.getDimension() <= 0) { return; } else if (geometry instanceof LineString) { final LineString l = (LineString) geometry; coordArrayList.add(l.getCoordinates()); } else if (geometry instanceof Polygon) { final Polygon poly = (Polygon) geometry; Coordinate[] shell = poly.getExteriorRing().getCoordinates(); if (orientPolygons) { shell = ensureOrientation(CGAlgorithms.CLOCKWISE, shell); } coordArrayList.add(shell); for (int numRing = 0; numRing < poly.getNumInteriorRing(); numRing++) { Coordinate[] hole = poly.getInteriorRingN(numRing).getCoordinates(); if (orientPolygons) { hole = ensureOrientation( CGAlgorithms.COUNTERCLOCKWISE, hole); } coordArrayList.add(hole); } } else if (geometry instanceof GeometryCollection) { final GeometryCollection gc = (GeometryCollection) geometry; for (int numGeom = 0; numGeom < gc.getNumGeometries(); numGeom++) { addCoordinateArrays(gc.getGeometryN(numGeom), orientPolygons, coordArrayList); } } }
Example 2
Source File: SpatialSupportInitializer.java From rya with Apache License 2.0 | 5 votes |
@Override public boolean sfCrosses(Shape s1, Shape s2) { Geometry g1 = context.getGeometryFrom(s1); Geometry g2 = context.getGeometryFrom(s2); int d1 = g1.getDimension(); int d2 = g2.getDimension(); if ((d1 == 0 && d2 == 1) || (d1 == 0 && d2 == 2) || (d1 == 1 && d2 == 2)) { return g1.relate(g2, "T*T***T**"); } else if (d1 == 1 && d2 == 1) { return g1.relate(g2, "0*T***T**"); } else { return false; } }
Example 3
Source File: SpatialSupportInitializer.java From rya with Apache License 2.0 | 5 votes |
@Override public boolean sfOverlaps(Shape s1, Shape s2) { Geometry g1 = context.getGeometryFrom(s1); Geometry g2 = context.getGeometryFrom(s2); int d1 = g1.getDimension(); int d2 = g2.getDimension(); if ((d1 == 2 && d2 == 2) || (d1 == 0 && d2 == 0)) { return g1.relate(g2, "T*T***T**"); } else if (d1 == 1 && d2 == 1) { return g1.relate(g2, "1*T***T**"); } else { return false; } }
Example 4
Source File: GeometryTreeModel.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
private static boolean hasArea(Geometry geom) { if (geom.getDimension() >= 2) return true; if (geom instanceof LinearRing) return true; return false; }
Example 5
Source File: GeometryTreeModel.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
private static boolean hasLength(Geometry geom) { if (geom.getDimension() >= 1) return true; return false; }
Example 6
Source File: PreparedPolygonIntersects.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
/** * Tests whether this PreparedPolygon intersects a given geometry. * * @param geom * the test geometry * @return true if the test geometry intersects */ public boolean intersects(Geometry geom) { /** * Do point-in-poly tests first, since they are cheaper and may result in a * quick positive result. * * If a point of any test components lie in target, result is true */ boolean isInPrepGeomArea = isAnyTestComponentInTarget(geom); if (isInPrepGeomArea) return true; /** * If input contains only points, then at * this point it is known that none of them are contained in the target */ if (geom.getDimension() == 0) return false; /** * If any segments intersect, result is true */ List lineSegStr = SegmentStringUtil.extractSegmentStrings(geom); // only request intersection finder if there are segments // (i.e. NOT for point inputs) if (lineSegStr.size() > 0) { boolean segsIntersect = prepPoly.getIntersectionFinder().intersects( lineSegStr); if (segsIntersect) return true; } /** * If the test has dimension = 2 as well, it is necessary to test for proper * inclusion of the target. Since no segments intersect, it is sufficient to * test representative points. */ if (geom.getDimension() == 2) { // TODO: generalize this to handle GeometryCollections boolean isPrepGeomInArea = isAnyTargetComponentInAreaTest(geom, prepPoly.getRepresentativePoints()); if (isPrepGeomInArea) return true; } return false; }