org.locationtech.jts.geom.LinearRing Java Examples
The following examples show how to use
org.locationtech.jts.geom.LinearRing.
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: LasIndexer.java From hortonmachine with GNU General Public License v3.0 | 7 votes |
public static Polygon envelopeToPolygon( Envelope envelope ) { double w = envelope.getMinX(); double e = envelope.getMaxX(); double s = envelope.getMinY(); double n = envelope.getMaxY(); Coordinate[] coords = new Coordinate[5]; coords[0] = new Coordinate(w, n); coords[1] = new Coordinate(e, n); coords[2] = new Coordinate(e, s); coords[3] = new Coordinate(w, s); coords[4] = new Coordinate(w, n); GeometryFactory gf = GeometryUtilities.gf(); LinearRing linearRing = gf.createLinearRing(coords); Polygon polygon = gf.createPolygon(linearRing, null); return polygon; }
Example #2
Source File: FeatureUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Create a {@link Polygon} from an {@link Envelope}. * * @param envelope the envelope to convert. * @return the created polygon. */ public static Polygon envelopeToPolygon( Envelope2D envelope ) { double w = envelope.getMinX(); double e = envelope.getMaxX(); double s = envelope.getMinY(); double n = envelope.getMaxY(); Coordinate[] coords = new Coordinate[5]; coords[0] = new Coordinate(w, n); coords[1] = new Coordinate(e, n); coords[2] = new Coordinate(e, s); coords[3] = new Coordinate(w, s); coords[4] = new Coordinate(w, n); GeometryFactory gf = GeometryUtilities.gf(); LinearRing linearRing = gf.createLinearRing(coords); Polygon polygon = gf.createPolygon(linearRing, null); return polygon; }
Example #3
Source File: FeatureUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Create a {@link Polygon} from an {@link Envelope}. * * @param envelope the envelope to convert. * @return the created polygon. */ public static Polygon envelopeToPolygon( Envelope envelope ) { double w = envelope.getMinX(); double e = envelope.getMaxX(); double s = envelope.getMinY(); double n = envelope.getMaxY(); Coordinate[] coords = new Coordinate[5]; coords[0] = new Coordinate(w, n); coords[1] = new Coordinate(e, n); coords[2] = new Coordinate(e, s); coords[3] = new Coordinate(w, s); coords[4] = new Coordinate(w, n); GeometryFactory gf = GeometryUtilities.gf(); LinearRing linearRing = gf.createLinearRing(coords); Polygon polygon = gf.createPolygon(linearRing, null); return polygon; }
Example #4
Source File: GeometryConverterAdapter.java From importer-exporter with Apache License 2.0 | 6 votes |
private Polygon convertPolygonToJTS(GeometryObject geomObj) { double[][] coordinates = geomObj.getCoordinates(); int dimension = geomObj.getDimension(); LinearRing shell = null; LinearRing[] holes = geomObj.getNumElements() - 1 > 0 ? new LinearRing[geomObj.getNumElements() - 1] : null; for (int i = 0; i < coordinates.length; i++) { LinearRing ring = factory.createLinearRing(getCoordinatesArray(coordinates[i], dimension)); if (i == 0) shell = ring; else holes[i - 1] = ring; } return factory.createPolygon(shell, holes); }
Example #5
Source File: JTSHelperTest.java From arctic-sea with Apache License 2.0 | 6 votes |
@Test public void shouldReverseMultiPolygon() throws OwsExceptionReport { final GeometryFactory factory = getGeometryFactoryForSRID(4326); testReverse(factory.createMultiPolygon(new Polygon[]{ factory.createPolygon( factory.createLinearRing(randomCoordinateRing(13)), new LinearRing[]{factory.createLinearRing(randomCoordinateRing(130)), factory.createLinearRing(randomCoordinateRing(4121)), factory.createLinearRing(randomCoordinateRing(12))}), factory.createPolygon( factory.createLinearRing(randomCoordinateRing(8)), new LinearRing[]{factory.createLinearRing(randomCoordinateRing(1101)), factory.createLinearRing(randomCoordinateRing(413)), factory.createLinearRing(randomCoordinateRing(123))}), factory.createPolygon( factory.createLinearRing(randomCoordinateRing(89)), new LinearRing[]{factory.createLinearRing(randomCoordinateRing(112)), factory.createLinearRing(randomCoordinateRing(4)), factory.createLinearRing(randomCoordinateRing(43))})})); }
Example #6
Source File: TWKBReader.java From geowave with Apache License 2.0 | 6 votes |
private Polygon readPolygon( final PrecisionReader precision, final byte metadata, final ByteBuffer input) throws IOException { if ((metadata & TWKBUtils.EMPTY_GEOMETRY) != 0) { return GeometryUtils.GEOMETRY_FACTORY.createPolygon(); } final int numRings = VarintUtils.readUnsignedInt(input); final LinearRing exteriorRing = GeometryUtils.GEOMETRY_FACTORY.createLinearRing(precision.readPointArray(input)); final LinearRing[] interiorRings = new LinearRing[numRings - 1]; for (int i = 0; i < (numRings - 1); i++) { interiorRings[i] = GeometryUtils.GEOMETRY_FACTORY.createLinearRing(precision.readPointArray(input)); } return GeometryUtils.GEOMETRY_FACTORY.createPolygon(exteriorRing, interiorRings); }
Example #7
Source File: VectorTileDecoderTest.java From java-vector-tile with Apache License 2.0 | 6 votes |
public void testPolygon() throws IOException { // Exterior ring in counter-clockwise order. LinearRing shell = gf.createLinearRing(new Coordinate[] { new Coordinate(10, 10), new Coordinate(20, 10), new Coordinate(20, 20), new Coordinate(10, 20), new Coordinate(10, 10) }); assertTrue(shell.isClosed()); assertTrue(shell.isValid()); Geometry geometry = gf.createPolygon(shell, new LinearRing[] {}); assertTrue(geometry.isValid()); Map<String, Object> attributes = new HashMap<String, Object>(); String layerName = "layer"; VectorTileEncoder e = new VectorTileEncoder(512); e.addFeature(layerName, attributes, geometry); byte[] encoded = e.encode(); VectorTileDecoder d = new VectorTileDecoder(); assertEquals(1, d.decode(encoded).getLayerNames().size()); assertEquals(layerName, d.decode(encoded).getLayerNames().iterator().next()); assertEquals(attributes, d.decode(encoded, layerName).asList().get(0).getAttributes()); assertEquals(geometry, d.decode(encoded, layerName).asList().get(0).getGeometry()); }
Example #8
Source File: FilterToElastic.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
private void visitLiteralGeometry(Literal expression) throws IOException { // evaluate the literal and store it for later currentGeometry = (Geometry) evaluateLiteral(expression, Geometry.class); if ( currentGeometry instanceof LinearRing ) { // convert LinearRing to LineString final GeometryFactory factory = currentGeometry.getFactory(); final LinearRing linearRing = (LinearRing) currentGeometry; final CoordinateSequence coordinates; coordinates = linearRing.getCoordinateSequence(); currentGeometry = factory.createLineString(coordinates); } final String geoJson = new GeometryJSON().toString(currentGeometry); currentShapeBuilder = mapReader.readValue(geoJson); }
Example #9
Source File: SimpleFeatureShapeFigure.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private Geometry getGeometryFromShape(Shape shape) { AwtGeomToJtsGeomConverter converter = new AwtGeomToJtsGeomConverter(); Geometry geometry; // May need to handle more cases here in the future! (nf) if (Polygon.class.isAssignableFrom(geometryType)) { geometry = converter.createPolygon(shape); } else if (MultiPolygon.class.isAssignableFrom(geometryType)) { geometry = converter.createMultiPolygon(shape); } else if (LinearRing.class.isAssignableFrom(geometryType)) { geometry = converter.createLinearRingList(shape).get(0); } else if (LineString.class.isAssignableFrom(geometryType)) { geometry = converter.createLineStringList(shape).get(0); } else { geometry = converter.createMultiLineString(shape); } return geometry; }
Example #10
Source File: SubsetUI.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private void getGeoRegion() { geoRegion = null; geoText.setText(""); if (geoCoordRadio.isSelected()) { final GeoPos[] selectionBox = worldMapUI.getSelectionBox(); if (selectionBox != null) { final Coordinate[] coords = new Coordinate[selectionBox.length + 1]; for (int i = 0; i < selectionBox.length; ++i) { coords[i] = new Coordinate(selectionBox[i].getLon(), selectionBox[i].getLat()); } coords[selectionBox.length] = new Coordinate(selectionBox[0].getLon(), selectionBox[0].getLat()); final GeometryFactory geometryFactory = new GeometryFactory(); final LinearRing linearRing = geometryFactory.createLinearRing(coords); geoRegion = geometryFactory.createPolygon(linearRing, null); geoText.setText(geoRegion.toText()); } } }
Example #11
Source File: SimpleFeatureShapeFigureTest.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private LinearRing createLinearRing() { return gf.createLinearRing(new Coordinate[]{ new Coordinate(0, 0), new Coordinate(1, 0), new Coordinate(1, 1), new Coordinate(0, 1), new Coordinate(0, 0), }); }
Example #12
Source File: GeometryUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Creates a polygon that may help out as placeholder. * * @return a dummy {@link Polygon}. */ public static Polygon createDummyPolygon() { Coordinate[] c = new Coordinate[]{new Coordinate(0.0, 0.0), new Coordinate(1.0, 1.0), new Coordinate(1.0, 0.0), new Coordinate(0.0, 0.0)}; LinearRing linearRing = gf().createLinearRing(c); return gf().createPolygon(linearRing, null); }
Example #13
Source File: CoverageUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Create a bounds polygon of a {@link GridCoverage2D}. * * @param gridCoverage the coverage to use. * @return the bounding polygon. */ public static Polygon getRegionPolygon( GridCoverage2D gridCoverage ) { Envelope2D env = gridCoverage.getEnvelope2D(); Coordinate[] c = new Coordinate[]{new Coordinate(env.getMinX(), env.getMinY()), new Coordinate(env.getMinX(), env.getMaxY()), new Coordinate(env.getMaxX(), env.getMaxY()), new Coordinate(env.getMaxX(), env.getMinY()), new Coordinate(env.getMinX(), env.getMinY())}; GeometryFactory gf = GeometryUtilities.gf(); LinearRing linearRing = gf.createLinearRing(c); Polygon polygon = gf.createPolygon(linearRing, null); return polygon; }
Example #14
Source File: GeometryTranslator.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Builds a polygon feature from a dwg solid. * */ public SimpleFeature convertDwgSolid( String typeName, String layerName, DwgSolid solid, int id ) { double[] p1 = solid.getCorner1(); double[] p2 = solid.getCorner2(); double[] p3 = solid.getCorner3(); double[] p4 = solid.getCorner4(); Point2D[] ptos = new Point2D[]{new Point2D.Double(p1[0], p1[1]), new Point2D.Double(p2[0], p2[1]), new Point2D.Double(p3[0], p3[1]), new Point2D.Double(p4[0], p4[1])}; CoordinateList coordList = new CoordinateList(); for( int j = 0; j < ptos.length; j++ ) { Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY()); coordList.add(coord); } coordList.closeRing(); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName(typeName); b.setCRS(crs); b.add(THE_GEOM, Polygon.class); b.add(LAYER, String.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); LinearRing linearRing = gF.createLinearRing(coordList.toCoordinateArray()); Geometry polygon = gF.createPolygon(linearRing, null); Object[] values = new Object[]{polygon, layerName}; builder.addAll(values); return builder.buildFeature(typeName + "." + id); }
Example #15
Source File: TestGeometryUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testLines2Polygon() throws Exception { GeometryFactory gf = GeometryUtilities.gf(); LineString l1 = gf.createLineString(new Coordinate[]{negll, negul, ul}); LineString l2 = gf.createLineString(new Coordinate[]{ur, lr}); LineString l3 = gf.createLineString(new Coordinate[]{ll, lr}); Polygon lines2Polygon = GeometryUtilities.lines2Polygon(true, l1, l2, l3); Coordinate[] polygonCoord = new Coordinate[]{negll, negul, ul, ur, lr, lr, ll, negll}; LinearRing linearRing = gf.createLinearRing(polygonCoord); Polygon expectedPolygon = gf.createPolygon(linearRing, null); assertTrue(lines2Polygon.equalsExact(expectedPolygon)); }
Example #16
Source File: SpatialiteWKBReader.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private Polygon readPolygon() throws IOException { int numRings = dis.readInt(); LinearRing[] holes = null; if (numRings > 1) holes = new LinearRing[numRings - 1]; LinearRing shell = readLinearRing(); for( int i = 0; i < numRings - 1; i++ ) { holes[i] = readLinearRing(); } return factory.createPolygon(shell, holes); }
Example #17
Source File: Polygon.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * To geometry * * @param factory GeometryFactory * @return Geometry */ public Geometry toGeometry(GeometryFactory factory) { PointD p; Coordinate[] cs = new Coordinate[_outLine.size()]; for (int i = 0; i < cs.length; i++) { p = _outLine.get(i); cs[i] = new Coordinate(p.X, p.Y); } if (cs[0].x != cs[cs.length -1].x){ cs = (Coordinate[])DataConvert.resizeArray(cs, cs.length + 1); cs[cs.length - 1] = new Coordinate(cs[0].x, cs[1].y); } LinearRing shell = factory.createLinearRing(cs); LinearRing[] holes = new LinearRing[this._holeLines.size()]; int n; boolean isclose; for (int j = 0; j < holes.length; j++) { List<? extends PointD> hole = this._holeLines.get(j); n = hole.size(); isclose = true; if (n == 3) { n = 4; isclose = false; } cs = new Coordinate[n]; for (int i = 0; i < hole.size(); i++) { p = hole.get(i); cs[i] = new Coordinate(p.X, p.Y); } if (!isclose){ cs[n - 1] = new Coordinate(hole.get(0).X, hole.get(0).Y); } holes[j] = factory.createLinearRing(cs); } return factory.createPolygon(shell, holes); }
Example #18
Source File: ShapeConverter.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private void coordinatesToGeometry(ArrayList<Coordinate> coordinates, ArrayList<Geometry> geometries) { if (coordinates.size() > 0) { if (coordinates.get(0).equals(coordinates.get(coordinates.size() - 1))) { LinearRing linearRing = geometryFactory.createLinearRing(coordinates.toArray(new Coordinate[coordinates.size()])); geometries.add(linearRing); } else { LineString lineString = geometryFactory.createLineString(coordinates.toArray(new Coordinate[coordinates.size()])); geometries.add(lineString); } coordinates.clear(); } }
Example #19
Source File: FeatureLayerConfigurationPersistencyTest.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
@Override protected Layer createLayer(LayerType layerType) throws Exception { final PropertySet configuration = layerType.createLayerConfig(null); final URL shapefileUrl = getClass().getResource("bundeslaender.shp"); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_URL, shapefileUrl); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_CRS, DefaultGeographicCRS.WGS84); final Coordinate[] coordinates = { new Coordinate(-10, 50), new Coordinate(+10, 50), new Coordinate(+10, 30), new Coordinate(-10, 30), new Coordinate(-10, 50) }; final GeometryFactory geometryFactory = new GeometryFactory(); final LinearRing ring = geometryFactory.createLinearRing(coordinates); final Polygon clipGeometry = geometryFactory.createPolygon(ring, new LinearRing[0]); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_CLIP_GEOMETRY, clipGeometry); configuration.setValue(FeatureLayerType.PROPERTY_NAME_SLD_STYLE, createStyle()); FeatureCollection<SimpleFeatureType, SimpleFeature> fc; try { fc = FeatureUtils.createFeatureCollection( shapefileUrl, DefaultGeographicCRS.WGS84, clipGeometry); } catch (IOException e) { throw new IllegalArgumentException(e); } return new FeatureLayer(layerType, fc, configuration); }
Example #20
Source File: VectorTileDecoderTest.java From java-vector-tile with Apache License 2.0 | 5 votes |
public void testPolygonWithHole() throws IOException { // Exterior ring in counter-clockwise order. LinearRing shell = gf.createLinearRing(new Coordinate[] { new Coordinate(10, 10), new Coordinate(20, 10), new Coordinate(20, 20), new Coordinate(10, 20), new Coordinate(10, 10) }); assertTrue(shell.isClosed()); assertTrue(shell.isValid()); Geometry geometry = gf.createPolygon(shell, new LinearRing[] {}); assertTrue(geometry.isValid()); // Interior ring in clockwise order. LinearRing hole = gf.createLinearRing(new Coordinate[] { new Coordinate(11, 11), new Coordinate(11, 19), new Coordinate(19, 19), new Coordinate(19, 11), new Coordinate(11, 11) }); assertTrue(hole.isClosed()); assertTrue(hole.isValid()); assertTrue(geometry.contains(hole)); geometry = gf.createPolygon(shell, new LinearRing[] { hole }); assertTrue(geometry.isValid()); Map<String, Object> attributes = new HashMap<String, Object>(); String layerName = "layer"; VectorTileEncoder e = new VectorTileEncoder(512); e.addFeature(layerName, attributes, geometry); byte[] encoded = e.encode(); VectorTileDecoder d = new VectorTileDecoder(); assertEquals(1, d.decode(encoded).getLayerNames().size()); assertEquals(layerName, d.decode(encoded).getLayerNames().iterator().next()); assertEquals(attributes, d.decode(encoded, layerName).asList().get(0).getAttributes()); assertEquals(geometry.toText(), d.decode(encoded, layerName).asList().get(0).getGeometry().toText()); assertEquals(geometry, d.decode(encoded, layerName).asList().get(0).getGeometry()); }
Example #21
Source File: TWKBReader.java From geowave with Apache License 2.0 | 5 votes |
private MultiPolygon readMultiPolygon( final PrecisionReader precision, final byte metadata, final ByteBuffer input) throws IOException { if ((metadata & TWKBUtils.EMPTY_GEOMETRY) != 0) { return GeometryUtils.GEOMETRY_FACTORY.createMultiPolygon(); } final int numPolygons = VarintUtils.readUnsignedInt(input); final Polygon[] polygons = new Polygon[numPolygons]; int numRings; for (int i = 0; i < numPolygons; i++) { numRings = VarintUtils.readUnsignedInt(input); if (numRings == 0) { polygons[i] = GeometryUtils.GEOMETRY_FACTORY.createPolygon(); continue; } final LinearRing exteriorRing = GeometryUtils.GEOMETRY_FACTORY.createLinearRing(precision.readPointArray(input)); final LinearRing[] interiorRings = new LinearRing[numRings - 1]; for (int j = 0; j < (numRings - 1); j++) { interiorRings[j] = GeometryUtils.GEOMETRY_FACTORY.createLinearRing(precision.readPointArray(input)); } polygons[i] = GeometryUtils.GEOMETRY_FACTORY.createPolygon(exteriorRing, interiorRings); } return GeometryUtils.GEOMETRY_FACTORY.createMultiPolygon(polygons); }
Example #22
Source File: GeometryTransform.java From sis with Apache License 2.0 | 5 votes |
/** * Transforms the given geometry. This method delegates to one of the {@code transform(…)} methods * based on the type of the given geometry. * * @param geom the geometry to transform. * @return the transformed geometry. * @throws TransformException if an error occurred while transforming the geometry. */ public Geometry transform(final Geometry geom) throws TransformException { if (geom instanceof Point) return transform((Point) geom); if (geom instanceof MultiPoint) return transform((MultiPoint) geom); if (geom instanceof LinearRing) return transform((LinearRing) geom); // Must be tested before LineString. if (geom instanceof LineString) return transform((LineString) geom); if (geom instanceof MultiLineString) return transform((MultiLineString) geom); if (geom instanceof Polygon) return transform((Polygon) geom); if (geom instanceof MultiPolygon) return transform((MultiPolygon) geom); if (geom instanceof GeometryCollection) return transform((GeometryCollection) geom); throw new IllegalArgumentException(Errors.format(Errors.Keys.UnsupportedType_1, Classes.getClass(geom))); }
Example #23
Source File: GeometryTransform.java From sis with Apache License 2.0 | 5 votes |
/** * Transforms the given polygon. Can be invoked directly if the type is known at compile-time, * or indirectly through a call to the more generic {@link #transform(Geometry)} method. * * @param geom the polygon to transform. * @return the transformed polygon. * @throws TransformException if an error occurred while transforming the geometry. */ public Polygon transform(final Polygon geom) throws TransformException { final LinearRing exterior = transform((LinearRing) geom.getExteriorRing()); final LinearRing[] holes = new LinearRing[geom.getNumInteriorRing()]; for (int i = 0; i < holes.length; i++) { holes[i] = transform((LinearRing) geom.getInteriorRingN(i)); } return geometryFactory.createPolygon(exterior, holes); }
Example #24
Source File: PolygonBuilder.java From crate with Apache License 2.0 | 5 votes |
protected Polygon toPolygon(GeometryFactory factory) { final LinearRing shell = linearRing(factory, this.shell.coordinates); final LinearRing[] holes = new LinearRing[this.holes.size()]; Iterator<LineStringBuilder> iterator = this.holes.iterator(); for (int i = 0; iterator.hasNext(); i++) { holes[i] = linearRing(factory, iterator.next().coordinates); } return factory.createPolygon(shell, holes); }
Example #25
Source File: GeoUtils.java From elasticsearch-plugin-geoshape with MIT License | 5 votes |
public static Polygon removeDuplicateCoordinates(Polygon polygon) { LinearRing polygonShell = removeDuplicateCoordinates((LinearRing) polygon.getExteriorRing()); LinearRing[] holes = new LinearRing[polygon.getNumInteriorRing()]; for (int i = 0; i < polygon.getNumInteriorRing(); i++) { holes[i] = removeDuplicateCoordinates((LinearRing) polygon.getInteriorRingN(i)); } return polygon.getFactory().createPolygon(polygonShell, holes); }
Example #26
Source File: GeoJSONTest.java From arctic-sea with Apache License 2.0 | 5 votes |
private LinearRing randomLinearRing(int srid) { Coordinate p = randomCoordinate(); LinearRing geometry = geometryFactory.createLinearRing( new Coordinate[] { p, randomCoordinate(), randomCoordinate(), randomCoordinate(), p }); geometry.setSRID(srid); return geometry; }
Example #27
Source File: JTSHelper.java From arctic-sea with Apache License 2.0 | 5 votes |
public Geometry convertSequence(Geometry geometry) { if (geometry instanceof Point) { return createPoint(((Point) geometry).getCoordinateSequence()); } else if (geometry instanceof LinearRing) { return createLinearRing(((LinearRing) geometry).getCoordinates()); } else if (geometry instanceof LineString) { return createLineString(((LineString) geometry).getCoordinates()); } else if (geometry instanceof Polygon) { LinearRing[] linearRings = new LinearRing[((Polygon) geometry).getNumInteriorRing()]; for (int i = 0; i < ((Polygon) geometry).getNumInteriorRing(); i++) { linearRings[i] = (LinearRing) convertSequence(((Polygon) geometry).getInteriorRingN(i)); } return createPolygon((LinearRing) convertSequence(((Polygon) geometry).getExteriorRing()), linearRings); } else if (geometry instanceof MultiPoint) { return createMultiPointFromCoords(((MultiPoint) geometry).getCoordinates()); } else if (geometry instanceof MultiLineString) { LineString[] lineStrings = new LineString[((MultiLineString) geometry).getNumGeometries()]; for (int i = 0; i < ((MultiLineString) geometry).getNumGeometries(); i++) { lineStrings[i] = (LineString) convertSequence(((MultiLineString) geometry).getGeometryN(i)); } return createMultiLineString(lineStrings); } else if (geometry instanceof MultiPolygon) { Polygon[] polygons = new Polygon[((MultiPolygon) geometry).getNumGeometries()]; for (int i = 0; i < ((MultiPolygon) geometry).getNumGeometries(); i++) { polygons[i] = (Polygon) convertSequence(((MultiPolygon) geometry).getGeometryN(i)); } return createMultiPolygon(polygons); } else if (geometry instanceof GeometryCollection) { Geometry[] geometries = new Geometry[((GeometryCollection) geometry).getNumGeometries()]; for (int i = 0; i < ((GeometryCollection) geometry).getNumGeometries(); i++) { geometries[i] = convertSequence(((GeometryCollection) geometry).getGeometryN(i)); } return createGeometryCollection(geometries); } return geometry; }
Example #28
Source File: ElasticParserUtil.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
private Polygon createPolygon(final List<List<List<Object>>> posList) { final Coordinate[] shellCoordinates = createCoordinates(posList.get(0)); final LinearRing shell = geometryFactory.createLinearRing(shellCoordinates); final LinearRing[] holes = new LinearRing[posList.size() - 1]; for (int i = 1; i < posList.size(); i++) { final Coordinate[] coordinates = createCoordinates(posList.get(i)); holes[i - 1] = geometryFactory.createLinearRing(coordinates); } return geometryFactory.createPolygon(shell, holes); }
Example #29
Source File: KMLManagement.java From GeoTriples with Apache License 2.0 | 5 votes |
public LinearRing createLinearRing(CoordinateSequence cs) { if (cs.getCoordinate(0).equals(cs.getCoordinate(cs.size() - 1))) return super.createLinearRing(cs); // add a new coordinate to close the ring CoordinateSequenceFactory csFact = getCoordinateSequenceFactory(); CoordinateSequence csNew = csFact.create(cs.size() + 1, cs.getDimension()); CoordinateSequences.copy(cs, 0, csNew, 0, cs.size()); CoordinateSequences.copyCoord(csNew, 0, csNew, csNew.size() - 1); return super.createLinearRing(csNew); }
Example #30
Source File: GeoTiffReaderExample.java From GeoTriples with Apache License 2.0 | 5 votes |
public LinearRing createLinearRing(CoordinateSequence cs) { if (cs.getCoordinate(0).equals(cs.getCoordinate(cs.size() - 1))) return super.createLinearRing(cs); // add a new coordinate to close the ring CoordinateSequenceFactory csFact = getCoordinateSequenceFactory(); CoordinateSequence csNew = csFact.create(cs.size() + 1, cs.getDimension()); CoordinateSequences.copy(cs, 0, csNew, 0, cs.size()); CoordinateSequences.copyCoord(csNew, 0, csNew, csNew.size() - 1); return super.createLinearRing(csNew); }