Search in sources :

Example 6 with GeoSpatialBound

use of org.geotoolkit.observation.model.GeoSpatialBound in project geotoolkit by Geomatys.

the class NetCDFExtractor method parseDataBlockTS.

private static ExtractionResult parseDataBlockTS(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 netCDF TS");
    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);
        }
        final Variable timeVar = analyze.vars.get(analyze.mainField.name);
        final String timeUnits = analyze.mainField.uom;
        final Array timeArray = analyze.file.readArrays(Arrays.asList(timeVar)).get(0);
        final boolean constantT = analyze.mainField.dimension == 1;
        final boolean timeFirst = analyze.mainField.mainVariableFirst;
        final Map<String, Array> phenArrays = analyze.getPhenomenonArrayMap();
        results.fields.addAll(phenArrays.keySet());
        final AbstractDataRecord datarecord = OMUtils.getDataRecordTimeSeries("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(), "Component", "timeseries");
                results.procedures.add(compo);
                final MeasureStringBuilder sb = new MeasureStringBuilder();
                final int count = timeVar.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, analyze.latField.fillValue);
                    final double longitude = Longitude.normalize(getDoubleValue(lonArray, 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());
                    }
                }
                // iterating over time
                for (int i = 0; i < count; i++) {
                    final long millis = getTimeValue(timeUnits, timeArray, i);
                    if (millis == 0 || millis == LIMIT) {
                        continue;
                    }
                    gb.addDate(millis);
                    sb.appendDate(millis);
                    for (NCField field : analyze.phenfields) {
                        final Array phenArray = phenArrays.get(field.name);
                        final Double value = getDoubleValue(phenArray, i, 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(), "System", "timeseries");
            results.procedures.add(system);
            for (int j = 0; j < separators.size(); j++) {
                final String identifier = separators.get(j);
                final MeasureStringBuilder sb = new MeasureStringBuilder();
                final int count = getGoodTimeDimension(timeVar, analyze.dimensionSeparator).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(), "Component", "timeseries");
                if (acceptedSensorID == null || acceptedSensorID.contains(currentProcID)) {
                    // read geometry (assume point)
                    SamplingFeature sp = null;
                    if (analyze.hasSpatial()) {
                        final double latitude = getDoubleValue(latArray, j, analyze.latField.fillValue);
                        final double longitude = Longitude.normalize(getDoubleValue(lonArray, j, 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());
                        }
                    }
                    for (int i = 0; i < count; i++) {
                        final long millis = getTimeValue(timeUnits, timeFirst, constantT, timeArray, i, j);
                        if (millis == 0 || millis == LIMIT) {
                            continue;
                        }
                        gb.addDate(millis);
                        sb.appendDate(millis);
                        for (NCField field : analyze.phenfields) {
                            final Array phenArray = phenArrays.get(field.name);
                            final boolean mainFirst = field.mainVariableFirst;
                            final Double value = getDoubleValue(mainFirst, phenArray, i, j, field.fillValue);
                            sb.appendValue(value);
                        }
                        // remove the last token separator
                        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 timeserie", 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 7 with GeoSpatialBound

use of org.geotoolkit.observation.model.GeoSpatialBound 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 8 with GeoSpatialBound

use of org.geotoolkit.observation.model.GeoSpatialBound in project geotoolkit by Geomatys.

the class NetCDFExtractor method getProcedureTS.

private static List<ProcedureTree> getProcedureTS(final NCFieldAnalyze analyze, final String procedureID, final List<String> acceptedSensorID) throws NetCDFParsingException {
    final List<ProcedureTree> results = new ArrayList<>();
    if (analyze.mainField == null) {
        LOGGER.warning("No main field found");
        return results;
    }
    LOGGER.info("parsing netCDF TS");
    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);
        }
        final Variable timeVar = analyze.vars.get(analyze.mainField.name);
        final String timeUnits = analyze.mainField.uom;
        final Array timeArray = analyze.file.readArrays(Arrays.asList(timeVar)).get(0);
        final boolean constantT = analyze.mainField.dimension == 1;
        final boolean timeFirst = analyze.mainField.mainVariableFirst;
        final Set<String> fields = analyze.getPhenomenonArrayMap().keySet();
        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.getHref(), "Component", "timeseries", fields);
                results.add(compo);
                final int count = timeVar.getDimension(0).getLength();
                final GeoSpatialBound gb = new GeoSpatialBound();
                if (analyze.hasSpatial()) {
                    final double latitude = getDoubleValue(latArray, analyze.latField.fillValue);
                    final double longitude = Longitude.normalize(getDoubleValue(lonArray, analyze.lonField.fillValue));
                    if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
                        gb.addXYCoordinate(longitude, latitude);
                    }
                }
                // iterating over time
                for (int i = 0; i < count; i++) {
                    final long millis = getTimeValue(timeUnits, timeArray, i);
                    if (millis == 0 || millis == LIMIT) {
                        continue;
                    }
                    gb.addDate(millis);
                }
                compo.spatialBound.merge(gb);
            }
        } else {
            final Process proc = (Process) OMUtils.buildProcess(procedureID);
            final ProcedureTree system = new ProcedureTree(proc.getHref(), proc.getName(), proc.getHref(), "System", "timeseries", fields);
            results.add(system);
            for (int j = 0; j < separators.size(); j++) {
                final String identifier = separators.get(j);
                final int count = getGoodTimeDimension(timeVar, analyze.dimensionSeparator).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(), "Component", "timeseries", fields);
                if (acceptedSensorID == null || acceptedSensorID.contains(currentProcID)) {
                    if (analyze.hasSpatial()) {
                        final double latitude = getDoubleValue(latArray, j, analyze.latField.fillValue);
                        final double longitude = Longitude.normalize(getDoubleValue(lonArray, j, analyze.lonField.fillValue));
                        if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
                            gb.addXYCoordinate(longitude, latitude);
                        }
                    }
                    for (int i = 0; i < count; i++) {
                        final long millis = getTimeValue(timeUnits, timeFirst, constantT, timeArray, i, j);
                        if (millis == 0 || millis == LIMIT) {
                            continue;
                        }
                        gb.addDate(millis);
                    }
                    compo.spatialBound.merge(gb);
                    system.children.add(compo);
                }
            }
        }
    } catch (IOException | IllegalArgumentException ex) {
        throw new NetCDFParsingException("error while parsing netcdf timeserie", ex);
    }
    LOGGER.info("datablock parsed");
    return results;
}
Also used : Variable(ucar.nc2.Variable) ArrayList(java.util.ArrayList) Process(org.geotoolkit.observation.xml.Process) GeoSpatialBound(org.geotoolkit.observation.model.GeoSpatialBound) IOException(java.io.IOException) Array(ucar.ma2.Array) ProcedureTree(org.geotoolkit.observation.model.ExtractionResult.ProcedureTree)

Aggregations

IOException (java.io.IOException)8 ProcedureTree (org.geotoolkit.observation.model.ExtractionResult.ProcedureTree)8 GeoSpatialBound (org.geotoolkit.observation.model.GeoSpatialBound)8 Process (org.geotoolkit.observation.xml.Process)8 Array (ucar.ma2.Array)8 Variable (ucar.nc2.Variable)7 ArrayList (java.util.ArrayList)5 ExtractionResult (org.geotoolkit.observation.model.ExtractionResult)4 SamplingFeature (org.geotoolkit.sampling.xml.SamplingFeature)4 MeasureStringBuilder (org.geotoolkit.sos.MeasureStringBuilder)4 AbstractDataRecord (org.geotoolkit.swe.xml.AbstractDataRecord)4 Phenomenon (org.geotoolkit.swe.xml.Phenomenon)4 DirectPosition (org.opengis.geometry.DirectPosition)1