public JTSFeature parseFeature ( JSONObject feature ) throws JSONException { JTSFeature feat = new JTSFeature ( null ) ; JSONObject geometry = ( JSONObject ) feature . get ( "geometry" ) ; String geomType = geometry . get ( "type" ) . toString ( ) ; if ( geomType . compareTo ( "Point" ) == 0 ) { JSONArray coords = geometry . getJSONArray ( "coordinates" ) ; double x = coords . getDouble ( 0 ) ; double y = coords . getDouble ( 1 ) ; GeometryFactory factory = new GeometryFactory ( ) ; Coordinate c = new Coordinate ( ) ; c . x = x ; c . y = y ; Point p = factory . createPoint ( c ) ; feat . setGeometry ( new JTSGeometry ( p ) ) ; } // TODO process other geometry types JSONObject props = feature . getJSONObject ( "properties" ) ; Iterator it = props . keys ( ) ; String key ; String val ; feat . setText ( "" ) ; while ( it . hasNext ( ) ) { key = it . next ( ) . toString ( ) ; val = props . getString ( key ) ; feat . addField ( key , val , 0 ) ; if ( val . indexOf ( "http" ) == - 1 ) { feat . setText ( feat . getText ( ) + " " + val ) ; } } return feat ; }
Parses a single feature with a Point