Search in sources :

Example 6 with SamplingFeature

use of org.geotoolkit.sampling.xml.SamplingFeature in project geotoolkit by Geomatys.

the class OMUtils method buildSamplingPoint.

public static SamplingFeature buildSamplingPoint(final String identifier, final double latitude, final double longitude) {
    final DirectPosition position = SOSXmlFactory.buildDirectPosition("2.0.0", "EPSG:4326", 2, Arrays.asList(latitude, longitude));
    final Point geom = SOSXmlFactory.buildPoint("2.0.0", "SamplingPoint", position);
    geom.setSrsName("EPSG:4326");
    final SamplingFeature sp = SOSXmlFactory.buildSamplingPoint("2.0.0", identifier, null, null, null, geom);
    return sp;
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) SamplingFeature(org.geotoolkit.sampling.xml.SamplingFeature) Point(org.geotoolkit.gml.xml.Point)

Example 7 with SamplingFeature

use of org.geotoolkit.sampling.xml.SamplingFeature in project geotoolkit by Geomatys.

the class OMUtils method buildSamplingCurve.

public static SamplingFeature buildSamplingCurve(final String identifier, final List<DirectPosition> positions) {
    final LineString geom = SOSXmlFactory.buildLineString("2.0.0", null, "EPSG:4326", positions);
    final SamplingFeature sp = SOSXmlFactory.buildSamplingCurve("2.0.0", identifier, null, null, null, geom, null, null, null);
    return sp;
}
Also used : LineString(org.geotoolkit.gml.xml.LineString) SamplingFeature(org.geotoolkit.sampling.xml.SamplingFeature)

Example 8 with SamplingFeature

use of org.geotoolkit.sampling.xml.SamplingFeature in project geotoolkit by Geomatys.

the class NetCDFExtractor method parseDataBlockXY.

private static ExtractionResult parseDataBlockXY(final NCFieldAnalyze analyze, final String procedureID, final List<String> acceptedSensorID, Set<org.opengis.observation.Phenomenon> phenomenons) throws NetCDFParsingException {
    final ExtractionResult results = new ExtractionResult();
    if (analyze.mainField == null) {
        LOGGER.warning("No main field found");
        return results;
    }
    LOGGER.info("parsing datablock XY");
    try {
        final List<String> separators = parseSeparatorValues(analyze);
        final boolean single = separators.isEmpty();
        Array latArray = null;
        Array lonArray = null;
        if (analyze.hasSpatial()) {
            latArray = analyze.getArrayFromField(analyze.latField);
            lonArray = analyze.getArrayFromField(analyze.lonField);
        }
        Array timeArray = null;
        String timeUnits = null;
        if (analyze.hasTime()) {
            timeUnits = analyze.timeField.uom;
            timeArray = analyze.getArrayFromField(analyze.timeField);
        }
        final Variable zVar = analyze.vars.get(analyze.mainField.name);
        final Array zArray = analyze.file.readArrays(Arrays.asList(zVar)).get(0);
        final boolean constantZ = analyze.mainField.dimension == 1;
        final boolean Zfirst = analyze.mainField.mainVariableFirst;
        final Map<String, Array> phenArrays = analyze.getPhenomenonArrayMap();
        results.fields.addAll(phenArrays.keySet());
        final AbstractDataRecord datarecord = OMUtils.getDataRecordProfile("2.0.0", analyze.phenfields);
        final Phenomenon phenomenon = OMUtils.getPhenomenon("2.0.0", analyze.phenfields, phenomenons);
        results.phenomenons.add(phenomenon);
        if (single) {
            if (acceptedSensorID == null || acceptedSensorID.contains(procedureID)) {
                final Process proc = (Process) OMUtils.buildProcess(procedureID);
                final ProcedureTree compo = new ProcedureTree(proc.getHref(), proc.getName(), proc.getDescription(), "profile", "Component");
                results.procedures.add(compo);
                final MeasureStringBuilder sb = new MeasureStringBuilder();
                final int count = zVar.getDimension(0).getLength();
                final GeoSpatialBound gb = new GeoSpatialBound();
                final String identifier = UUID.randomUUID().toString();
                // read geometry (assume point)
                SamplingFeature sp = null;
                if (analyze.hasSpatial()) {
                    final double latitude = getDoubleValue(latArray, 0, analyze.latField.fillValue);
                    final double longitude = Longitude.normalize(getDoubleValue(lonArray, 0, analyze.lonField.fillValue));
                    if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
                        sp = OMUtils.buildSamplingPoint(identifier, latitude, longitude);
                        results.addFeatureOfInterest(sp);
                        gb.addXYCoordinate(longitude, latitude);
                        gb.addGeometry((AbstractGeometry) sp.getGeometry());
                    }
                }
                if (analyze.hasTime()) {
                    final long millis = getTimeValue(timeUnits, timeArray, 0);
                    if (millis != 0 && millis != LIMIT) {
                        gb.addDate(millis);
                    }
                }
                for (int zIndex = 0; zIndex < zVar.getDimension(0).getLength(); zIndex++) {
                    double zLevel = getDoubleValue(zArray, zIndex, analyze.mainField.fillValue);
                    if (zLevel == 0 || zLevel == FILL_VALUE) {
                        continue;
                    }
                    sb.appendValue(zLevel);
                    for (NCField field : analyze.phenfields) {
                        final Array phenArray = phenArrays.get(field.name);
                        final double value = getDoubleValue(phenArray, zIndex, field.fillValue);
                        sb.appendValue(value);
                    }
                    sb.closeBlock();
                }
                results.observations.add(// id
                OMUtils.buildObservation(// id
                identifier, // foi
                sp, // phenomenon
                phenomenon, // procedure
                proc, // result
                count, // result
                datarecord, // result
                sb, // time
                gb.getTimeObject("2.0.0")));
                results.spatialBound.merge(gb);
                compo.spatialBound.merge(gb);
            }
        } else {
            final Process proc = (Process) OMUtils.buildProcess(procedureID);
            final ProcedureTree system = new ProcedureTree(proc.getHref(), proc.getName(), proc.getDescription(), "profile", "System");
            results.procedures.add(system);
            for (int profileIndex = 0; profileIndex < separators.size(); profileIndex++) {
                final String identifier = separators.get(profileIndex);
                final int count = zVar.getDimension(0).getLength();
                final GeoSpatialBound gb = new GeoSpatialBound();
                final String currentProcID = procedureID + '-' + identifier;
                final Process currentProc = (Process) OMUtils.buildProcess(currentProcID);
                final ProcedureTree compo = new ProcedureTree(currentProc.getHref(), currentProc.getName(), currentProc.getDescription(), "profile", "Component");
                if (acceptedSensorID == null || acceptedSensorID.contains(currentProcID)) {
                    // read geometry (assume point)
                    SamplingFeature sp = null;
                    if (analyze.hasSpatial()) {
                        final double latitude = getDoubleValue(latArray, 0, analyze.latField.fillValue);
                        final double longitude = Longitude.normalize(getDoubleValue(lonArray, 0, analyze.lonField.fillValue));
                        if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
                            sp = OMUtils.buildSamplingPoint(identifier, latitude, longitude);
                            results.addFeatureOfInterest(sp);
                            gb.addXYCoordinate(longitude, latitude);
                            gb.addGeometry((AbstractGeometry) sp.getGeometry());
                        }
                    }
                    if (analyze.hasTime()) {
                        final long millis = getTimeValue(timeUnits, timeArray, 0);
                        if (millis != 0 && millis != LIMIT) {
                            gb.addDate(millis);
                        }
                    }
                    final MeasureStringBuilder sb = new MeasureStringBuilder();
                    for (int zIndex = 0; zIndex < zVar.getDimension(0).getLength(); zIndex++) {
                        double zLevel = getZValue(Zfirst, constantZ, zArray, zIndex, profileIndex, analyze.mainField.fillValue);
                        if (zLevel == 0 || zLevel == FILL_VALUE) {
                            continue;
                        }
                        sb.appendValue(zLevel);
                        for (NCField field : analyze.phenfields) {
                            final Array phenArray = phenArrays.get(field.name);
                            final boolean mainFirst = field.mainVariableFirst;
                            final double value = getDoubleValue(mainFirst, phenArray, zIndex, profileIndex, field.fillValue);
                            sb.appendValue(value);
                        }
                        sb.closeBlock();
                    }
                    compo.spatialBound.merge(gb);
                    system.children.add(compo);
                    final String obsid = UUID.randomUUID().toString();
                    results.observations.add(// id
                    OMUtils.buildObservation(// id
                    obsid, // foi
                    sp, // phenomenon
                    phenomenon, // procedure
                    currentProc, // result
                    count, // result
                    datarecord, // result
                    sb, // time
                    gb.getTimeObject("2.0.0")));
                    results.spatialBound.merge(gb);
                }
            }
        }
    } catch (IOException | IllegalArgumentException ex) {
        throw new NetCDFParsingException("error while parsing netcdf profile", ex);
    }
    LOGGER.info("datablock parsed");
    return results;
}
Also used : Variable(ucar.nc2.Variable) MeasureStringBuilder(org.geotoolkit.sos.MeasureStringBuilder) Process(org.geotoolkit.observation.xml.Process) GeoSpatialBound(org.geotoolkit.observation.model.GeoSpatialBound) SamplingFeature(org.geotoolkit.sampling.xml.SamplingFeature) IOException(java.io.IOException) Array(ucar.ma2.Array) Phenomenon(org.geotoolkit.swe.xml.Phenomenon) ProcedureTree(org.geotoolkit.observation.model.ExtractionResult.ProcedureTree) ExtractionResult(org.geotoolkit.observation.model.ExtractionResult) AbstractDataRecord(org.geotoolkit.swe.xml.AbstractDataRecord)

Example 9 with SamplingFeature

use of org.geotoolkit.sampling.xml.SamplingFeature in project geotoolkit by Geomatys.

the class NetcdfFeatureReader method getFeatureFromFOI.

protected final Feature getFeatureFromFOI(final AnyFeature foi) {
    if (foi instanceof SamplingFeature) {
        final SamplingFeature feature = (SamplingFeature) foi;
        final org.opengis.geometry.Geometry isoGeom = feature.getGeometry();
        try {
            final Geometry geom;
            if (isoGeom instanceof AbstractGeometry) {
                geom = GeometrytoJTS.toJTS((AbstractGeometry) isoGeom, AxisResolve.STRICT);
            } else {
                geom = null;
            }
            if (firstCRS && isoGeom != null) {
                // configure crs in the feature type
                final CoordinateReferenceSystem crs = ((AbstractGeometry) isoGeom).getCoordinateReferenceSystem(false);
                type = new ReprojectMapper(type, crs).getMappedType();
                firstCRS = false;
            }
            final Feature f = type.newInstance();
            f.setPropertyValue(AttributeConvention.IDENTIFIER, feature.getId());
            f.setPropertyValue(OMFeatureTypes.ATT_DESC.toString(), feature.getDescription());
            f.setPropertyValue(OMFeatureTypes.ATT_NAME.toString(), feature.getName());
            f.setPropertyValue(OMFeatureTypes.ATT_POSITION.toString(), geom);
            final List<String> sampleds = new ArrayList<>();
            for (FeatureProperty featProp : feature.getSampledFeatures()) {
                if (featProp.getHref() != null) {
                    sampleds.add(featProp.getHref());
                }
            }
            f.setPropertyValue(OMFeatureTypes.ATT_SAMPLED.toString(), sampleds);
            return f;
        } catch (FactoryException ex) {
            LOGGER.log(Level.WARNING, "error while transforming GML geometry to JTS", ex);
        }
    } else {
        LOGGER.warning("unable to find a valid feature of interest in the observation");
    }
    return null;
}
Also used : AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) FactoryException(org.opengis.util.FactoryException) ReprojectMapper(org.geotoolkit.feature.ReprojectMapper) ArrayList(java.util.ArrayList) SamplingFeature(org.geotoolkit.sampling.xml.SamplingFeature) SamplingFeature(org.geotoolkit.sampling.xml.SamplingFeature) Feature(org.opengis.feature.Feature) AnyFeature(org.opengis.observation.AnyFeature) FeatureProperty(org.geotoolkit.gml.xml.FeatureProperty) AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) Geometry(org.locationtech.jts.geom.Geometry) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Aggregations

SamplingFeature (org.geotoolkit.sampling.xml.SamplingFeature)9 IOException (java.io.IOException)4 ExtractionResult (org.geotoolkit.observation.model.ExtractionResult)4 ProcedureTree (org.geotoolkit.observation.model.ExtractionResult.ProcedureTree)4 GeoSpatialBound (org.geotoolkit.observation.model.GeoSpatialBound)4 Process (org.geotoolkit.observation.xml.Process)4 MeasureStringBuilder (org.geotoolkit.sos.MeasureStringBuilder)4 AbstractDataRecord (org.geotoolkit.swe.xml.AbstractDataRecord)4 Phenomenon (org.geotoolkit.swe.xml.Phenomenon)4 Array (ucar.ma2.Array)4 Variable (ucar.nc2.Variable)4 ArrayList (java.util.ArrayList)3 AbstractGeometry (org.geotoolkit.gml.xml.AbstractGeometry)3 FeatureProperty (org.geotoolkit.gml.xml.FeatureProperty)2 Geometry (org.locationtech.jts.geom.Geometry)2 Feature (org.opengis.feature.Feature)2 DirectPosition (org.opengis.geometry.DirectPosition)2 AnyFeature (org.opengis.observation.AnyFeature)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 FactoryException (org.opengis.util.FactoryException)2