/** * Creates a {@link LinearRing} using the given {@link CoordinateSequence}. * A null or empty CoordinateSequence will * create an empty LinearRing. The points must form a closed and simple * linestring. Consecutive points must not be equal. * * @param coordinates a CoordinateSequence possibly empty, or null * @throws IllegalArgumentException if the ring is not closed, or has too few points */ public LinearRing createLinearRing(CoordinateSequence coordinates) { return new LinearRing(coordinates, this); }
LinearRing lr = new LinearRing(merge.getCoordinateSequence(), this.geomFactory); Polygon concaveHull = new Polygon(lr, null, this.geomFactory); return concaveHull;
public void test() { Coordinate coordiates2d = new Coordinate(34.2d, 34.4d); Coordinate coordiates2d1 = new Coordinate(34.2d, 34.4d); Coordinate[] coordinates = new Coordinate[2]; coordinates[0] = coordiates2d; coordinates[1] = coordiates2d1; com.vividsolutions.jts.geom.impl.PackedCoordinateSequence.Float floatSequence = new com.vividsolutions.jts.geom.impl.PackedCoordinateSequence.Float( coordinates, 1); GeometryFactory geoFactory = new GeometryFactory(new PrecisionModel(2)); com.vividsolutions.jts.geom.impl.PackedCoordinateSequence.Double doubleSequence = new com.vividsolutions.jts.geom.impl.PackedCoordinateSequence.Double( coordinates, 1); LinearRing shell = new LinearRing(floatSequence, geoFactory); LinearRing[] holes = new LinearRing[1]; holes[0] = new LinearRing(doubleSequence, geoFactory); Polygon polygon = new Polygon(shell, holes, geoFactory); Assert.assertNotNull(polygon.getCoordinates()); }
/** * Creates a {@link LinearRing} using the given {@link CoordinateSequence}. * A null or empty array creates an empty LinearRing. * The points must form a closed and simple linestring. * * @param coordinates a CoordinateSequence (possibly empty), or null * @return the created LinearRing * @throws IllegalArgumentException if the ring is not closed, or has too few points */ public LinearRing createLinearRing(CoordinateSequence coordinates) { return new LinearRing(coordinates, this); }
public static LinearRing buildLinearRing(final CoordinateSequence sequence) { return new LinearRing(sequence, GEOMETRY_FACTORY); }
LinearRing shell = new LinearRing(points, factory); LinearRing[] holes = new LinearRing[0];
public static LinearRing buildLinearRing(final List<Coordinate> coordinates) { final Coordinate[] coordinateArray = coordinates .toArray(new Coordinate[coordinates.size()]); final CoordinateArraySequence sequence = new CoordinateArraySequence(coordinateArray); return new LinearRing(sequence, GEOMETRY_FACTORY); }
@Override public LinearRing convert(final Polygon object) { final List<Location> locations = new ArrayList<>(object); // Hack to close the loop, as JTS expects it... locations.add(locations.get(0)); while (locations.size() < MINIMUM_LINEAR_RING_SIZE) { locations.add(locations.get(0)); } return new LinearRing(COORDINATE_ARRAY_CONVERTER.convert(locations), FACTORY); } }
public static Polygon constructRectyPolygon(Point2D.Double aLeftUpperCorner, Point2D.Double aBottomRightCorner) { Coordinate[] coordinates = new Coordinate[5]; coordinates[0] = new Coordinate(aLeftUpperCorner.x, aLeftUpperCorner.y); coordinates[1] = new Coordinate(aBottomRightCorner.x, aLeftUpperCorner.y); coordinates[2] = new Coordinate(aBottomRightCorner.x, aBottomRightCorner.y); coordinates[3] = new Coordinate(aLeftUpperCorner.x, aBottomRightCorner.y); coordinates[4] = new Coordinate(aLeftUpperCorner.x, aLeftUpperCorner.y); CoordinateSequence cSeq = csFactory.create(coordinates); return gFactory.createPolygon(new LinearRing(cSeq, gFactory), null); }
public static Polygon toPolygon(final Coordinate[] coordinates) { if (coordinates.length < MININMUM_NUMBER_OF_POLYGON_POINTS && coordinates.length != 0) { // An invalid polygon. one example A->B->A return null; } final CoordinateArraySequence sequence = new CoordinateArraySequence(coordinates); final LinearRing shell = new LinearRing(sequence, GEOMETRY_FACTORY); return new Polygon(shell, new LinearRing[] {}, GEOMETRY_FACTORY); }
private LinearRing getLinearRing(java.awt.Polygon p) { if (p.npoints < 4) { return null; } ArrayList<Coordinate> coords = new ArrayList<>(); for (int i = 0; i < p.npoints; i++) { int x = p.xpoints[i]; int y = p.ypoints[i]; double[] xy = grid.getCoordinates(grid.getOffset(x, y)); coords.add(new Coordinate(xy[0], xy[1])); } return new LinearRing(new CoordinateArraySequence(coords .toArray(new Coordinate[coords.size()])), gfact); }
public Polygon readPolygon(ObjectInputStream in) throws IOException { List<Coordinate> shellCoordinates = new ArrayList<Coordinate>(); while (in.readBoolean()) { shellCoordinates.add(new Coordinate(in.readDouble(), in.readDouble())); } shellCoordinates.add(shellCoordinates.get(0)); CoordinateSequence shellPoints = new CoordinateArraySequence(shellCoordinates.toArray(new Coordinate[shellCoordinates.size()])); LinearRing shell = new LinearRing(shellPoints, geometryFactory); List<LinearRing> holes = new ArrayList<LinearRing>(); while (in.readBoolean()) { List<Coordinate> holeCoordinates = new ArrayList<Coordinate>(); while (in.readBoolean()) { holeCoordinates.add(new Coordinate(in.readDouble(), in.readDouble())); } holeCoordinates.add(holeCoordinates.get(0)); CoordinateSequence holePoints = new CoordinateArraySequence(shellCoordinates.toArray(new Coordinate[holeCoordinates.size()])); LinearRing hole = new LinearRing(holePoints, geometryFactory); holes.add(hole); } return new Polygon(shell, holes.isEmpty() ? null : holes.toArray(new LinearRing[holes.size()]), geometryFactory); } }
public static Polygon createPolygon(Coordinate[] aCoordinates) { if (!aCoordinates[0].equals(aCoordinates[aCoordinates.length - 1])) { aCoordinates = Arrays.copyOf(aCoordinates, aCoordinates.length + 1); aCoordinates[aCoordinates.length - 1] = aCoordinates[0]; } CoordinateSequence cSeq = csFactory.create(aCoordinates); return gFactory.createPolygon(new LinearRing(cSeq, gFactory), null); }
public static Polygon createPolygonWithHoles(Polygon aPolygon, Geometry[] aHoles) { CoordinateSequence polygonSeq = csFactory.create(getPolygonShell(aPolygon).getCoordinates()); LinearRing shell = new LinearRing(polygonSeq, gFactory); List<LinearRing> holes = new ArrayList<>(); if (aHoles != null) { for (Geometry aHole : aHoles) { Coordinate[] coord = aHole.getCoordinates(); if (coord.length > 1) { CoordinateSequence holeSeq = csFactory.create(coord); holes.add(new LinearRing(holeSeq, gFactory)); } } } LinearRing[] arHoles = new LinearRing[0]; return gFactory.createPolygon(shell, holes.toArray(arHoles)); }
public static Polygon addPoint2Polygon(Polygon aPoly, Point point2Add) { Coordinate[] oldCoordinates = aPoly.getCoordinates(); Coordinate[] newCoordinates = new Coordinate[oldCoordinates.length + 1]; System.arraycopy(oldCoordinates, 0, newCoordinates, 0, oldCoordinates.length - 1); newCoordinates[newCoordinates.length - 2] = point2Add.getCoordinate(); newCoordinates[newCoordinates.length - 1] = oldCoordinates[oldCoordinates.length - 1]; CoordinateSequence cSeq = csFactory.create(newCoordinates); return gFactory.createPolygon(new LinearRing(cSeq, gFactory), null); }
@Override public Geometry getBoundingBox() { if (getInternalGrid() == null) { LOGGER.warning("FIXME:getBoundingBox called while grid is null"); return null; } if (boundingBox == null) { LOGGER.finest("Initializing bounding box for Grid"); Coordinate[] coordinates = new Coordinate[5]; Envelope2D e2d = getInternalGrid().getEnvelope2D(); coordinates[0] = new Coordinate(e2d.x, e2d.y); coordinates[1] = new Coordinate(e2d.x + e2d.width, e2d.y); coordinates[2] = new Coordinate(e2d.x + e2d.width, e2d.y + e2d.height); coordinates[3] = new Coordinate(e2d.x, e2d.y + e2d.height); coordinates[4] = new Coordinate(e2d.x, e2d.y); GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); LinearRing linearRing = new LinearRing(new CoordinateArraySequence(coordinates), geometryFactory); boundingBox = new Polygon(linearRing, null, geometryFactory); } return boundingBox; }
public static Polygon createPolygon(Point begPoint, Point endPoint) { Coordinate[] coordinates = new Coordinate[4]; coordinates[0] = new Coordinate(begPoint.getX(), begPoint.getY()); coordinates[1] = new Coordinate(endPoint.getX(), endPoint.getY()); coordinates[2] = new Coordinate(endPoint.getX(), endPoint.getY()); coordinates[3] = new Coordinate(begPoint.getX(), begPoint.getY()); CoordinateSequence cSeq = csFactory.create(coordinates); return gFactory.createPolygon(new LinearRing(cSeq, gFactory), null); }
private Geometry buildGeometry() { Coordinate[] coordinates = new Coordinate[locations.size()]; for (int i = 0; i < locations.size(); i++) { coordinates[i] = new Coordinate( locations.get(i).getLongitude(), locations.get(i).getLatitude()); } GeometryFactory factory = SPATIAL_CONTEXT.getGeometryFactory(); CoordinateSequence sequence = factory.getCoordinateSequenceFactory().create(coordinates); switch (getShapeType()) { case POINT: return new Point(sequence, factory); case LINESTRING: return new LineString(sequence, factory); case POLYGON: LinearRing shell = new LinearRing(sequence, factory); return new Polygon(shell, null, factory); default: throw new IllegalStateException("Unrecognized geometry"); } }
@Test public void updateGeometry() throws SQLException { userId = 3; ResourceId formId = CuidAdapter.adminLevelFormClass(1); ResourceId recordId = entity(1); ResourceId fieldId = CuidAdapter.field(formId, CuidAdapter.GEOMETRY_FIELD); Optional<FormStorage> storage = catalog.getForm(formId); GeometryFactory factory = new GeometryFactory(); Polygon polygon = new Polygon(new LinearRing(new CoordinateArraySequence( new Coordinate[]{ new Coordinate(100, 0), new Coordinate(101, 0), new Coordinate(101, 1), new Coordinate(100, 1), new Coordinate(100, 0) }), factory), new LinearRing[0], factory); storage.get().updateGeometry(recordId, fieldId, polygon); query(formId, "_id", "ST_XMIN(boundary)", "ST_XMAX(boundary)"); }
public final void setBoundingBox(BoundingBox boundingBox) { this.boundingBox = boundingBox; LOGGER.finest("Initializing bounding box for Grid"); Coordinate[] coordinates = new Coordinate[5]; coordinates[0] = new Coordinate(boundingBox.getMinX(), boundingBox.getMinY()); coordinates[1] = new Coordinate(boundingBox.getMaxX(), boundingBox.getMinY()); coordinates[2] = new Coordinate(boundingBox.getMaxX(), boundingBox.getMaxY()); coordinates[3] = new Coordinate(boundingBox.getMinX(), boundingBox.getMaxY()); coordinates[4] = new Coordinate(boundingBox.getMinX(), boundingBox.getMinY()); GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); LinearRing linearRing = new LinearRing(new CoordinateArraySequence(coordinates), geometryFactory); boundingBoxGeometry = new Polygon(linearRing, null, geometryFactory); Dimension d = gridCellSize.getDimension(boundingBox); int bands = 1; Point location = new Point(0, 0); this.raster = WritableRaster.createBandedRaster(DataBuffer.TYPE_INT, d.width, d.height, bands, location); LOGGER.log(Level.FINEST, "created raster with dimension{0}", d); // fill raster with min values for (int iw = 0; iw < d.width; iw++) { for (int ih = 0; ih < d.height; ih++) { raster.setSample(iw, ih, 0, Integer.MIN_VALUE); } } }