Search in sources :

Example 1 with CoordinateObject

use of org.hisp.dhis.common.coordinate.CoordinateObject in project dhis2-core by dhis2.

the class GeoFeatureService method getCoordinates.

/**
 * Get the {@link GeoFeature} coordinate from {@link DimensionalItemObject}
 *
 * @param feature the {@link GeoFeature}
 * @param unit the {@link DimensionalItemObject} contains the coordinate
 *        values.
 * @return the given {@link GeoFeature} with updated coordinate value and
 *         coordinate type.
 */
private void getCoordinates(GeoFeature feature, DimensionalItemObject unit) {
    if (!CoordinateObject.class.isAssignableFrom(unit.getClass())) {
        return;
    }
    CoordinateObject coordinateObject = (CoordinateObject) unit;
    Integer ty = coordinateObject.getFeatureType() != null ? FEATURE_TYPE_MAP.get(coordinateObject.getFeatureType()) : null;
    feature.setCo(coordinateObject.getCoordinates());
    feature.setTy(ObjectUtils.firstNonNull(ty, 0));
}
Also used : CoordinateObject(org.hisp.dhis.common.coordinate.CoordinateObject)

Example 2 with CoordinateObject

use of org.hisp.dhis.common.coordinate.CoordinateObject in project dhis2-core by dhis2.

the class GeoFeatureService method getGeoFeatures.

/**
 * Returns a list of {@link GeoFeature}.
 *
 * @param params the {@link DataQueryParams}.
 * @param dimensionalItemObjects the list of {@link DimensionalItemObject}.
 * @param includeGroupSets whether to include group sets.
 * @param useOrgUnitGroup whether to use org unit group when retrieving
 *        features.
 * @param geoJsonAttribute OrganisationUnit attribute used for retrieving
 *        {@link GeoJsonObject}
 * @return a list of {@link GeoFeature}.
 */
private List<GeoFeature> getGeoFeatures(DataQueryParams params, List<DimensionalItemObject> dimensionalItemObjects, boolean includeGroupSets, boolean useOrgUnitGroup, Attribute geoJsonAttribute) {
    List<GeoFeature> features = new ArrayList<>();
    List<OrganisationUnitGroupSet> groupSets = includeGroupSets ? organisationUnitGroupService.getAllOrganisationUnitGroupSets() : new ArrayList<>();
    Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnitsWithFallback();
    for (DimensionalItemObject unit : dimensionalItemObjects) {
        GeoFeature feature = new GeoFeature();
        CoordinateObject coordinateObject = (CoordinateObject) unit;
        feature.setId(unit.getUid());
        feature.setCode(unit.getCode());
        feature.setHcd(coordinateObject.hasDescendantsWithCoordinates());
        if (!useOrgUnitGroup) {
            OrganisationUnit castUnit = (OrganisationUnit) unit;
            feature.setHcu(castUnit.hasCoordinatesUp());
            feature.setLe(castUnit.getLevel());
            feature.setPg(castUnit.getParentGraph(roots));
            feature.setPi(castUnit.getParent() != null ? castUnit.getParent().getUid() : null);
            feature.setPn(castUnit.getParent() != null ? castUnit.getParent().getDisplayName() : null);
            if (includeGroupSets) {
                for (OrganisationUnitGroupSet groupSet : groupSets) {
                    OrganisationUnitGroup group = castUnit.getGroupInGroupSet(groupSet);
                    if (group != null) {
                        feature.getDimensions().put(groupSet.getUid(), group.getUid());
                    }
                }
            }
        }
        getCoordinates(feature, unit, geoJsonAttribute);
        feature.setNa(unit.getDisplayProperty(params.getDisplayProperty()));
        features.add(feature);
    }
    features.sort(Comparator.comparing(GeoFeature::getTy));
    return features;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) CoordinateObject(org.hisp.dhis.common.coordinate.CoordinateObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ArrayList(java.util.ArrayList) GeoFeature(org.hisp.dhis.webapi.webdomain.GeoFeature) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Aggregations

CoordinateObject (org.hisp.dhis.common.coordinate.CoordinateObject)2 ArrayList (java.util.ArrayList)1 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)1 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)1 GeoFeature (org.hisp.dhis.webapi.webdomain.GeoFeature)1