if (CGAlgorithms.signedArea(ring.getCoordinateSequence()) > 0.0) holes.add(ring); else
public Coordinate[] getCoordinates() { return linearize().getCoordinates(); }
LinearRing minShell = null; Envelope minEnv = null; Envelope testEnv = testRing.getEnvelopeInternal(); Coordinate testPt = testRing.getCoordinateN(0); LinearRing tryRing; tryRing = (LinearRing) shells.get(j); Envelope tryEnv = tryRing.getEnvelopeInternal(); if (minShell != null) { minEnv = minShell.getEnvelopeInternal(); Coordinate[] coordList = tryRing.getCoordinates();
/** * Create the LinearRing. * * @param geometryFactory The geometry factory used for the build. * @return LinearRing geometry created. */ public Geometry create(GeometryFactory geometryFactory) { try { Coordinate[] coords = (Coordinate[]) coordinateList.toArray(new Coordinate[coordinateList.size()]); LinearRing ring = geometryFactory.createLinearRing(coords); ring.setUserData(getSRS()); ring.setSRID(getSRID()); return ring; } catch (TopologyException e) { LOGGER.log(Level.FINE, "Caught Topology exception in GMLLinearRingHandler", e); return null; } } }
if (ring == null || ring.isEmpty()) { return null; final CoordinateSequence cs = ring.getCoordinateSequence(); double px = cs.getX(0); double py = cs.getY(0); if (ring.getFactory().createPolygon(ring).getArea() > 0) { return ring; } else {
@Test public void linearRing() throws Exception { LinearRing ring = builder.linearRing(); assertTrue(ring.isEmpty()); assertEquals(2, ring.getCoordinateSequence().getDimension()); }
private int locateInPolygonRing(Coordinate p, LinearRing ring) { // bounding-box check if (! ring.getEnvelopeInternal().intersects(p)) return Location.EXTERIOR; return PointLocation.locateInRing(p, ring.getCoordinates()); }
void checkAreaOfRing(String wkt, double expectedArea) { LinearRing ring = (LinearRing) read(wkt); Coordinate[] ringPts = ring.getCoordinates(); double actual1 = Area.ofRing(ringPts); assertEquals(actual1, expectedArea); CoordinateSequence ringSeq = ring.getCoordinateSequence(); double actual2 = Area.ofRing(ringSeq); assertEquals(actual2, expectedArea); }
/** http://jira.codehaus.org/browse/GEOT-1923 */ @Test public void testDecimateRingEnvelope() { // acute triangle LinearRing g = gf.createLinearRing(csf.create(new double[] {0, 0, 0, 10, 2, 10, 2, 0, 0, 0})); assertTrue(g.isValid()); Decimator d = new Decimator(20, 20); d.decimate(g); g.geometryChanged(); assertTrue(g.isValid()); assertEquals(4, g.getCoordinateSequence().size()); }
/** * Does what it says, reverses the order of the Coordinates in the ring. * * <p>This is different then lr.reverses() in that a copy is produced using a new coordinate * sequence. * * @param lr The ring to reverse. * @return A new ring with the reversed Coordinates. */ public static final LinearRing reverseRing(LinearRing lr) { GeometryFactory gf = lr.getFactory(); CoordinateSequenceFactory csf = gf.getCoordinateSequenceFactory(); CoordinateSequence csOrig = lr.getCoordinateSequence(); int numPoints = csOrig.size(); int dimensions = csOrig.getDimension(); CoordinateSequence csNew = JTS.createCS(csf, numPoints, dimensions, csOrig.getMeasures()); for (int i = 0; i < numPoints; i++) { for (int j = 0; j < dimensions; j++) { csNew.setOrdinate(numPoints - 1 - i, j, csOrig.getOrdinate(i, j)); } } return gf.createLinearRing(csNew); }
public void testCreateEmptyGeometry() throws Exception { assertTrue(geometryFactory.createPoint((Coordinate)null).isEmpty()); assertTrue(geometryFactory.createLinearRing(new Coordinate[] { }).isEmpty()); assertTrue(geometryFactory.createLineString(new Coordinate[] { }).isEmpty()); assertTrue(geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { }), new LinearRing[] { }).isEmpty()); assertTrue(geometryFactory.createLinearRing(new Coordinate[] { }).isSimple()); assertTrue(geometryFactory.createLinearRing(new Coordinate[] { }).getBoundary().isEmpty()); assertTrue(geometryFactory.createLineString(new Coordinate[] { }).getBoundary().isEmpty()); assertTrue(geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { }), new LinearRing[] { }).getBoundary().isEmpty()); assertTrue(geometryFactory.createMultiPoint(new Point[] { }).getBoundary().isEmpty()); assertTrue(geometryFactory.createLinearRing((CoordinateSequence)null).isEmpty()); assertTrue(geometryFactory.createLineString((Coordinate[])null).isEmpty()); assertTrue(geometryFactory.createPolygon(null, null).isEmpty()); assertEquals(-1, (geometryFactory.createLinearRing((CoordinateSequence)null)).getBoundaryDimension()); assertEquals(0, (geometryFactory.createLineString((Coordinate[])null)).getBoundaryDimension()); assertEquals(1, (geometryFactory.createPolygon(null, null)).getBoundaryDimension()); assertEquals(0, (geometryFactory.createLinearRing((CoordinateSequence)null)).getNumPoints()); assertEquals(0, (geometryFactory.createLineString((Coordinate[])null)).getNumPoints()); assertEquals(0, (geometryFactory.createPolygon(null, null)).getNumPoints()); assertEquals(0, (geometryFactory.createLinearRing((CoordinateSequence)null)).getCoordinates().length); assertEquals(0, (geometryFactory.createLineString((Coordinate[])null)).getCoordinates().length); assertEquals(0, (geometryFactory.createPolygon(null, null)).getCoordinates().length);
LinearRing minShell = null; Envelope minEnv = null; Envelope testEnv = testRing.getEnvelopeInternal(); Coordinate testPt = testRing.getCoordinateN(0); LinearRing tryRing; tryRing = shells.get(j); Envelope tryEnv = tryRing.getEnvelopeInternal(); if (minShell != null) { minEnv = minShell.getEnvelopeInternal(); Coordinate[] coordList = tryRing.getCoordinates(); shells.add((LinearRing) testRing.reverse()); holesForShells.add(new ArrayList<LinearRing>()); } else {
if (shell.getNumPoints() != 5) return false; CoordinateSequence seq = shell.getCoordinateSequence();
@Test public void linearRingFromOrdinates() throws Exception { double[] closedOrdinates = new double[] {1, 1, 1, 2, 2, 2, 2, 1, 1, 1}; double[] openOrdinates = Arrays.copyOf(closedOrdinates, closedOrdinates.length - 2); LinearRing ring = builder.linearRing(openOrdinates); // ring should be closed even though ordinate sequence is not assertTrue(ring.isClosed()); assertCoordinates(ring.getCoordinates(), closedOrdinates, 2); }
private void checkClosedRing(LinearRing ring) { if (ring.isEmpty()) return; if (! ring.isClosed() ) { Coordinate pt = null; if (ring.getNumPoints() >= 1) pt = ring.getCoordinateN(0); validErr = new TopologyValidationError( TopologyValidationError.RING_NOT_CLOSED, pt); } }
/** * This method will read a LineString, CircularString or CompoundCurve and return the result as * a LinearRing. * * @return LinearRing * <p>This method expects either "EMPTY", "(", "CIRCULARSTRING", or "COMPOIUNDCURVE" to * start out with. * @throws IOException * @throws ParseException */ private LinearRing readCurvedLinearRingText() throws IOException, ParseException { String nextWord = getNextWord(); if (nextWord.equals(L_PAREN)) { List<Coordinate> coords = getCoordinateList(false); return new LinearRing( new CoordinateArraySequence(coords.toArray(new Coordinate[coords.size()])), geometryFactory); } else if (nextWord.equalsIgnoreCase("CIRCULARSTRING")) { return (LinearRing) readCircularStringText(); } else if (nextWord.equalsIgnoreCase("COMPOUNDCURVE")) { return (LinearRing) readCompoundCurveText(); } else { parseError(L_PAREN + ", CIRCULARSTRING or COMPOUNDCURVE"); return null; } }
/** * Does what it says, reverses the order of the Coordinates in the ring. * * @param lr The ring to reverse. * @return A new ring with the reversed Coordinates. */ public static LinearRing reverseRing(final LinearRing lr) { final GeometryFactory gf = new GeometryFactory(); final int numPoints = lr.getNumPoints() - 1; final Coordinate[] newCoords = new Coordinate[numPoints + 1]; for (int t = numPoints; t >= 0; t--) { newCoords[t] = lr.getCoordinateN(numPoints - t); } return gf.createLinearRing(newCoords); }
public void setSRID(int SRID) { super.setSRID(SRID); }
protected Envelope computeEnvelopeInternal() { return shell.getEnvelopeInternal(); }
public int getNumPoints() { // trick to avoid issues while JTS validates the ring is closed, // it's calling super.isClosed() breaking the local override if (delegate != null) { return linearize().getNumPoints(); } else { return super.getNumPoints(); } }