if (CGAlgorithms.signedArea(ring.getCoordinateSequence()) > 0.0) holes.add(ring); else
public Object getProperty(Object object, QName name) throws Exception { LinearRing linearRing = (LinearRing) object; if (GML.coordinates.equals(name)) { return linearRing.getCoordinateSequence(); } return null; } }
public CoordinateSequence getCoordinateSequence() { // 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().getCoordinateSequence(); } else { return super.getCoordinateSequence(); } }
public CoordinateSequence getCoordinateSequence() { // 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().getCoordinateSequence(); } else { return super.getCoordinateSequence(); } }
public Object getProperty(Object object, QName name) throws Exception { if (KML.coordinates.getLocalPart().equals(name.getLocalPart())) { LinearRing l = (LinearRing) object; return l.getCoordinateSequence(); } return null; } }
@Override public void setGeometryValue( Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column) throws SQLException { if (g != null) { if (g instanceof LinearRing) { // teradata does not handle linear rings, convert to just a line string g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence()); } // TODO: use WKB instead of WKT String wkt = new WKTWriter().write(g); if (wkt.length() > 64000) { ByteArrayInputStream bin = new ByteArrayInputStream(wkt.getBytes()); ps.setAsciiStream(column, bin, bin.available()); } else { ps.setString(column, wkt); } } else { ps.setNull(column, Types.OTHER, "Geometry"); } }
@Override protected void visitLiteralGeometry(Literal expression) throws IOException { Geometry g = (Geometry) evaluateLiteral(expression, Geometry.class); if (g instanceof LinearRing) { // WKT does not support linear rings g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence()); } out.write("ST_GeomFromText('" + g.toText() + "', " + currentSRID + ")"); }
@Override protected void visitLiteralGeometry(Literal expression) throws IOException { Geometry g = (Geometry) evaluateLiteral(expression, Geometry.class); if (g instanceof LinearRing) { // WKT does not support linear rings g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence()); } out.write("geometry::STGeomFromText('" + g.toText() + "', " + currentSRID + ")"); }
@Override protected void visitLiteralGeometry(Literal expression) throws IOException { Geometry g = (Geometry) evaluateLiteral(expression, Geometry.class); if (g instanceof LinearRing) { // WKT does not support linear rings g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence()); } out.write("GeomFromText('" + g.toText() + "', " + currentSRID + ")"); }
@Override protected void visitLiteralGeometry(Literal expression) throws IOException { // evaluate the literal and store it for later Geometry geom = (Geometry) evaluateLiteral(expression, Geometry.class); if (geom instanceof LinearRing) { // postgis does not handle linear rings, convert to just a line string geom = geom.getFactory().createLineString(((LinearRing) geom).getCoordinateSequence()); } Object typename = currentGeometry.getUserData().get(JDBCDataStore.JDBC_NATIVE_TYPENAME); if ("geography".equals(typename)) { out.write("ST_GeogFromText('"); out.write(geom.toText()); out.write("')"); } else { out.write("ST_GeomFromText('"); out.write(geom.toText()); if (currentSRID == null && currentGeometry != null) { // if we don't know at all, use the srid of the geometry we're comparing against // (much slower since that has to be extracted record by record as opposed to // being a constant) out.write("', ST_SRID(\"" + currentGeometry.getLocalName() + "\"))"); } else { out.write("', " + currentSRID + ")"); } } }
@Override public void setGeometryValue( Geometry g, int dimension, int srid, Class binding, PreparedStatement ps, int column) throws SQLException { if (g != null && !g.isEmpty()) { if (g instanceof LinearRing) { // postgis does not handle linear rings, convert to just a line string g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence()); } byte[] bytes = new WKBWriter(dimension).write(g); ps.setBytes(column, bytes); } else { ps.setNull(column, Types.OTHER, "Geometry"); } }
@Override public void encodeGeometryValue(Geometry value, int dimension, int srid, StringBuffer sql) throws IOException { if (value == null || value.isEmpty()) { sql.append("NULL"); } else { if (value instanceof LinearRing && !(value instanceof CurvedRing)) { // postgis does not handle linear rings, convert to just a line string value = value.getFactory() .createLineString(((LinearRing) value).getCoordinateSequence()); } WKTWriter writer = new WKTWriter2(dimension); String wkt = writer.write(value); sql.append("ST_GeomFromText('" + wkt + "', " + srid + ")"); } }
private static final Geometry cloneGeometry(LinearRing geom, int dimension) { if (geom instanceof SingleCurvedGeometry<?>) { SingleCurvedGeometry<?> curved = (SingleCurvedGeometry<?>) geom; double[] controlPoints = curved.getControlPoints(); double[] clonedPoints = new double[controlPoints.length]; System.arraycopy(controlPoints, 0, clonedPoints, 0, controlPoints.length); return new CircularRing(clonedPoints, geomFac, curved.getTolerance()); } else if (geom instanceof CompoundCurvedGeometry<?>) { CompoundCurvedGeometry<?> curved = (CompoundCurvedGeometry<?>) geom; List<LineString> components = curved.getComponents(); List<LineString> clonedComponents = new ArrayList<>(components.size()); for (LineString ls : components) { LineString cloned = (LineString) cloneGeometry(ls, dimension); clonedComponents.add(cloned); } return new CompoundRing(clonedComponents, geomFac, dimension); } else { return geomFac.createLinearRing( new LiteCoordinateSequence(geom.getCoordinateSequence(), dimension)); } }
/** * 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); }
@Test public void linearRing() throws Exception { LinearRing ring = builder.linearRing(); assertTrue(ring.isEmpty()); assertEquals(2, ring.getCoordinateSequence().getDimension()); }
@Test public void linearRingZ() throws Exception { LinearRing ring = builder.linearRingZ(); assertTrue(ring.isEmpty()); assertEquals(3, ring.getCoordinateSequence().getDimension()); }
final CoordinateSequence cs = ring.getCoordinateSequence(); double px = cs.getX(0); double py = cs.getY(0);
/** http://jira.codehaus.org/browse/GEOT-1923 */ @Test public void testDecimateRing() { // a long rectangle made of 5 coordinates 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(4, 4); d.decimate(g); g.geometryChanged(); assertTrue(g.isValid()); assertEquals(4, g.getCoordinateSequence().size()); }
/** 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()); }
CoordinateSequence coordinates = cr.linearize().getCoordinateSequence(); circle.assertTolerance(coordinates, 0.1);