use of org.geotoolkit.sampling.xml.SamplingFeature 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;
}
use of org.geotoolkit.sampling.xml.SamplingFeature 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;
}
use of org.geotoolkit.sampling.xml.SamplingFeature 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;
}
use of org.geotoolkit.sampling.xml.SamplingFeature in project geotoolkit by Geomatys.
the class GeoSpatialBound method appendLocation.
public void appendLocation(final TemporalObject time, final AnyFeature feature) {
Date d = addTime(time);
AbstractGeometry ageom = null;
if (feature instanceof SamplingFeature) {
final SamplingFeature sf = (SamplingFeature) feature;
final Geometry geom = sf.getGeometry();
if (geom instanceof AbstractGeometry) {
ageom = (AbstractGeometry) geom;
} else if (geom != null) {
ageom = GMLUtilities.getGMLFromISO(geom);
}
addGeometry(ageom);
extractBoundary(ageom);
}
if (d != null && ageom != null) {
historicalLocation.put(d, ageom);
}
}
use of org.geotoolkit.sampling.xml.SamplingFeature in project geotoolkit by Geomatys.
the class XmlFeatureReader method getFeatureFromFOI.
protected final Feature getFeatureFromFOI(final AnyFeature foi) {
if (foi instanceof SamplingFeature) {
final SamplingFeature feature = (SamplingFeature) foi;
final Feature f = type.newInstance();
f.setPropertyValue(AttributeConvention.IDENTIFIER, feature.getId());
final org.opengis.geometry.Geometry isoGeom = feature.getGeometry();
try {
final Geometry geom;
if (isoGeom instanceof AbstractGeometry) {
geom = GeometrytoJTS.toJTS((AbstractGeometry) isoGeom);
} else {
geom = null;
}
if (firstCRS && isoGeom != null) {
// configure crs in the feature type
final CoordinateReferenceSystem crs = ((AbstractGeometry) isoGeom).getCoordinateReferenceSystem(false);
type = FeatureTypeExt.createSubType(type, null, crs);
firstCRS = false;
}
f.setPropertyValue(ATT_DESC.toString(), feature.getDescription());
if (feature.getName() != null) {
f.setPropertyValue(ATT_NAME.toString(), feature.getName().toString());
}
f.setPropertyValue(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(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;
}
Aggregations