Search in sources :

Example 1 with CoordinateOperations

use of org.openforis.idm.geospatial.CoordinateOperations in project collect by openforis.

the class SRSFormValidator method validateWKT.

private boolean validateWKT(ValidationContext ctx) {
    String wkt = (String) getValue(ctx, WKT_FIELD);
    CollectSurvey survey = getSurvey(ctx);
    SurveyContext context = survey.getContext();
    CoordinateOperations coordinateOperations = context.getCoordinateOperations();
    try {
        coordinateOperations.validateWKT(wkt);
        return true;
    } catch (Exception e) {
        String message = Labels.getLabel("survey.srs.validation.error.invalid_wkt", new String[] { e.getMessage() });
        addInvalidMessage(ctx, WKT_FIELD, message);
        return false;
    }
}
Also used : CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations) CollectSurvey(org.openforis.collect.model.CollectSurvey) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 2 with CoordinateOperations

use of org.openforis.idm.geospatial.CoordinateOperations in project collect by openforis.

the class SamplingPointsController method loadSamplingPointDataFeatures.

private FeatureCollection loadSamplingPointDataFeatures(CollectSurvey survey) {
    FeatureCollection featureCollection = new FeatureCollection();
    Feature feature = new Feature();
    feature.setProperty("letter", "o");
    feature.setProperty("color", "blue");
    feature.setProperty("rank", "15");
    MultiPoint multiPoint = new MultiPoint();
    CoordinateOperations coordinateOperations = getCoordinateOperations(survey);
    List<SamplingDesignItem> samplingDesignItems = loadSamplingDesignItems(survey);
    for (SamplingDesignItem item : samplingDesignItems) {
        Coordinate coordinate = new Coordinate(item.getX(), item.getY(), item.getSrsId());
        multiPoint.add(createLngLatAlt(coordinateOperations, coordinate));
    }
    feature.setGeometry(multiPoint);
    featureCollection.add(feature);
    return featureCollection;
}
Also used : MultiPoint(org.geojson.MultiPoint) CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations) FeatureCollection(org.geojson.FeatureCollection) Coordinate(org.openforis.idm.model.Coordinate) Feature(org.geojson.Feature) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 3 with CoordinateOperations

use of org.openforis.idm.geospatial.CoordinateOperations in project collect by openforis.

the class SamplingPointsController method loadSamplingPointBounds.

@RequestMapping(value = "survey/{surveyId}/sampling_point_bounds.json", method = GET)
@ResponseBody
public Bounds loadSamplingPointBounds(@PathVariable int surveyId) {
    CollectSurvey survey = surveyManager.loadSurvey(surveyId);
    CollectSurveyContext surveyContext = survey.getContext();
    CoordinateOperations coordinateOperations = surveyContext.getCoordinateOperations();
    SamplingDesignSummaries samplingDesignSummaries = samplingDesignManager.loadBySurvey(survey.getId());
    List<SamplingDesignItem> samplingDesignItems = samplingDesignSummaries.getRecords();
    Bounds bounds = new Bounds();
    for (SamplingDesignItem item : samplingDesignItems) {
        Coordinate coordinate = new Coordinate(item.getX(), item.getY(), item.getSrsId());
        LngLatAlt lngLatAlt = createLngLatAlt(coordinateOperations, coordinate);
        if (lngLatAlt != null) {
            if (bounds.topLeft == null) {
                bounds.topLeft = bounds.topRight = bounds.bottomLeft = bounds.bottomRight = lngLatAlt;
            } else {
                if (lngLatAlt.getLatitude() < bounds.topLeft.getLatitude() && lngLatAlt.getLongitude() < bounds.topLeft.getLongitude()) {
                    bounds.topLeft = lngLatAlt;
                } else if (lngLatAlt.getLatitude() < bounds.topRight.getLatitude() && lngLatAlt.getLongitude() > bounds.topRight.getLongitude()) {
                    bounds.topRight = lngLatAlt;
                } else if (lngLatAlt.getLatitude() > bounds.bottomRight.getLatitude() && lngLatAlt.getLongitude() > bounds.bottomRight.getLongitude()) {
                    bounds.bottomRight = lngLatAlt;
                } else if (lngLatAlt.getLatitude() > bounds.bottomLeft.getLatitude() && lngLatAlt.getLongitude() > bounds.bottomLeft.getLongitude()) {
                    bounds.bottomLeft = lngLatAlt;
                }
            }
        }
    }
    return bounds;
}
Also used : CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations) Coordinate(org.openforis.idm.model.Coordinate) CollectSurveyContext(org.openforis.collect.model.CollectSurveyContext) SamplingDesignSummaries(org.openforis.collect.model.SamplingDesignSummaries) CollectSurvey(org.openforis.collect.model.CollectSurvey) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) LngLatAlt(org.geojson.LngLatAlt) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with CoordinateOperations

use of org.openforis.idm.geospatial.CoordinateOperations in project collect by openforis.

the class Survey method initCoordinateOperations.

private void initCoordinateOperations() {
    CoordinateOperations coordinateOperations = getContext().getCoordinateOperations();
    coordinateOperations.registerSRS(getSpatialReferenceSystems());
}
Also used : CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations)

Example 5 with CoordinateOperations

use of org.openforis.idm.geospatial.CoordinateOperations in project collect by openforis.

the class SamplingPointDataKmlGenerator method createLngLat.

private LngLat createLngLat(Coordinate coord) {
    try {
        CollectSurveyContext surveyContext = survey.getContext();
        CoordinateOperations coordOpts = surveyContext.getCoordinateOperations();
        Coordinate wgs84Coord = coordOpts.convertToWgs84(coord);
        return new LngLat(wgs84Coord.getX(), wgs84Coord.getY());
    } catch (Exception e) {
        return null;
    }
}
Also used : CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations) LngLat(org.openforis.collect.model.LngLat) Coordinate(org.openforis.idm.model.Coordinate) CollectSurveyContext(org.openforis.collect.model.CollectSurveyContext) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

CoordinateOperations (org.openforis.idm.geospatial.CoordinateOperations)9 Coordinate (org.openforis.idm.model.Coordinate)4 CollectSurvey (org.openforis.collect.model.CollectSurvey)3 CollectSurveyContext (org.openforis.collect.model.CollectSurveyContext)2 SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 FileNotFoundException (java.io.FileNotFoundException)1 Feature (org.geojson.Feature)1 FeatureCollection (org.geojson.FeatureCollection)1 LngLatAlt (org.geojson.LngLatAlt)1 MultiPoint (org.geojson.MultiPoint)1 LngLat (org.openforis.collect.model.LngLat)1 RecordCoordinatesKmlGeneratorJob (org.openforis.collect.model.RecordCoordinatesKmlGeneratorJob)1 RecordFilter (org.openforis.collect.model.RecordFilter)1 SamplingDesignSummaries (org.openforis.collect.model.SamplingDesignSummaries)1 CoordinateOperationException (org.openforis.idm.geospatial.CoordinateOperationException)1 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)1 Survey (org.openforis.idm.metamodel.Survey)1 SurveyContext (org.openforis.idm.metamodel.SurveyContext)1 ExpressionEvaluator (org.openforis.idm.model.expression.ExpressionEvaluator)1