use of de.symeda.sormas.api.geo.GeoLatLon in project SORMAS-Project by hzi-braunschweig.
the class LocationEditForm method triggerGeocoding.
private void triggerGeocoding() {
String street = getConvertedValue(LocationDto.STREET);
String houseNumber = getConvertedValue(LocationDto.HOUSE_NUMBER);
String postalCode = getConvertedValue(LocationDto.POSTAL_CODE);
String city = getConvertedValue(LocationDto.CITY);
GeoLatLon latLon = FacadeProvider.getGeocodingFacade().getLatLon(street, houseNumber, postalCode, city);
if (latLon != null) {
setConvertedValue(LocationDto.LATITUDE, latLon.getLat());
setConvertedValue(LocationDto.LONGITUDE, latLon.getLon());
}
}
use of de.symeda.sormas.api.geo.GeoLatLon in project SORMAS-Project by hzi-braunschweig.
the class LocationEditForm method updateLeafletMapContent.
private void updateLeafletMapContent() {
if (leafletMapPopup == null) {
return;
}
if (areFieldsValid(LocationDto.LATITUDE, LocationDto.LONGITUDE)) {
Double lat = getConvertedValue(LocationDto.LATITUDE);
Double lon = getConvertedValue(LocationDto.LONGITUDE);
GeoLatLon coordinates;
if (ObjectUtils.allNotNull(lat, lon)) {
coordinates = new GeoLatLon(lat, lon);
} else {
coordinates = null;
}
leafletMapPopup.setEnabled(coordinates != null);
leafletMapPopup.setCoordinates(coordinates);
} else {
leafletMapPopup.setEnabled(false);
}
}
use of de.symeda.sormas.api.geo.GeoLatLon in project SORMAS-Project by hzi-braunschweig.
the class GeoShapeHelper method polygonToGeoLatLons.
/**
* Convert a polygon to an 2D array of Lat/Lon coordinates.
*
* @param multiPolygon
* The polygon which Lat/Lon coordinates get extracted.
* @return
* 2D array of Lat/Lon coordinates of the polygon.
*/
private static GeoLatLon[][] polygonToGeoLatLons(MultiPolygon multiPolygon) {
GeoLatLon[][] shape = new GeoLatLon[multiPolygon.getNumGeometries()][];
for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
Polygon polygon = (Polygon) multiPolygon.getGeometryN(i);
shape[i] = Arrays.stream(polygon.getExteriorRing().getCoordinates()).map(c -> new GeoLatLon(c.y, c.x)).toArray(GeoLatLon[]::new);
}
return shape;
}
use of de.symeda.sormas.api.geo.GeoLatLon in project SORMAS-Project by hzi-braunschweig.
the class GeoShapeProviderEjb method buildCountryShape.
private void buildCountryShape() {
GeometryFactory factory = JTSFactoryFinder.getGeometryFactory();
// combine all regions that touch into new polygons
List<Polygon> polygons = new ArrayList<>();
for (GeoLatLon[][] regionShape : regionShapes.values()) {
for (GeoLatLon[] regionPolygon : regionShape) {
try {
// convert region to polygon
Polygon polygon = factory.createPolygon(Arrays.stream(regionPolygon).map(regionPoint -> new Coordinate(regionPoint.getLon(), regionPoint.getLat())).toArray(Coordinate[]::new));
boolean added = false;
for (int i = 0; i < polygons.size(); i++) {
if (polygons.get(i).touches(polygon)) {
// touch?
// union
polygons.set(i, (Polygon) polygons.get(i).union(polygon));
added = true;
break;
}
}
if (!added) {
polygons.add(polygon);
}
} catch (TopologyException e) {
logger.error(e.toString());
}
}
}
// go through the polygons again
for (int i = 0; i < polygons.size(); i++) {
for (int j = 0; j < polygons.size(); j++) {
if (i == j)
continue;
try {
if (polygons.get(i).touches(polygons.get(j))) {
// touch
// union
polygons.set(i, (Polygon) polygons.get(i).union(polygons.get(j)));
polygons.remove(j);
if (i >= j) {
i--;
break;
} else {
j--;
}
}
} catch (TopologyException e) {
logger.error(e.toString());
}
}
}
countryShape = polygons.stream().map(polygon -> Arrays.stream(polygon.getCoordinates()).map(coordinate -> new GeoLatLon(coordinate.y, coordinate.x)).toArray(GeoLatLon[]::new)).toArray(GeoLatLon[][]::new);
}
use of de.symeda.sormas.api.geo.GeoLatLon in project SORMAS-Project by hzi-braunschweig.
the class GeoShapeProviderEjb method updateCenterOfAllRegions.
protected void updateCenterOfAllRegions() {
if (regionMultiPolygons.isEmpty()) {
regionsCenter = null;
} else {
double lat = 0, lon = 0;
int count = 0;
for (MultiPolygon polygon : regionMultiPolygons.values()) {
lon += polygon.getCentroid().getX();
lat += polygon.getCentroid().getY();
count++;
}
if (count > 0) {
regionsCenter = new GeoLatLon(lat / count, lon / count);
} else {
regionsCenter = null;
}
}
}
Aggregations