Java Code Examples for com.vividsolutions.jts.algorithm.CGAlgorithms#isCCW()
The following examples show how to use
com.vividsolutions.jts.algorithm.CGAlgorithms#isCCW() .
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 | 6 votes |
public Coordinate[] ensureOrientation( final int desiredOrientation, final Coordinate... coord) { if (coord.length == 0) { return coord; } final int orientation = CGAlgorithms.isCCW(coord) ? CGAlgorithms.COUNTERCLOCKWISE : CGAlgorithms.CLOCKWISE; if (orientation != desiredOrientation) { final Coordinate[] reverse = (Coordinate[]) coord.clone(); reverse(reverse); return reverse; } return coord; }
Example 2
Source File: GeometryLocationsWriter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
private String componentType(GeometryLocation loc) { String compType = ""; if (loc.getComponent() instanceof LinearRing) { boolean isCCW = CGAlgorithms.isCCW(loc.getComponent().getCoordinates()); compType = "Ring" + (isCCW ? "-CCW" : "-CW ") + " "; } else if (loc.getComponent() instanceof LineString) { compType = "Line "; } else if (loc.getComponent() instanceof Point) { compType = "Point "; } return compType; }
Example 3
Source File: GeometryFunctions.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static boolean isCCW(Geometry g) { Coordinate[] pts = null; if (g instanceof Polygon) { pts = ((Polygon) g).getExteriorRing().getCoordinates(); } else if (g instanceof LineString && ((LineString) g).isClosed()) { pts = g.getCoordinates(); } if (pts == null) return false; return CGAlgorithms.isCCW(pts); }
Example 4
Source File: EdgeRing.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
/** * Compute a LinearRing from the point list previously collected. * Test if the ring is a hole (i.e. if it is CCW) and set the hole flag * accordingly. */ public void computeRing() { if (ring != null) return; // don't compute more than once Coordinate[] coord = new Coordinate[pts.size()]; for (int i = 0; i < pts.size(); i++) { coord[i] = (Coordinate) pts.get(i); } ring = geometryFactory.createLinearRing(coord); isHole = CGAlgorithms.isCCW(ring.getCoordinates()); //Debug.println( (isHole ? "hole - " : "shell - ") + WKTWriter.toLineString(new CoordinateArraySequence(ring.getCoordinates()))); }
Example 5
Source File: LinearRingImpl.java From mrgeo with Apache License 2.0 | 5 votes |
@Override public boolean isCCW() { Coordinate[] coordinates = new Coordinate[getNumPoints()]; for (int i = 0; i < getNumPoints(); i++) { Point pt = getPoint(i); coordinates[i] = new Coordinate(pt.getX(), pt.getY()); } return CGAlgorithms.isCCW(coordinates); }
Example 6
Source File: GeometryValidator.java From geowe-core with GNU General Public License v3.0 | 4 votes |
private void validate(final Geometry geom, final List<ValidationResult> validationErrors) { if (geom.isEmpty()) { return; } if (geom instanceof GeometryCollection) { final GeometryCollection gc = (GeometryCollection) geom; for (int numGeom = 0; numGeom < gc.getNumGeometries(); numGeom++) { validate(gc.getGeometryN(numGeom), validationErrors); } } final ValidationResult result = new ValidationResult(); result.setWkt(geom.toText()); final List<String> messages = new ArrayList<String>(); if (!geom.isValid()) { messages.add("Error en topología básica"); } if (!geom.isSimple()) { messages.add("No es una geometría simple"); } if (repeatedPointTester.hasRepeatedPoint(geom)) { messages.add("Se encuentran vértices repetidos"); } if (geom instanceof Polygon) { final Polygon polygon = (Polygon) geom; if (CGAlgorithms.isCCW(polygon.getExteriorRing().getCoordinates())) { messages.add("Error en orientación del polígono"); } else { for (int numRing = 0; numRing < polygon.getNumInteriorRing(); numRing++) { if (!CGAlgorithms.isCCW(polygon.getInteriorRingN(numRing).getCoordinates())) { messages.add("Error en orientación del polígono en anillos interiores"); break; } } } if (!validateMinPolygonArea(geom)) { messages.add("Error en validación mínima de area de un polígono"); } } if (!validateMinSegmentLength(geom)) { messages.add("Error en validación mínima de longitud de segmento. Coordenadas"); result.setErrorsPoints(errorCoordinates); } if(!messages.isEmpty()) { result.setMessages(messages); validationErrors.add(result); } }
Example 7
Source File: OraReader.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
/** * Read {@link Polygon) from encoded geometry. * * @param oraGeom SDO_GEOMETRY attributes being read * @param elemIndex the element being read * @param coords the coordinates of the entire geometry * @return Polygon as encoded by elemInfo, or null when faced with and * encoding that can not be captured by JTS * @throws IllegalArgumentException When faced with an invalid SDO encoding */ private Polygon readPolygon(OraGeom oraGeom, int elemIndex) { int etype = oraGeom.eType(elemIndex); int interpretation = oraGeom.interpretation(elemIndex); checkOrdinates(oraGeom, elemIndex, "Polygon"); checkETYPE(etype,OraGeom.ETYPE.POLYGON, OraGeom.ETYPE.POLYGON_EXTERIOR, "Polygon"); checkInterpretation(interpretation, OraGeom.INTERP.POLYGON, OraGeom.INTERP.RECTANGLE, "Polygon"); int nElem = oraGeom.numElements(); // ETYPE is either POLYGON or POLYGON_EXTERIOR LinearRing exteriorRing = readLinearRing(oraGeom, elemIndex); /** * Holes are read as long as ETYPE = POLYGON_INTERIOR * or ETYPE = POLYGON && orient = CW (Hole) */ List holeRings = new ArrayList(); for (int i = elemIndex + 1; i < nElem; i++) { etype = oraGeom.eType(i); if (etype == OraGeom.ETYPE.POLYGON_INTERIOR) { holeRings.add(readLinearRing(oraGeom, i)); } else if (etype == OraGeom.ETYPE.POLYGON) { // test orientation of Ring to see if it is // an interior (hole) ring LinearRing ring = readLinearRing(oraGeom, i); // TODO: use the coordSeq directly (requires new CGAlgorithms method) boolean isHole = ! CGAlgorithms.isCCW(ring.getCoordinates()); // if not a hole, exit if (! isHole) break; // it is an Interior Hole holeRings.add(ring); } else { // not a LinearRing - get out of here break; } } Polygon poly = geometryFactory.createPolygon(exteriorRing, GeometryFactory.toLinearRingArray(holeRings)); return poly; }
Example 8
Source File: OraWriter.java From jts with GNU Lesser General Public License v2.1 | 3 votes |
/** * Writes ordinates in the orientation * specified by the isWriteCCW CCW flag. * Coordinates are reversed if necessary. * * @param seq the coordinates to write * @param dim the output dimension required * @param ordData the ordinates array * @param ordIndex the starting index in the ordinates array * @param isWriteCCW true if the ordinates should be written in CCW orientation, false if CW * @return the next index to write in the ordinates array */ private int writeOrdsOriented(CoordinateSequence seq, int dim, double[] ordData, int ordIndex, boolean isWriteCCW) { Coordinate[] coords = seq.toCoordinateArray(); //TODO: add method to CGAlgorithms to compute isCCW for CoordinateSequences boolean isCCW = CGAlgorithms.isCCW(coords); if (isCCW != isWriteCCW) { return writeOrdsReverse(seq, dim, ordData, ordIndex); } return writeOrds(seq, dim, ordData, ordIndex); }