Search in sources :

Example 26 with Coordinate

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

the class SamplingPointDataKmlGenerator method generate.

public void generate() {
    Kml kml = KmlFactory.createKml();
    Document doc = kml.createAndSetDocument();
    List<SamplingDesignItem> samplingDesignItems = loadSamplingDesignItems();
    for (SamplingDesignItem item : samplingDesignItems) {
        Coordinate coordinate = new Coordinate(item.getX(), item.getY(), item.getSrsId());
        LngLat lngLatAlt = createLngLat(coordinate);
        doc.createAndAddPlacemark().withName(Strings.joinNotBlank(item.getLevelCodes(), "|")).withOpen(true).createAndSetPoint().addToCoordinates(lngLatAlt.getLongitude(), lngLatAlt.getLatitude());
    }
    this.kml = kml;
}
Also used : LngLat(org.openforis.collect.model.LngLat) Coordinate(org.openforis.idm.model.Coordinate) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) Document(de.micromata.opengis.kml.v_2_2_0.Document) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 27 with Coordinate

use of org.openforis.idm.model.Coordinate 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 28 with Coordinate

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

the class CSVValueFormatter method format.

public String format(AttributeDefinition defn, Value value) {
    if (value == null) {
        return "";
    } else if (value instanceof BooleanValue) {
        return ((BooleanValue) value).getValue().toString();
    } else if (value instanceof Code) {
        CodeListService codeListService = defn.getSurvey().getContext().getCodeListService();
        CodeList list = ((CodeAttributeDefinition) defn).getList();
        if (codeListService.hasQualifiableItems(list)) {
            return String.format("%s: %s", ((Code) value).getCode(), ((Code) value).getQualifier());
        } else {
            return ((Code) value).getCode();
        }
    } else if (value instanceof Coordinate) {
        return value.toString();
    } else if (value instanceof Date) {
        Date date = (Date) value;
        return String.format("%d/%d/%d", ((Date) value).getDay(), ((Date) value).getMonth(), date.getYear());
    } else if (value instanceof File) {
        return ((File) value).getFilename();
    } else if (value instanceof NumberValue) {
        Number val = ((NumberValue<?>) value).getValue();
        NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
        String formattedVal = numberFormat.format(val);
        return formattedVal;
    } else if (value instanceof NumericRange) {
        Number from = ((NumericRange<?>) value).getFrom();
        Number to = ((NumericRange<?>) value).getFrom();
        String format;
        if (value instanceof IntegerRange) {
            format = "%d-%d";
        } else {
            format = "%f-%f";
        }
        String formattedValue = String.format(Locale.ENGLISH, format, from, to);
        return formattedValue;
    } else if (value instanceof TextValue) {
        return ((TextValue) value).getValue();
    } else if (value instanceof Time) {
        Time time = (Time) value;
        return String.format("%d:%d", time.getHour(), time.getMinute());
    } else
        throw new IllegalArgumentException("Unsupported attribute value type: " + value.getClass().getName());
}
Also used : IntegerRange(org.openforis.idm.model.IntegerRange) CodeListService(org.openforis.idm.metamodel.CodeListService) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) Date(org.openforis.idm.model.Date) NumericRange(org.openforis.idm.model.NumericRange) CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Coordinate(org.openforis.idm.model.Coordinate) NumberValue(org.openforis.idm.model.NumberValue) TextValue(org.openforis.idm.model.TextValue) BooleanValue(org.openforis.idm.model.BooleanValue) File(org.openforis.idm.model.File) NumberFormat(java.text.NumberFormat)

Example 29 with Coordinate

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

the class DatabaseLookupProvider method lookupSamplingPointCoordinate.

@Override
public Coordinate lookupSamplingPointCoordinate(Survey survey, String... keys) {
    String valueColumnName = OfcSamplingDesign.OFC_SAMPLING_DESIGN.LOCATION.getName();
    Object value = lookupSamplingPointColumnValue(survey, valueColumnName, keys);
    Coordinate coordinate = Coordinate.parseCoordinate(value);
    return coordinate;
}
Also used : Coordinate(org.openforis.idm.model.Coordinate)

Example 30 with Coordinate

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

the class RecordCoordinatesKmlGeneratorJob method processAttribute.

private void processAttribute(CoordinateAttribute coordAttr) {
    if (coordAttr.isFilled()) {
        Coordinate coordinate = coordAttr.getValue();
        Coordinate wgs84Coordinate = coordinateOperations.convertTo(coordinate, SpatialReferenceSystem.WGS84_SRS_ID);
        kmlDoc.createAndAddPlacemark().withName(((CollectRecord) coordAttr.getRecord()).getRootEntityKeyValues().toString()).withOpen(Boolean.TRUE).createAndSetPoint().addToCoordinates(wgs84Coordinate.getY(), wgs84Coordinate.getX());
    }
}
Also used : Coordinate(org.openforis.idm.model.Coordinate)

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