verify(holes.isEmpty(), "shell is null but holes found"); shell = GEOMETRY_FACTORY.createLinearRing(coordinates); holes.add(GEOMETRY_FACTORY.createLinearRing(coordinates));
LinearRing ring = geometryFactory.createLinearRing(polyPoints .toArray(new Coordinate[polyPoints.size()])); rings.add(ring);
/** * Converts the specified {@code Envelope} to a {@code Polygon} having the specified srid. * * @param env The envelope to convert * @param srid The srid for the polygon * * @return The Polygon */ public static Polygon toPolygon(Envelope env, int srid) { final Coordinate[] coords = new Coordinate[5]; coords[0] = new Coordinate( env.getMinX(), env.getMinY() ); coords[1] = new Coordinate( env.getMinX(), env.getMaxY() ); coords[2] = new Coordinate( env.getMaxX(), env.getMaxY() ); coords[3] = new Coordinate( env.getMaxX(), env.getMinY() ); coords[4] = new Coordinate( env.getMinX(), env.getMinY() ); final LinearRing shell = geomFactory.createLinearRing( coords ); final Polygon pg = geomFactory.createPolygon( shell, null ); pg.setSRID( srid ); return pg; }
/** {@inheritDoc} */ public Geometry toGeometry() { Coordinate[] ring = new Coordinate[7]; System.arraycopy(vertices, 0, ring, 0, 6); ring[6] = vertices[0]; return geomFactory.createPolygon(geomFactory.createLinearRing(ring), null); }
/** * Creates a ring from the specified (<var>x</var>,<var>y</var>) coordinates. The coordinates * are stored in a flat array. */ public LinearRing ring(int[] xy) { Coordinate[] coords = new Coordinate[xy.length / 2]; for (int i = 0; i < xy.length; i += 2) { coords[i / 2] = new Coordinate(xy[i], xy[i + 1]); } return gf.createLinearRing(coords); }
@Override public LinearRing linearize() { CoordinateSequence cs = delegate.getLinearizedCoordinateSequence(delegate.tolerance); return getFactory().createLinearRing(cs); }
@Override public LinearRing linearize() { CoordinateSequence cs = delegate.getLinearizedCoordinateSequence(delegate.tolerance); return getFactory().createLinearRing(cs); }
/** * Creates a ring from the specified (<var>x</var>,<var>y</var>) coordinates. The coordinates * are stored in a flat array. */ public LinearRing ring(int[] xy) { Coordinate[] coords = new Coordinate[xy.length / 2]; for (int i = 0; i < xy.length; i += 2) { coords[i / 2] = new Coordinate(xy[i], xy[i + 1]); } return gf.createLinearRing(coords); } }
public static LinearRing ring(int[] xy) { Coordinate[] coords = new Coordinate[xy.length / 2]; for (int i = 0; i < xy.length; i += 2) { coords[i / 2] = new Coordinate(xy[i], xy[i + 1]); } return GF.createLinearRing(coords); }
private void addFullAreaPolygon(List<Polygon> geometriesList) { Coordinate[] coordinateArray = new Coordinate[5]; coordinateArray[0] = new Coordinate(imageProperties.minX - 1, imageProperties.minY - 1); coordinateArray[1] = new Coordinate(imageProperties.maxX, imageProperties.minY - 1); coordinateArray[2] = new Coordinate(imageProperties.maxX, imageProperties.maxY); coordinateArray[3] = new Coordinate(imageProperties.minX - 1, imageProperties.maxY); coordinateArray[4] = new Coordinate(imageProperties.minX - 1, imageProperties.minY - 1); LinearRing linearRing = GF.createLinearRing(coordinateArray); Polygon polygon = GF.createPolygon(linearRing, null); geometriesList.add(polygon); }
@Test public void testCoordinateDimensionPolygonEmpty() { Geometry geom = gf.createPolygon(gf.createLinearRing((Coordinate[]) null), null); // empty geometries using CoordinateArraySequence always report 3 assertEquals(3, CoordinateSequences.coordinateDimension(geom)); }
@Test public void testCoordinateDimensionPolygonLite2D() { Geometry geom = liteGF.createPolygon( liteGF.createLinearRing( liteCSF.create(new double[] {1, 1, 2, 1, 2, 2, 1, 2, 1, 1}, 2)), null); assertEquals(2, CoordinateSequences.coordinateDimension(geom)); }
@Test public void testCoordinateDimensionPolygonEmptyLite2D() { Geometry geom = liteGF.createPolygon( liteGF.createLinearRing(liteCSF.create(new double[0], 2)), null); assertEquals(2, CoordinateSequences.coordinateDimension(geom)); }
public void testCreateSchemaAndInsertPolyTriangle() throws Exception { LiteCoordinateSequenceFactory csf = new LiteCoordinateSequenceFactory(); GeometryFactory gf = new GeometryFactory(csf); LinearRing shell = gf.createLinearRing( csf.create(new double[] {0, 0, 99, 1, 0, 33, 1, 1, 66, 0, 0, 99}, 3)); Polygon poly = gf.createPolygon(shell, null); checkCreateSchemaAndInsert(poly); }
public void testCreateSchemaAndInsertPolyRectangle() throws Exception { LiteCoordinateSequenceFactory csf = new LiteCoordinateSequenceFactory(); GeometryFactory gf = new GeometryFactory(csf); LinearRing shell = gf.createLinearRing( csf.create( new double[] {0, 0, 99, 1, 0, 33, 1, 1, 66, 0, 1, 33, 0, 0, 99}, 3)); Polygon poly = gf.createPolygon(shell, null); checkCreateSchemaAndInsert(poly); }
@Test public void toEnvelope() { Coordinate[] coords = getPolyCoords(); GeometryFactory gf = new GeometryFactory(); Geometry geom = gf.createPolygon(gf.createLinearRing(coords), null); ReferencedEnvelope refEnv = JTS.toEnvelope(geom); assertTrue(geom.getEnvelopeInternal().equals(refEnv)); }
public void testIntersectsRingFilter() throws Exception { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); // should match only "r1" GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); LineString ls = gf.createLinearRing(sf.create(new double[] {2, 1, 2, 3, 0, 3, 2, 1}, 2)); Intersects is = ff.intersects(ff.property(aname("geom")), ff.literal(ls)); FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(is); checkSingleResult(features, "r1"); }
@Test public void smoothLinearRing() { Coordinate[] coords = getPolyCoords(); LineString line = factory.createLinearRing(coords); Geometry smoothed = JTS.smooth(line, 0); assertTrue(smoothed instanceof LinearRing); CoordList list = new CoordList(smoothed.getCoordinates()); assertTrue(list.containsAll(coords)); Envelope lineEnv = line.getEnvelopeInternal(); Envelope smoothEnv = smoothed.getEnvelopeInternal(); assertTrue(smoothEnv.covers(lineEnv)); }
public void testDisjointFilter() throws Exception { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); // should match only "r2" GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); LinearRing shell = gf.createLinearRing(sf.create(new double[] {4, -1, 4, 5, 6, 5, 6, -1, 4, -1}, 2)); Polygon polygon = gf.createPolygon(shell, null); Disjoint dj = ff.disjoint(ff.property(aname("geom")), ff.literal(polygon)); FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(dj); checkSingleResult(features, "r2"); }
public void testContainsFilter() throws Exception { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); // should match only "r2" GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); LinearRing shell = gf.createLinearRing(sf.create(new double[] {2, -1, 2, 5, 4, 5, 4, -1, 2, -1}, 2)); Polygon polygon = gf.createPolygon(shell, null); Contains cs = ff.contains(ff.literal(polygon), ff.property(aname("geom"))); FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(cs); checkSingleResult(features, "r2"); }