Search in sources :

Example 1 with GeoLatLon

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());
    }
}
Also used : GeoLatLon(de.symeda.sormas.api.geo.GeoLatLon)

Example 2 with GeoLatLon

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);
    }
}
Also used : GeoLatLon(de.symeda.sormas.api.geo.GeoLatLon)

Example 3 with GeoLatLon

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;
}
Also used : Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) GeoLatLon(de.symeda.sormas.api.geo.GeoLatLon)

Example 4 with GeoLatLon

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);
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) ArrayList(java.util.ArrayList) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Point(org.locationtech.jts.geom.Point) TopologyException(org.locationtech.jts.geom.TopologyException) GeoLatLon(de.symeda.sormas.api.geo.GeoLatLon)

Example 5 with GeoLatLon

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;
        }
    }
}
Also used : MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Point(org.locationtech.jts.geom.Point) GeoLatLon(de.symeda.sormas.api.geo.GeoLatLon)

Aggregations

GeoLatLon (de.symeda.sormas.api.geo.GeoLatLon)10 ArrayList (java.util.ArrayList)4 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)3 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)2 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)2 LeafletPolygon (de.symeda.sormas.ui.map.LeafletPolygon)2 BigDecimal (java.math.BigDecimal)2 Point (org.locationtech.jts.geom.Point)2 Polygon (org.locationtech.jts.geom.Polygon)2 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)1 AbstractOrderedLayout (com.vaadin.ui.AbstractOrderedLayout)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Label (com.vaadin.ui.Label)1 ReferenceDto (de.symeda.sormas.api.ReferenceDto)1 DashboardEventDto (de.symeda.sormas.api.dashboard.DashboardEventDto)1 CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)1 DistrictDto (de.symeda.sormas.api.infrastructure.district.DistrictDto)1 FacilityReferenceDto (de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto)1 StatisticsCaseCountDto (de.symeda.sormas.api.statistics.StatisticsCaseCountDto)1 Pair (de.symeda.sormas.api.utils.DataHelper.Pair)1