From: Ahmed A. <ahm...@gm...> - 2016-02-08 09:38:23
|
Dear All, I have implemented the following code, but still I am struggling in getting direct access to X and Y coordinates, to do some computations on them. *the syntax:* *System.out.println(feature.getDefaultGeometryProperty().getValue());* shows coordinates' pairs, but I could not use them in my computations. Any help will be appreciated. *Java code* File file = new File("LUX_adm2.shp"); FileDataStore store = FileDataStoreFinder.getDataStore(file); SimpleFeatureSource featureSource = store.getFeatureSource(); // Create a map content and add our shapefile to it MapContent map = new MapContent(); map.setTitle("Display Shapefile"); Style style; style = SLD.createSimpleStyle(featureSource.getSchema()); Layer layer; layer = new FeatureLayer(featureSource, style); map.addLayer(layer); // Now display the map JMapFrame.showMap(map); Filter filter = Filter.INCLUDE; FeatureCollection collection = featureSource.getFeatures(filter); try (FeatureIterator<SimpleFeature> features = collection.features()) { while (features.hasNext()) { SimpleFeature feature = features.next(); System.out.println(feature.getID() + ": "); //System.out.print(": "); System.out.println(feature.getDefaultGeometryProperty().getValue()); } } Best wishes, Ahmed |