use of org.geotoolkit.gml.xml.Envelope in project geotoolkit by Geomatys.
the class BBOXType method getMaxX.
@Override
public double getMaxX() {
Object candidate = getAny();
if (candidate instanceof JAXBElement) {
candidate = ((JAXBElement) candidate).getValue();
}
if (candidate instanceof Envelope) {
final Envelope env = (Envelope) candidate;
final DirectPosition pos = env.getUpperCorner();
if (pos != null && pos.getCoordinate() != null && pos.getCoordinate().length > 1) {
return pos.getCoordinate()[0];
}
}
return -1;
}
use of org.geotoolkit.gml.xml.Envelope in project geotoolkit by Geomatys.
the class GeometryTransformer method get.
/**
* Procede to conversion from GML to JTS.
* @return Created JTS geometry. Never null, but can be an emptry geometry.
* @throws UnconvertibleObjectException If we don't know how to process
* source GML geometry.
*/
@Override
public Geometry get() throws UnconvertibleObjectException {
Geometry geometry;
/*
* SIMPLE CASES
*/
if (source instanceof org.geotoolkit.gml.xml.Point) {
geometry = accumulateAndBuild(coords -> (coords.length > 0 ? GF.createPoint(coords[0]) : GF.createPoint((Coordinate) null)));
} else if (source instanceof org.geotoolkit.gml.xml.LineString) {
geometry = accumulateAndBuild(GF::createLineString);
} else if (source instanceof org.geotoolkit.gml.xml.LinearRing) {
geometry = accumulateAndBuild(GF::createLinearRing);
} else if (source instanceof Curve) {
geometry = convertCurve((Curve) source);
} else if (source instanceof Envelope) {
geometry = convertEnvelope((Envelope) source);
/*
* COMPOSED GEOMETRIES
*/
} else if (source instanceof org.geotoolkit.gml.xml.Ring) {
geometry = convertRing((Ring) source);
} else if (source instanceof org.geotoolkit.gml.xml.Polygon) {
geometry = convertPolygon((org.geotoolkit.gml.xml.Polygon) source);
if (isForceMultiPolygon()) {
Polygon[] polys = { (Polygon) geometry };
final MultiPolygon result = GF.createMultiPolygon(polys);
applyCRS(result);
geometry = result;
}
} else if (source instanceof AbstractSurface) {
if (source instanceof SurfaceType) {
geometry = convertSurface((SurfaceType) source);
} else if (source instanceof org.geotoolkit.gml.xml.v311.SurfaceType) {
geometry = convertSurface((org.geotoolkit.gml.xml.v311.SurfaceType) source);
} else // TODO : complex case
{
throw new IllegalArgumentException("Unsupported geometry type : " + source.getClass());
}
/*
* GEOMETRY COLLECTIONS
*/
} else if (source instanceof org.geotoolkit.gml.xml.MultiPoint) {
geometry = convertMultiPoint((org.geotoolkit.gml.xml.MultiPoint) source);
} else if (source instanceof org.geotoolkit.gml.xml.MultiLineString) {
geometry = convertMultiLineString((org.geotoolkit.gml.xml.MultiLineString) source);
} else if (source instanceof MultiCurve) {
geometry = convertMultiCurve((MultiCurve) source);
} else if (source instanceof org.geotoolkit.gml.xml.MultiPolygon) {
geometry = convertMultiPolygon((org.geotoolkit.gml.xml.MultiPolygon) source);
} else if (source instanceof MultiSurface) {
geometry = convertMultiSurface((MultiSurface) source);
} else if (source instanceof MultiGeometry) {
geometry = convertMultiGeometry((MultiGeometry) source);
} else {
throw new IllegalArgumentException("Unsupported geometry type : " + source.getClass());
}
// store identifier in user map
final String id = source.getId();
if (id != null && !id.isEmpty()) {
Object userData = geometry.getUserData();
Map values;
if (userData instanceof Map) {
values = (Map) userData;
} else if (userData instanceof CoordinateReferenceSystem) {
values = new HashMap();
values.put(org.apache.sis.internal.feature.jts.JTS.CRS_KEY, userData);
} else if (userData == null) {
values = new HashMap();
} else {
throw new IllegalArgumentException("Unexpected user data object : " + userData);
}
values.put("@id", id);
geometry.setUserData(values);
}
return geometry;
}
use of org.geotoolkit.gml.xml.Envelope in project geotoolkit by Geomatys.
the class OMUtils method getCollectionBound.
/**
* Return an envelope containing all the Observation member of the collection.
*
* @param version
* @param observations
* @param srsName
* @return
*/
public static Envelope getCollectionBound(final String version, final List<Observation> observations, final String srsName) {
double minx = Double.MAX_VALUE;
double miny = Double.MAX_VALUE;
double maxx = -Double.MAX_VALUE;
double maxy = -Double.MAX_VALUE;
for (Observation observation : observations) {
final AbstractFeature feature = (AbstractFeature) observation.getFeatureOfInterest();
if (feature != null) {
if (feature.getBoundedBy() != null) {
final BoundingShape bound = feature.getBoundedBy();
if (bound.getEnvelope() != null) {
if (bound.getEnvelope().getLowerCorner() != null && bound.getEnvelope().getLowerCorner().getCoordinate() != null && bound.getEnvelope().getLowerCorner().getCoordinate().length == 2) {
final double[] lower = bound.getEnvelope().getLowerCorner().getCoordinate();
if (lower[0] < minx) {
minx = lower[0];
}
if (lower[1] < miny) {
miny = lower[1];
}
}
if (bound.getEnvelope().getUpperCorner() != null && bound.getEnvelope().getUpperCorner().getCoordinate() != null && bound.getEnvelope().getUpperCorner().getCoordinate().length == 2) {
final double[] upper = bound.getEnvelope().getUpperCorner().getCoordinate();
if (upper[0] > maxx) {
maxx = upper[0];
}
if (upper[1] > maxy) {
maxy = upper[1];
}
}
}
}
}
}
if (minx == Double.MAX_VALUE) {
minx = -180.0;
}
if (miny == Double.MAX_VALUE) {
miny = -90.0;
}
if (maxx == (-Double.MAX_VALUE)) {
maxx = 180.0;
}
if (maxy == (-Double.MAX_VALUE)) {
maxy = 90.0;
}
final Envelope env = SOSXmlFactory.buildEnvelope(version, null, minx, miny, maxx, maxy, srsName);
env.setSrsDimension(2);
env.setAxisLabels(Arrays.asList("Y X"));
return env;
}
use of org.geotoolkit.gml.xml.Envelope in project geotoolkit by Geomatys.
the class GeoSpatialBound method extractBoundary.
private void extractBoundary(final AbstractGeometry geom) {
if (geom instanceof Point) {
final Point p = (Point) geom;
if (p.getPos() != null) {
addXCoordinate(p.getPos().getOrdinate(0));
addYCoordinate(p.getPos().getOrdinate(1));
}
} else if (geom instanceof LineString) {
final LineString ls = (LineString) geom;
final Envelope env = ls.getBounds();
if (env != null) {
addXCoordinate(env.getMinimum(0));
addXCoordinate(env.getMaximum(0));
addYCoordinate(env.getMinimum(1));
addYCoordinate(env.getMaximum(1));
}
} else if (geom instanceof Polygon) {
final Polygon p = (Polygon) geom;
AbstractRing ext = p.getExterior().getAbstractRing();
// TODO
}
}
use of org.geotoolkit.gml.xml.Envelope in project geotoolkit by Geomatys.
the class GeometryTransformer method convertEnvelope.
private Polygon convertEnvelope(final Envelope source) {
final org.locationtech.jts.geom.Envelope e = new org.locationtech.jts.geom.Envelope(convertDirectPosition(source.getLowerCorner()), convertDirectPosition(source.getUpperCorner()));
final Polygon geom = JTS.toGeometry(e);
applyCRS(geom);
return geom;
}
Aggregations