use of org.geotoolkit.observation.model.GeoSpatialBound 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.observation.model.GeoSpatialBound in project geotoolkit by Geomatys.
the class NetCDFExtractor method getProcedureGrid.
private static List<ProcedureTree> getProcedureGrid(final NCFieldAnalyze analyze, final String procedureID, final List<String> acceptedSensorID) throws NetCDFParsingException {
final List<ProcedureTree> results = new ArrayList<>();
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.add(compo);
if (analyze.mainField == null) {
LOGGER.warning("No main field identified");
return results;
}
LOGGER.info("parsing netCDF GRID");
try {
if (analyze.latField == null || analyze.lonField == null) {
LOGGER.warning("No lat/lon field identified");
return results;
}
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);
compo.fields.addAll(analyze.getPhenomenonArrayMap().keySet());
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 int count = timeVar.getDimension(0).getLength();
final GeoSpatialBound gb = new GeoSpatialBound();
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)) {
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);
}
compo.spatialBound.merge(gb);
}
}
} catch (IOException | IllegalArgumentException ex) {
throw new NetCDFParsingException("error while parsing netcdf grid", ex);
}
}
LOGGER.info("datablock parsed");
return results;
}
use of org.geotoolkit.observation.model.GeoSpatialBound in project geotoolkit by Geomatys.
the class NetCDFExtractor method getProcedureXY.
private static List<ProcedureTree> getProcedureXY(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 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 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.getDescription(), "Component", "profile", fields);
results.add(compo);
final GeoSpatialBound gb = new GeoSpatialBound();
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)) {
gb.addXYCoordinate(longitude, latitude);
}
}
if (analyze.hasTime()) {
final long millis = getTimeValue(timeUnits, timeArray, 0);
if (millis != 0 && millis != LIMIT) {
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.getDescription(), "System", "profile", fields);
results.add(system);
for (int profileIndex = 0; profileIndex < separators.size(); profileIndex++) {
final String identifier = separators.get(profileIndex);
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", "profile", fields);
if (acceptedSensorID == null || acceptedSensorID.contains(currentProcID)) {
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)) {
gb.addXYCoordinate(longitude, latitude);
}
}
if (analyze.hasTime()) {
final long millis = getTimeValue(timeUnits, timeArray, 0);
if (millis != 0 && millis != LIMIT) {
gb.addDate(millis);
}
}
compo.spatialBound.merge(gb);
system.children.add(compo);
}
}
}
} catch (IOException | IllegalArgumentException ex) {
throw new NetCDFParsingException("error while parsing netcdf profile", ex);
}
LOGGER.info("datablock parsed");
return results;
}
use of org.geotoolkit.observation.model.GeoSpatialBound in project geotoolkit by Geomatys.
the class NetCDFExtractor method getProcedureTraj.
private static List<ProcedureTree> getProcedureTraj(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 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 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.getDescription(), "Component", "trajectory", fields);
results.add(compo);
final int count = timeVar.getDimension(0).getLength();
final GeoSpatialBound gb = new GeoSpatialBound();
// 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);
final double latitude = getDoubleValue(latArray, i, analyze.latField.fillValue);
final double longitude = Longitude.normalize(getDoubleValue(lonArray, i, analyze.lonField.fillValue));
if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
gb.addXYCoordinate(longitude, latitude);
}
}
compo.spatialBound.merge(gb);
}
} else {
final Process proc = (Process) OMUtils.buildProcess(procedureID);
final ProcedureTree system = new ProcedureTree(proc.getHref(), proc.getName(), proc.getDescription(), "System", "trajectory", fields);
results.add(system);
for (int j = 0; j < separators.size(); j++) {
final String identifier = separators.get(j);
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(), "Component", "trajectory", fields);
if (acceptedSensorID == null || acceptedSensorID.contains(currentProcID)) {
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);
final double latitude = getDoubleValue(true, latArray, i, j, analyze.latField.fillValue);
final double longitude = Longitude.normalize(getDoubleValue(true, lonArray, i, j, analyze.lonField.fillValue));
if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
gb.addXYCoordinate(longitude, latitude);
}
}
compo.spatialBound.merge(gb);
system.children.add(compo);
}
}
}
} catch (IOException | IllegalArgumentException ex) {
throw new NetCDFParsingException("error while parsing netcdf trajectory", ex);
}
LOGGER.info("datablock parsed");
return results;
}
use of org.geotoolkit.observation.model.GeoSpatialBound 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;
}
Aggregations