Search in sources :

Example 1 with CollectSurveyContext

use of org.openforis.collect.model.CollectSurveyContext 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 2 with CollectSurveyContext

use of org.openforis.collect.model.CollectSurveyContext in project collect by openforis.

the class SamplingPointDataGeneratorTest method createTestSurvey.

private CollectSurvey createTestSurvey() {
    CollectSurvey survey = (CollectSurvey) new CollectSurveyContext().createSurvey();
    survey.setId(1);
    return survey;
}
Also used : CollectSurveyContext(org.openforis.collect.model.CollectSurveyContext) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 3 with CollectSurveyContext

use of org.openforis.collect.model.CollectSurveyContext in project collect by openforis.

the class UIOptionsTest method initSurvey.

protected void initSurvey() {
    SurveyContext ctx = new CollectSurveyContext(new ExpressionFactory(), new CollectValidator());
    survey = (CollectSurvey) ctx.createSurvey();
    schema = survey.getSchema();
    populateSchema();
    initUIOptions();
}
Also used : ExpressionFactory(org.openforis.idm.model.expression.ExpressionFactory) CollectSurveyContext(org.openforis.collect.model.CollectSurveyContext) CollectValidator(org.openforis.collect.model.validation.CollectValidator) CollectSurveyContext(org.openforis.collect.model.CollectSurveyContext) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 4 with CollectSurveyContext

use of org.openforis.collect.model.CollectSurveyContext 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)

Example 5 with CollectSurveyContext

use of org.openforis.collect.model.CollectSurveyContext in project collect by openforis.

the class CollectRelationalTest method loadSurvey.

@BeforeClass
public static void loadSurvey() throws IdmlParseException, FileNotFoundException {
    InputStream is = ClassLoader.getSystemResourceAsStream("test.idm.xml");
    // InputStream is = new FileInputStream("/home/gino/workspace/of/idm/idm-test/src/main/resources/test.idm.xml");
    // InputStream is = new FileInputStream("D:/data/workspace/idm/idm-test/src/main/resources/test.idm.xml");
    // InputStream is = new FileInputStream("/home/gino/workspace/faofin/tz/naforma-idm/tanzania-naforma.idm.xml");
    CollectSurveyContext ctx = new CollectSurveyContext(new ExpressionFactory(), null);
    // DefaultSurveyContext ctx = new DefaultSurveyContext();
    CollectSurveyIdmlBinder binder = new CollectSurveyIdmlBinder(ctx);
    survey = (CollectSurvey) binder.unmarshal(is);
}
Also used : ExpressionFactory(org.openforis.idm.model.expression.ExpressionFactory) InputStream(java.io.InputStream) CollectSurveyContext(org.openforis.collect.model.CollectSurveyContext) CollectSurveyIdmlBinder(org.openforis.collect.persistence.xml.CollectSurveyIdmlBinder) BeforeClass(org.junit.BeforeClass)

Aggregations

CollectSurveyContext (org.openforis.collect.model.CollectSurveyContext)5 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 CoordinateOperations (org.openforis.idm.geospatial.CoordinateOperations)2 Coordinate (org.openforis.idm.model.Coordinate)2 ExpressionFactory (org.openforis.idm.model.expression.ExpressionFactory)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 LngLatAlt (org.geojson.LngLatAlt)1 BeforeClass (org.junit.BeforeClass)1 LngLat (org.openforis.collect.model.LngLat)1 SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)1 SamplingDesignSummaries (org.openforis.collect.model.SamplingDesignSummaries)1 CollectValidator (org.openforis.collect.model.validation.CollectValidator)1 CollectSurveyIdmlBinder (org.openforis.collect.persistence.xml.CollectSurveyIdmlBinder)1 SurveyContext (org.openforis.idm.metamodel.SurveyContext)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1