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);
}
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;
}
}
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());
}
}
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;
}
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);
}
}
Aggregations