public String getNeighborhoodId(Coordinates c){ GeometryFactory geometryFactory = new GeometryFactory(); String utm = converter.latLon2UTM(c.getLat(), c.getLng()); Coordinate coords = new Coordinate(Double.valueOf(utm.split(" ")[2]),Double.valueOf(utm.split(" ")[3])); Geometry point = geometryFactory.createPoint(coords); for(Feature f : neighborhoods){ MultiPolygon m = (MultiPolygon) f.getProperty("geometry").getValue(); if(m.contains(point)){ return f.getProperty("neighborhoodId").getValue().toString(); } } return ""; }
private Zone getSmallestZoneContainingPoint(List<Zone> zones, Point point) { if (zones.size() == 1) {// almost 100% cases return zones.get(0); } double minArea = Double.MAX_VALUE; Zone smallestZone = null; for (Zone z : zones) { if (z.getMultiPolygon().contains(point)) { double area = z.getMultiPolygon().getArea(); if (area < minArea) { minArea = area; smallestZone = z; } } } return smallestZone; }
"{\"type\":\"MultiPolygon\", \"coordinates\":" + multiPolygonJson + "}" ) ); contains = multiPolygon.contains( point );
public static Map<String, Object> getFeatureProperties(Point point, SimpleFeatureCollection featureCollection) { Map<String, Object> map = null; SimpleFeatureIterator features = featureCollection.features(); try { while (features.hasNext()) { SimpleFeature feature = features.next(); Object defaultGeometry = feature.getDefaultGeometry(); if (defaultGeometry instanceof MultiPolygon) { MultiPolygon polygon = (MultiPolygon) defaultGeometry; if (polygon.contains(point)) { map = new TreeMap<String, Object>(); SimpleFeatureType featureType = feature.getFeatureType(); List<AttributeDescriptor> attributeDescriptors = featureType.getAttributeDescriptors(); for (AttributeDescriptor attributeDescriptor : attributeDescriptors) { String localName = attributeDescriptor.getLocalName(); Object value = feature.getAttribute(localName); if (value != null) { map.put(attributeDescriptor.getLocalName(), value); } } break; } } } } finally { features.close(); } return map; }