Search in sources :

Example 1 with AbstractDataRecord

use of org.geotoolkit.swe.xml.AbstractDataRecord in project geotoolkit by Geomatys.

the class NetCDFExtractor method parseDataBlockGrid.

private static ExtractionResult parseDataBlockGrid(final NCFieldAnalyze analyze, final String procedureID, final List<String> acceptedSensorID, Set<org.opengis.observation.Phenomenon> phenomenons) throws NetCDFParsingException {
    final ExtractionResult results = new ExtractionResult();
    if (acceptedSensorID == null || acceptedSensorID.contains(procedureID)) {
        final Process proc = (Process) OMUtils.buildProcess(procedureID);
        final ProcedureTree compo = new ProcedureTree(proc.getHref(), proc.getName(), proc.getDescription(), "grid", "Component");
        results.procedures.add(compo);
        if (analyze.mainField == null) {
            LOGGER.warning("No main field found");
            return results;
        }
        LOGGER.info("parsing netCDF GRID");
        try {
            final Variable latVar = analyze.vars.get(analyze.latField.name);
            final Variable lonVar = analyze.vars.get(analyze.lonField.name);
            final Array latArray = analyze.file.readArrays(Arrays.asList(latVar)).get(0);
            final Array lonArray = analyze.file.readArrays(Arrays.asList(lonVar)).get(0);
            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 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);
            final int latSize = latVar.getDimension(0).getLength();
            for (int latIndex = 0; latIndex < latSize; latIndex++) {
                final int lonSize = lonVar.getDimension(0).getLength();
                for (int lonIndex = 0; lonIndex < lonSize; lonIndex++) {
                    final String identifier = UUID.randomUUID().toString();
                    final MeasureStringBuilder sb = new MeasureStringBuilder();
                    final int count = timeVar.getDimension(0).getLength();
                    final GeoSpatialBound gb = new GeoSpatialBound();
                    SamplingFeature sp = null;
                    final double latitude = getDoubleValue(latArray, latIndex, analyze.latField.fillValue);
                    final double longitude = Longitude.normalize(getDoubleValue(lonArray, lonIndex, analyze.lonField.fillValue));
                    if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
                        sp = OMUtils.buildSamplingPoint(identifier, latitude, longitude);
                        results.addFeatureOfInterest(sp);
                        gb.addXYCoordinate(longitude, latitude);
                    }
                    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, latIndex, lonIndex, 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);
                }
            }
            results.spatialBound.addGeometry(results.spatialBound.getPolyGonBounds("2.0.0"));
            compo.spatialBound.addGeometry(results.spatialBound.getPolyGonBounds("2.0.0"));
        } catch (IOException | IllegalArgumentException ex) {
            throw new NetCDFParsingException("error while parsing netcdf grid", 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 2 with AbstractDataRecord

use of org.geotoolkit.swe.xml.AbstractDataRecord in project geotoolkit by Geomatys.

the class NetCDFExtractor method parseDataBlockTraj.

private static ExtractionResult parseDataBlockTraj(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 Traj");
    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.getDataRecordTrajectory("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(), "trajectory", "Component");
                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();
                final List<DirectPosition> positions = new ArrayList<>();
                DirectPosition previousPosition = null;
                // 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);
                    final double latitude = getDoubleValue(latArray, i, analyze.latField.fillValue);
                    sb.appendValue(latitude);
                    final double longitude = Longitude.normalize(getDoubleValue(lonArray, i, analyze.lonField.fillValue));
                    sb.appendValue(longitude);
                    if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
                        final DirectPosition position = SOSXmlFactory.buildDirectPosition("2.0.0", null, 2, Arrays.asList(latitude, longitude));
                        if (!position.equals(previousPosition)) {
                            positions.add(position);
                        }
                        previousPosition = position;
                        gb.addXYCoordinate(longitude, latitude);
                    }
                    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();
                }
                final SamplingFeature sp = OMUtils.buildSamplingCurve("foi-" + identifier, positions);
                results.addFeatureOfInterest(sp);
                gb.addGeometry((AbstractGeometry) sp.getGeometry());
                results.observations.add(// id
                OMUtils.buildObservation(// id
                "obs-" + 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(), "trajectory", "System");
            results.procedures.add(system);
            for (int j = 0; j < separators.size(); j++) {
                final String identifier = separators.get(j);
                final MeasureStringBuilder sb = new MeasureStringBuilder();
                int count = timeVar.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(), "trajectory", "Component");
                if (acceptedSensorID == null || acceptedSensorID.contains(currentProcID)) {
                    final List<DirectPosition> positions = new ArrayList<>();
                    DirectPosition previousPosition = null;
                    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);
                        final double latitude = getDoubleValue(true, latArray, i, j, analyze.latField.fillValue);
                        final double longitude = Longitude.normalize(getDoubleValue(true, lonArray, i, j, analyze.lonField.fillValue));
                        sb.appendValue(latitude);
                        sb.appendValue(longitude);
                        if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
                            final DirectPosition position = SOSXmlFactory.buildDirectPosition("2.0.0", null, 2, Arrays.asList(latitude, longitude));
                            if (!position.equals(previousPosition)) {
                                positions.add(position);
                            }
                            previousPosition = position;
                            gb.addXYCoordinate(longitude, latitude);
                        }
                        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);
                        }
                        sb.closeBlock();
                    }
                    final SamplingFeature sp = OMUtils.buildSamplingCurve(identifier, positions);
                    results.addFeatureOfInterest(sp);
                    gb.addGeometry((AbstractGeometry) sp.getGeometry());
                    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 trajectory", ex);
    }
    LOGGER.info("datablock parsed");
    return results;
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) Variable(ucar.nc2.Variable) ArrayList(java.util.ArrayList) Process(org.geotoolkit.observation.xml.Process) GeoSpatialBound(org.geotoolkit.observation.model.GeoSpatialBound) SamplingFeature(org.geotoolkit.sampling.xml.SamplingFeature) ExtractionResult(org.geotoolkit.observation.model.ExtractionResult) AbstractDataRecord(org.geotoolkit.swe.xml.AbstractDataRecord) MeasureStringBuilder(org.geotoolkit.sos.MeasureStringBuilder) IOException(java.io.IOException) Array(ucar.ma2.Array) Phenomenon(org.geotoolkit.swe.xml.Phenomenon) ProcedureTree(org.geotoolkit.observation.model.ExtractionResult.ProcedureTree)

Example 3 with AbstractDataRecord

use of org.geotoolkit.swe.xml.AbstractDataRecord 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 4 with AbstractDataRecord

use of org.geotoolkit.swe.xml.AbstractDataRecord 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)

Aggregations

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 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 Array (ucar.ma2.Array)4 Variable (ucar.nc2.Variable)4 ArrayList (java.util.ArrayList)1 DirectPosition (org.opengis.geometry.DirectPosition)1