private LinkedHashMap < Integer , Coordinate > getCoordinate ( int nStaz , SimpleFeatureCollection collection , String idField ) throws Exception { LinkedHashMap < Integer , Coordinate > id2CoordinatesMap = new LinkedHashMap < Integer , Coordinate > ( ) ; FeatureIterator < SimpleFeature > iterator = collection . features ( ) ; Coordinate coordinate = null ; try { while ( iterator . hasNext ( ) ) { SimpleFeature feature = iterator . next ( ) ; int name = ( ( Number ) feature . getAttribute ( idField ) ) . intValue ( ) ; coordinate = ( ( Geometry ) feature . getDefaultGeometry ( ) ) . getCentroid ( ) . getCoordinate ( ) ; double z = 0 ; if ( fPointZ != null ) { try { z = ( ( Number ) feature . getAttribute ( fPointZ ) ) . doubleValue ( ) ; } catch ( NullPointerException e ) { pm . errorMessage ( msg . message ( "kriging.noPointZ" ) ) ; throw new Exception ( msg . message ( "kriging.noPointZ" ) ) ; } } coordinate . z = z ; id2CoordinatesMap . put ( name , coordinate ) ; } } finally { iterator . close ( ) ; } return id2CoordinatesMap ; }
Extract the coordinate of a FeatureCollection in a HashMap with an ID as a key .