public SimpleFeature next() throws IOException, IllegalArgumentException, NoSuchElementException {
    if (results == null) return null;

    SpatialDatabaseRecord record = results.next();
    if (record == null) return null;

    builder.reset();
    builder.set(FEATURE_PROP_GEOM, record.getGeometry());

    if (extraPropertyNames != null) {
      for (int i = 0; i < extraPropertyNames.length; i++) {
        if (record.hasProperty(extraPropertyNames[i])) {
          builder.set(extraPropertyNames[i], record.getProperty(extraPropertyNames[i]));
        }
      }
    }

    return builder.buildFeature(record.getId());
  }
Beispiel #2
0
 /**
  * Method to get the nearest parking by longitude and latitude.
  *
  * @param lon the longitude
  * @param lat the latitude
  * @param distance
  * @param status if 0 we search a station with free places and if null whatever !
  * @return
  */
 public POI getNearest(Double lon, Double lat, Double distance, Integer status)
     throws MobilITException {
   Coordinate coord = new Coordinate(lat, lon);
   EditableLayer layer = spatial.getOrCreateEditableLayer(Constant.PARKING_LAYER);
   // @formatter:off
   List<GeoPipeFlow> results =
       GeoPipeline.startNearestNeighborSearch(layer, coord, distance).sort("Distance").toList();
   // @formatter:on
   int i = 0;
   Boolean find = false;
   POI nearest = null;
   while (find == false && i < results.size()) {
     SpatialDatabaseRecord dbRecord = results.get(i).getRecord();
     Node node = dbRecord.getGeomNode();
     String geocode = (String) node.getProperty("geocode", null);
     String id = (String) node.getProperty("id", null);
     String name = (String) node.getProperty("name", null);
     Double lng = (Double) node.getProperty("lon", null);
     Double lati = (Double) node.getProperty("lat", null);
     if (status != null) {
       AbstractParking service = this.getGeoService(geocode);
       HashMap<String, Integer> places = (HashMap<String, Integer>) service.getParking(id);
       if (places.isEmpty()) {
         // here there is no information
         nearest = new POI(id, name, lng, lati, geocode);
         find = true;
       } else {
         Integer free = places.get(Constant.PARKING_FREE);
         if (free != null && free > 0) {
           nearest = new POI(id, name, lng, lati, geocode);
           find = true;
         }
       }
     } else {
       nearest = new POI(id, name, lng, lati, geocode);
       find = true;
     }
     i++;
   }
   // TODO: throw an exception if there is no station ?
   return nearest;
 }