Java Code Examples for org.locationtech.jts.geom.Geometry#getCoordinate()
The following examples show how to use
org.locationtech.jts.geom.Geometry#getCoordinate() .
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: OmsLW06_SlopeToNetworkAdder.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
@Execute public void process() throws Exception { // creates the schema for the output shapefile FeatureExtender ext = new FeatureExtender(inNetPoints.getSchema(), new String[]{SLOPE}, new Class[]{Double.class}); pm.beginTask("extract points...", inNetPoints.size()); /* * reads the network */ List<SimpleFeature> netList = FeatureUtilities.featureCollectionToList(inNetPoints); outNetPoints = new DefaultFeatureCollection(); for( SimpleFeature netFeature : netList ) { Geometry geometry = (Geometry) netFeature.getDefaultGeometry(); Coordinate coordinate = geometry.getCoordinate(); // gets the slope in the correspondent raster cell double slope = CoverageUtilities.getValue(inSlope, coordinate); // extents and adds the data to the output FC SimpleFeature extendedFeature = ext.extendFeature(netFeature, new Object[]{slope}); ((DefaultFeatureCollection) outNetPoints).add(extendedFeature); pm.worked(1); } pm.done(); }
Example 2
Source File: RiverSectionsFromDtmExtractor.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Extract a {@link RiverPoint}. * * @param riverLine the geometry of the main river. * @param elevIter the elevation raster. * @param gridGeometry the raster geometry. * @param progressiveDistance the progressive distance along the main river. * @param ks the KS for the section. * @param leftPoint the left point of the section. * @param rightPoint the right point of the section. * @return the created {@link RiverPoint}. * @throws TransformException */ private RiverPoint getNetworkPoint( LineString riverLine, RandomIter elevIter, GridGeometry2D gridGeometry, double progressiveDistance, Double ks, Coordinate leftPoint, Coordinate rightPoint ) throws TransformException { List<ProfilePoint> sectionPoints = CoverageUtilities.doProfile(elevIter, gridGeometry, rightPoint, leftPoint); List<Coordinate> coordinate3dList = new ArrayList<Coordinate>(); for( ProfilePoint sectionPoint : sectionPoints ) { Coordinate position = sectionPoint.getPosition(); position.z = sectionPoint.getElevation(); coordinate3dList.add(position); } LineString sectionLine3d = gf.createLineString(coordinate3dList.toArray(new Coordinate[0])); Geometry crossPoint = sectionLine3d.intersection(riverLine); Coordinate coordinate = crossPoint.getCoordinate(); if (coordinate == null) { return null; } int[] colRow = CoverageUtilities.colRowFromCoordinate(coordinate, gridGeometry, null); double elev = elevIter.getSampleDouble(colRow[0], colRow[1], 0); coordinate.z = elev; RiverPoint netPoint = new RiverPoint(coordinate, progressiveDistance, sectionLine3d, ks); return netPoint; }
Example 3
Source File: TestVectorTransformer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testVectorTransformer() throws Exception { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("test"); b.setCRS(DefaultGeographicCRS.WGS84); b.add("the_geom", Point.class); b.add("id", Integer.class); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Point point = GeometryUtilities.gf().createPoint(new Coordinate(0, 0)); Object[] values = new Object[]{point, 1}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0"); newCollection.add(feature); OmsVectorTransformer transformer = new OmsVectorTransformer(); transformer.inVector = newCollection; transformer.pTransX = 1.0; transformer.pTransY = -1.0; transformer.process(); SimpleFeatureCollection outFeatures = transformer.outVector; Geometry g = FeatureUtilities.featureCollectionToGeometriesList(outFeatures, false, null).get(0); Coordinate coord = g.getCoordinate(); assertEquals(coord.x, 1.0, 0.00001); assertEquals(coord.y, -1.0, 0.00001); }
Example 4
Source File: TestVectorReader.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testPropertiesReader() throws Exception { URL dataUrl = this.getClass().getClassLoader().getResource("example.properties"); String propertiesPath = new File(dataUrl.toURI()).getAbsolutePath(); // now read it again OmsVectorReader reader = new OmsVectorReader(); reader.file = propertiesPath; reader.process(); SimpleFeatureCollection readFC = reader.outVector; FeatureIterator<SimpleFeature> featureIterator = readFC.features(); while( featureIterator.hasNext() ) { SimpleFeature f = featureIterator.next(); int id = ((Number) f.getAttribute("id")).intValue(); Geometry geometry = (Geometry) f.getDefaultGeometry(); Coordinate coordinate = geometry.getCoordinate(); if (id == 1) { assertEquals(coordinate.x, 0.0); assertEquals(coordinate.y, 0.0); } if (id == 2) { assertEquals(coordinate.x, 10.0); assertEquals(coordinate.y, 10.0); } if (id == 3) { assertEquals(coordinate.x, 20.0); assertEquals(coordinate.y, 20.0); } if (id == 4) { String attribute = f.getAttribute("name").toString(); assertEquals(attribute, "justin deolivera"); } } }
Example 5
Source File: TestVectorReprojector.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testVectorReprojector() throws Exception { SimpleFeatureCollection testFC = HMTestMaps.getTestFC(); OmsVectorReprojector reprojector = new OmsVectorReprojector(); reprojector.inVector = testFC; reprojector.pCode = "EPSG:4326"; reprojector.pm = pm; reprojector.process(); CoordinateReferenceSystem sourceCRS = HMTestMaps.getCrs(); CoordinateReferenceSystem targetCRS = CrsUtilities.getCrsFromSrid(4326); MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS); SimpleFeatureCollection outFC = reprojector.outVector; FeatureIterator<SimpleFeature> featureIterator = outFC.features(); SimpleFeatureIterator originalFeatureIterator = testFC.features(); while( featureIterator.hasNext() ) { SimpleFeature feature = featureIterator.next(); Geometry geometry = (Geometry) feature.getDefaultGeometry(); Coordinate coordinate = geometry.getCoordinate(); SimpleFeature originalFeature = originalFeatureIterator.next(); Coordinate origCoord = ((Geometry) originalFeature.getDefaultGeometry()).getCoordinate(); Coordinate reprojected = JTS.transform(origCoord, null, transform); assertEquals(reprojected.x, coordinate.x, delta); assertEquals(reprojected.y, coordinate.y, delta); } featureIterator.close(); }
Example 6
Source File: OmsEpanetInpGenerator.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private String handleCoordinates( List<SimpleFeature> junctionsList, List<SimpleFeature> reservoirsList, List<SimpleFeature> tanksList ) throws IOException { ArrayList<SimpleFeature> nodesList = new ArrayList<SimpleFeature>(); nodesList.addAll(junctionsList); nodesList.addAll(reservoirsList); nodesList.addAll(tanksList); StringBuilder sbJunctionsCoords = new StringBuilder(); sbJunctionsCoords.append("\n\n[COORDINATES]\n"); sbJunctionsCoords.append(";NODE").append(SPACER); sbJunctionsCoords.append("XCOORD").append(SPACER); sbJunctionsCoords.append("YCOORD").append(NL); for( SimpleFeature node : nodesList ) { Geometry geometry = (Geometry) node.getDefaultGeometry(); Coordinate coordinate = geometry.getCoordinate(); // [COORDINATES] Object attribute = getAttribute(node, Junctions.ID.getAttributeName()); sbJunctionsCoords.append(attribute.toString()); sbJunctionsCoords.append(SPACER); sbJunctionsCoords.append(coordinate.x); sbJunctionsCoords.append(SPACER); sbJunctionsCoords.append(coordinate.y); sbJunctionsCoords.append(NL); } sbJunctionsCoords.append("\n\n"); return sbJunctionsCoords.toString(); }
Example 7
Source File: OmsEpanetFeaturesSynchronizer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private SimpleFeature findWithinTolerance( Coordinate c, List<SimpleFeature>... nodesLists ) { for( List<SimpleFeature> nodeList : nodesLists ) { for( SimpleFeature node : nodeList ) { Geometry geometry = (Geometry) node.getDefaultGeometry(); Coordinate coord = geometry.getCoordinate(); if (coord.distance(c) <= pTol) { return node; } } } return null; }
Example 8
Source File: PointShape.java From MeteoInfo with GNU Lesser General Public License v3.0 | 4 votes |
/** * Constructor * @param geometry Geometry */ public PointShape(Geometry geometry) { Coordinate c = geometry.getCoordinate(); this.setPoint(new PointD(c.x, c.y)); }
Example 9
Source File: PointZShape.java From MeteoInfo with GNU Lesser General Public License v3.0 | 4 votes |
/** * Constructor * @param geometry Geometry */ public PointZShape(Geometry geometry) { CoordinateXYZM c = (CoordinateXYZM)geometry.getCoordinate(); this.setPoint(new PointZ(c.x, c.y, c.getZ(), c.getM())); }
Example 10
Source File: GeoUtils.java From elasticsearch-plugin-geoshape with MIT License | 4 votes |
public static GeoPoint getCentroidFromGeom(Geometry geom) { Geometry geom_centroid = geom.getCentroid(); return new GeoPoint(geom_centroid.getCoordinate().y, geom_centroid.getCoordinate().x); }
Example 11
Source File: OmsDelaunayTriangulation.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inMap); if (!EGeometryType.isPoint(inMap.getSchema().getGeometryDescriptor())) { throw new ModelsIllegalargumentException("The input geometry needs to be points.", this, pm); } if (fElev != null) { fElev = FeatureUtilities.findAttributeName(inMap.getSchema(), fElev); if (fElev == null) { throw new ModelsIllegalargumentException("Couldn't find field: " + fElev, this); } } CoordinateReferenceSystem crs = inMap.getBounds().getCoordinateReferenceSystem(); List<SimpleFeature> fList = FeatureUtilities.featureCollectionToList(inMap); pm.beginTask("Processing...", fList.size()); DelaunayTriangulationBuilder b = new DelaunayTriangulationBuilder(); List<Coordinate> cList = new ArrayList<Coordinate>(); for( SimpleFeature f : fList ) { Geometry geometry = (Geometry) f.getDefaultGeometry(); double elev = 0.0; if (fElev != null) elev = (Double) f.getAttribute(fElev); Coordinate c = geometry.getCoordinate(); c.z = elev; cList.add(c); pm.worked(1); } pm.done(); b.setSites(cList); List<Geometry> geosList = new ArrayList<Geometry>(); Geometry triangles = b.getTriangles(gf); for( int i = 0; i < triangles.getNumGeometries(); i++ ) { Geometry geometryN = triangles.getGeometryN(i); Coordinate[] coordinates = geometryN.getCoordinates(); double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; for( Coordinate coordinate : coordinates ) { min = Math.min(min, coordinate.z); max = Math.max(max, coordinate.z); } geometryN.setUserData(new String[]{"" + min, "" + max}); geosList.add(geometryN); } outMap = FeatureUtilities.featureCollectionFromGeometry(crs, geosList.toArray(new Geometry[0])); }
Example 12
Source File: OmsVoronoiDiagram.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inMap); if (!EGeometryType.isPoint(inMap.getSchema().getGeometryDescriptor())) { throw new ModelsIllegalargumentException("The input geometry needs to be points.", this, pm); } if (fElev != null) { fElev = FeatureUtilities.findAttributeName(inMap.getSchema(), fElev); if (fElev == null) { throw new ModelsIllegalargumentException("Couldn't find field: " + fElev, this); } } CoordinateReferenceSystem crs = inMap.getBounds().getCoordinateReferenceSystem(); List<SimpleFeature> fList = FeatureUtilities.featureCollectionToList(inMap); pm.beginTask("Processing...", fList.size()); VoronoiDiagramBuilder b = new VoronoiDiagramBuilder(); List<Coordinate> cList = new ArrayList<Coordinate>(); for( SimpleFeature f : fList ) { Geometry geometry = (Geometry) f.getDefaultGeometry(); double elev = 0.0; if (fElev != null) elev = (Double) f.getAttribute(fElev); Coordinate c = geometry.getCoordinate(); c.z = elev; cList.add(c); pm.worked(1); } pm.done(); b.setSites(cList); List<Geometry> geosList = new ArrayList<Geometry>(); Geometry diagram = b.getDiagram(gf); for( int i = 0; i < diagram.getNumGeometries(); i++ ) { Geometry geometryN = diagram.getGeometryN(i); Coordinate[] coordinates = geometryN.getCoordinates(); double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; for( Coordinate coordinate : coordinates ) { min = Math.min(min, coordinate.z); max = Math.max(max, coordinate.z); } geometryN.setUserData(new String[]{"" + min, "" + max}); geosList.add(geometryN); } outMap = FeatureUtilities.featureCollectionFromGeometry(crs, geosList.toArray(new Geometry[0])); }
Example 13
Source File: TestVectorReader.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
public void testShapefileReader() throws Exception { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("test"); b.setCRS(DefaultGeographicCRS.WGS84); b.add("the_geom", Point.class); b.add("id", Integer.class); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); SimpleFeatureType type = b.buildFeatureType(); for( int i = 0; i < 2; i++ ) { SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Point point = GeometryUtilities.gf().createPoint(new Coordinate(i, i)); Object[] values = new Object[]{point, i}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(type.getTypeName() + "." + i); newCollection.add(feature); } File tmpShape = File.createTempFile("testshp", ".shp"); if (tmpShape.exists()) { if (!tmpShape.delete()) throw new IOException(); } OmsVectorWriter writer = new OmsVectorWriter(); writer.file = tmpShape.getAbsolutePath(); writer.inVector = newCollection; writer.process(); // now read it again OmsVectorReader reader = new OmsVectorReader(); reader.file = tmpShape.getAbsolutePath(); reader.process(); SimpleFeatureCollection readFC = reader.outVector; FeatureIterator<SimpleFeature> featureIterator = readFC.features(); while( featureIterator.hasNext() ) { SimpleFeature f = featureIterator.next(); int id = ((Number) f.getAttribute("id")).intValue(); Geometry geometry = (Geometry) f.getDefaultGeometry(); Coordinate coordinate = geometry.getCoordinate(); if (id == 0) { assertEquals(coordinate.x, 0.0); assertEquals(coordinate.y, 0.0); } if (id == 1) { assertEquals(coordinate.x, 1.0); assertEquals(coordinate.y, 1.0); } if (id == 2) { assertEquals(coordinate.x, 2.0); assertEquals(coordinate.y, 2.0); } } if (tmpShape.exists()) { tmpShape.deleteOnExit(); } }