Search in sources :

Example 21 with Coordinate

use of org.openforis.idm.model.Coordinate in project collect by openforis.

the class SamplingPointDataGenerator method calculateAoiCenter.

public Coordinate calculateAoiCenter() {
    List<Coordinate> aoiBoundary = configuration.getAoiBoundary();
    double[] latitudes = new double[aoiBoundary.size()];
    double[] longitudes = new double[aoiBoundary.size()];
    for (int i = 0; i < aoiBoundary.size(); i++) {
        Coordinate coord = aoiBoundary.get(i);
        latitudes[i] = coord.getY();
        longitudes[i] = coord.getX();
    }
    double minBoundaryLatitude = NumberUtils.min(latitudes);
    double maxBoundaryLatitude = NumberUtils.max(latitudes);
    double minBoundaryLongitude = NumberUtils.min(longitudes);
    double maxBoundaryLongitude = NumberUtils.max(longitudes);
    return new Coordinate(minBoundaryLongitude + (maxBoundaryLongitude - minBoundaryLongitude) / 2, minBoundaryLatitude + (maxBoundaryLatitude - minBoundaryLatitude) / 2, LAT_LON_SRS_ID);
}
Also used : Coordinate(org.openforis.idm.model.Coordinate)

Example 22 with Coordinate

use of org.openforis.idm.model.Coordinate in project collect by openforis.

the class SamplingPointDataGenerator method generateItems.

private List<SamplingDesignItem> generateItems(int levelIdx, List<String> previousLevelKeys, Coordinate latLonAoiCenter) {
    if (samplingPointsByLevel != null && samplingPointsByLevel.size() > levelIdx && CollectionUtils.isNotEmpty(samplingPointsByLevel.get(levelIdx))) {
        List<SamplingDesignItem> items = new ArrayList<SamplingDesignItem>();
        List<SamplingDesignItem> itemsInLevel = samplingPointsByLevel.get(levelIdx);
        items.addAll(itemsInLevel);
        for (SamplingDesignItem item : itemsInLevel) {
            item.setSurveyId(survey.getId());
            if (levelIdx < configuration.getLevelsSettings().size() - 1) {
                List<String> itemKeys = item.getLevelCodes();
                items.addAll(generateItems(levelIdx + 1, itemKeys, item.getCoordinate()));
            }
        }
        return items;
    } else {
        List<SamplingDesignItem> items = new ArrayList<SamplingDesignItem>();
        List<Coordinate> locations = generateLocations(latLonAoiCenter, levelIdx);
        for (int locationIdx = 0; locationIdx < locations.size(); locationIdx++) {
            Coordinate webMercatorCenter = locations.get(locationIdx);
            Coordinate latLonCenter = reprojectFromWebMercatorToLatLon(webMercatorCenter);
            SamplingDesignItem item = new SamplingDesignItem();
            item.setSrsId(LAT_LON_SRS_ID);
            item.setSurveyId(survey.getId());
            List<String> itemKeys = new ArrayList<String>(previousLevelKeys);
            itemKeys.add(String.valueOf(locationIdx + 1));
            item.setLevelCodes(itemKeys);
            item.setX(latLonCenter.getX());
            item.setY(latLonCenter.getY());
            items.add(item);
            if (levelIdx < configuration.getLevelsSettings().size() - 1) {
                items.addAll(generateItems(levelIdx + 1, itemKeys, latLonCenter));
            }
        }
        return items;
    }
}
Also used : Coordinate(org.openforis.idm.model.Coordinate) ArrayList(java.util.ArrayList) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 23 with Coordinate

use of org.openforis.idm.model.Coordinate in project collect by openforis.

the class SamplingPointDataGenerator method generateLocations.

private List<Coordinate> generateLocations(Coordinate latLonCenter, int levelIdx) {
    SamplingPointLevelGenerationSettings pointsConfiguration = configuration.getLevelsSettings().get(levelIdx);
    Coordinate webMercatorAoiCenter = reprojectFromLatLonToWebMercator(latLonCenter);
    switch(pointsConfiguration.getShape()) {
        case CIRCLE:
            double areaWidth = calculateAoiWidth(levelIdx);
            return generateLocationsInCircle(webMercatorAoiCenter, areaWidth / 2, pointsConfiguration);
        case SQUARE:
            SamplingPointLevelGenerationSettings nextLevelPointsConfiguration = levelIdx == configuration.getLevelsSettings().size() - 1 ? null : configuration.getLevelsSettings().get(levelIdx + 1);
            Double pointWidth = nextLevelPointsConfiguration == null ? DEFAULT_POINT_SIZE : nextLevelPointsConfiguration.getPointWidth();
            List<Coordinate> boundary = levelIdx == 0 ? configuration.getAoiBoundary() : generateSquareBoundary(latLonCenter, pointWidth);
            return generateLocationsInSquare(webMercatorAoiCenter, boundary, pointsConfiguration);
        default:
            throw new IllegalArgumentException("Shape type not supported: " + pointsConfiguration.getShape());
    }
}
Also used : Coordinate(org.openforis.idm.model.Coordinate) SamplingPointLevelGenerationSettings(org.openforis.collect.metamodel.samplingdesign.SamplingPointLevelGenerationSettings)

Example 24 with Coordinate

use of org.openforis.idm.model.Coordinate in project collect by openforis.

the class SamplingPointDataGenerator method reprojectToWebMercator.

private List<Coordinate> reprojectToWebMercator(List<Coordinate> aoiBoundary) {
    List<Coordinate> reprojectedAoiBoundary = new ArrayList<Coordinate>(aoiBoundary.size());
    for (Coordinate coord : aoiBoundary) {
        Coordinate reprojectedCoord = reprojectFromLatLonToWebMercator(coord);
        reprojectedAoiBoundary.add(reprojectedCoord);
    }
    return reprojectedAoiBoundary;
}
Also used : Coordinate(org.openforis.idm.model.Coordinate) ArrayList(java.util.ArrayList)

Example 25 with Coordinate

use of org.openforis.idm.model.Coordinate in project collect by openforis.

the class GeoToolsCoordinateOperations method convert.

private Coordinate convert(double x, double y, String fromSrsId, String toSrsId) {
    try {
        DirectPosition src = new DirectPosition2D(x, y);
        MathTransform transform = getOrCreateTransform(fromSrsId, toSrsId);
        if (transform == null) {
            if (LOG.isErrorEnabled()) {
                LOG.error("Unknown CRS: " + toSrsId);
            }
            return new Coordinate(0d, 0d, toSrsId);
        } else {
            DirectPosition directPosition = transform.transform(src, null);
            double[] coord = directPosition.getCoordinate();
            return new Coordinate(coord[0], coord[1], toSrsId);
        }
    } catch (Throwable t) {
        if (LOG.isErrorEnabled()) {
            LOG.error("Error converting lat lon to web marcator: lat=" + y + " lon=" + x, t);
        }
        return new Coordinate(0d, 0d, toSrsId);
    }
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) MathTransform(org.opengis.referencing.operation.MathTransform) Coordinate(org.openforis.idm.model.Coordinate) DirectPosition2D(org.geotools.geometry.DirectPosition2D)

Aggregations

Coordinate (org.openforis.idm.model.Coordinate)46 Code (org.openforis.idm.model.Code)14 Test (org.junit.Test)8 Date (org.openforis.idm.model.Date)8 Time (org.openforis.idm.model.Time)8 ArrayList (java.util.ArrayList)7 SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)7 CoordinateAttribute (org.openforis.idm.model.CoordinateAttribute)7 Entity (org.openforis.idm.model.Entity)7 CollectRecord (org.openforis.collect.model.CollectRecord)5 GregorianCalendar (java.util.GregorianCalendar)4 SamplingPointLevelGenerationSettings (org.openforis.collect.metamodel.samplingdesign.SamplingPointLevelGenerationSettings)4 CollectSurvey (org.openforis.collect.model.CollectSurvey)4 CoordinateOperations (org.openforis.idm.geospatial.CoordinateOperations)4 RealAttribute (org.openforis.idm.model.RealAttribute)4 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)3 ValidationResults (org.openforis.idm.metamodel.validation.ValidationResults)3 NumberAttribute (org.openforis.idm.model.NumberAttribute)3 RecordBuilder (org.openforis.idm.testfixture.RecordBuilder)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2