use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.
the class SurfaceGeometryTest method testSurfaceArcsGml32_grid.
/**
* Test surface geometries read from a GML 3.2 file
*
* @throws Exception if an error occurs
*/
@Stories("Arcs")
@Test
public void testSurfaceArcsGml32_grid() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml32.xsd").toURI(), getClass().getResource("/data/surface/sample-surface-arcs.xml").toURI(), gridConfig);
// three instance expected
ResourceIterator<Instance> it = instances.iterator();
try {
List<GeometryProperty<?>> geoms = new ArrayList<>();
assertTrue("First sample feature missing", it.hasNext());
Instance instance1 = it.next();
geoms.addAll(checkSingleGeometry(instance1, null));
assertTrue("Second sample feature missing", it.hasNext());
Instance instance2 = it.next();
geoms.addAll(checkSingleGeometry(instance2, null));
assertTrue("Third sample feature missing", it.hasNext());
Instance instance3 = it.next();
geoms.addAll(checkSingleGeometry(instance3, null));
assertEquals("Unexpected number of geometries", 3, geoms.size());
Geometry geom1 = geoms.get(0).getGeometry();
Geometry geom2 = geoms.get(1).getGeometry();
Geometry geom3 = geoms.get(2).getGeometry();
Envelope envelope = new Envelope();
envelope.expandToInclude(geom1.getEnvelopeInternal());
envelope.expandToInclude(geom2.getEnvelopeInternal());
envelope.expandToInclude(geom3.getEnvelopeInternal());
PaintSettings settings = new PaintSettings(envelope, 1000, 10);
SVGPainter svg = new SVGPainter(settings);
svg.setColor(Color.BLACK);
svg.drawGeometry(geom1);
svg.setColor(Color.BLUE);
svg.drawGeometry(geom2);
svg.setColor(Color.RED);
svg.drawGeometry(geom3);
saveDrawing(svg);
// ensure that polygons could be created
assertTrue(Polygon.class.isAssignableFrom(geom1.getClass()));
assertTrue(Polygon.class.isAssignableFrom(geom2.getClass()));
assertTrue(Polygon.class.isAssignableFrom(geom3.getClass()));
// XXX how to test?
// assertTrue("Geometries intersect", geom1.touches(geom2));
// assertTrue("Geometries intersect", geom2.touches(geom3));
} finally {
it.close();
}
}
use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.
the class SurfaceGeometryTest method testSurfaceArcsGml32.
/**
* Test surface geometries read from a GML 3.2 file
*
* @throws Exception if an error occurs
*/
@Stories("Arcs")
@Test
public void testSurfaceArcsGml32() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml32.xsd").toURI(), getClass().getResource("/data/surface/sample-surface-arcs.xml").toURI(), InterpolationConfigurations.segment(maxPositionalError));
// three instance expected
ResourceIterator<Instance> it = instances.iterator();
try {
List<GeometryProperty<?>> geoms = new ArrayList<>();
assertTrue("First sample feature missing", it.hasNext());
Instance instance1 = it.next();
geoms.addAll(checkSingleGeometry(instance1, null));
assertTrue("Second sample feature missing", it.hasNext());
Instance instance2 = it.next();
geoms.addAll(checkSingleGeometry(instance2, null));
assertTrue("Third sample feature missing", it.hasNext());
Instance instance3 = it.next();
geoms.addAll(checkSingleGeometry(instance3, null));
assertEquals("Unexpected number of geometries", 3, geoms.size());
Geometry geom1 = geoms.get(0).getGeometry();
Geometry geom2 = geoms.get(1).getGeometry();
Geometry geom3 = geoms.get(2).getGeometry();
Envelope envelope = new Envelope();
envelope.expandToInclude(geom1.getEnvelopeInternal());
envelope.expandToInclude(geom2.getEnvelopeInternal());
envelope.expandToInclude(geom3.getEnvelopeInternal());
PaintSettings settings = new PaintSettings(envelope, 1000, 10);
SVGPainter svg = new SVGPainter(settings);
svg.setColor(Color.BLACK);
svg.drawGeometry(geom1);
svg.setColor(Color.BLUE);
svg.drawGeometry(geom2);
svg.setColor(Color.RED);
svg.drawGeometry(geom3);
saveDrawing(svg);
// ensure that polygons could be created
assertTrue(Polygon.class.isAssignableFrom(geom1.getClass()));
assertTrue(Polygon.class.isAssignableFrom(geom2.getClass()));
assertTrue(Polygon.class.isAssignableFrom(geom3.getClass()));
// XXX how to test?
// intersection area cannot be computed
// double interArea1 = geom1.intersection(geom2).getArea();
// double interArea2 = geom2.intersection(geom3).getArea();
} finally {
it.close();
}
}
use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.
the class ArcByCenterPointHandler method createGeometry.
@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
PointHandler handler = new PointHandler();
// XXX support for different types of line strings in one instance (we
// support only one type per instance!)
Coordinate[] controlCoord = null;
double radius = 0;
double startAngle = 0;
double endAngle = 0;
// to parse coordinates of a line string
// for use with GML 2, 3, 3.1, 3.2
Collection<Object> values = PropertyResolver.getValues(instance, "coordinates", false);
if (values != null && !values.isEmpty()) {
Object value = values.iterator().next();
if (value instanceof Instance) {
try {
controlCoord = GMLGeometryUtil.parseCoordinates((Instance) value);
} catch (ParseException e) {
throw new GeometryNotSupportedException("Could not parse coordinates", e);
}
}
}
// for use with GML 3, 3.2
if (controlCoord == null || controlCoord.length == 0) {
values = PropertyResolver.getValues(instance, "pos", false);
if (values != null && !values.isEmpty()) {
Iterator<Object> iterator = values.iterator();
List<Coordinate> cs = new ArrayList<Coordinate>();
while (iterator.hasNext()) {
Object value = iterator.next();
if (value instanceof Instance) {
Coordinate c = GMLGeometryUtil.parseDirectPosition((Instance) value);
if (c != null) {
cs.add(c);
}
}
}
controlCoord = cs.toArray(new Coordinate[cs.size()]);
}
}
// for use with GML 3.1, 3.2
if (controlCoord == null || controlCoord.length == 0) {
values = PropertyResolver.getValues(instance, "posList", false);
if (values != null && !values.isEmpty()) {
Iterator<Object> iterator = values.iterator();
Object value = iterator.next();
if (value instanceof Instance) {
controlCoord = GMLGeometryUtil.parsePosList((Instance) value, srsDimension);
}
}
}
if (controlCoord == null || controlCoord.length == 0) {
values = PropertyResolver.getValues(instance, "pointRep.Point", false);
if (values != null && !values.isEmpty()) {
Iterator<Object> iterator = values.iterator();
List<Coordinate> cs = new ArrayList<Coordinate>();
while (iterator.hasNext()) {
Object value = iterator.next();
if (value instanceof Instance) {
try {
@SuppressWarnings("unchecked") DefaultGeometryProperty<Point> point = (DefaultGeometryProperty<Point>) handler.createGeometry((Instance) value, srsDimension, reader);
cs.add(point.getGeometry().getCoordinate());
} catch (GeometryNotSupportedException e) {
throw new GeometryNotSupportedException("Could not parse Point Representation", e);
}
}
}
controlCoord = cs.toArray(new Coordinate[cs.size()]);
}
}
// for use with GML 3.1
if (controlCoord == null || controlCoord.length == 0) {
values = PropertyResolver.getValues(instance, "pointProperty.Point", false);
if (values != null && !values.isEmpty()) {
Iterator<Object> iterator = values.iterator();
List<Coordinate> cs = new ArrayList<Coordinate>();
while (iterator.hasNext()) {
Object value = iterator.next();
if (value instanceof Instance) {
try {
@SuppressWarnings("unchecked") DefaultGeometryProperty<Point> point = (DefaultGeometryProperty<Point>) handler.createGeometry((Instance) value, srsDimension, reader);
cs.add(point.getGeometry().getCoordinate());
} catch (GeometryNotSupportedException e) {
throw new GeometryNotSupportedException("Could not parse Point Property", e);
}
}
}
controlCoord = cs.toArray(new Coordinate[cs.size()]);
}
}
// for use with GML2, 3, 3.1, 3.2
if (controlCoord == null || controlCoord.length == 0) {
values = PropertyResolver.getValues(instance, "coord", false);
if (values != null && !values.isEmpty()) {
Iterator<Object> iterator = values.iterator();
List<Coordinate> cs = new ArrayList<Coordinate>();
while (iterator.hasNext()) {
Object value = iterator.next();
if (value instanceof Instance) {
Coordinate c = GMLGeometryUtil.parseCoord((Instance) value);
if (c != null) {
cs.add(c);
}
}
}
controlCoord = cs.toArray(new Coordinate[cs.size()]);
}
}
values = PropertyResolver.getValues(instance, "radius", false);
if (values != null && !values.isEmpty()) {
Object value = values.iterator().next();
if (value instanceof Instance) {
// ##TODO :: need to check with real time data
radius = ConversionUtil.getAs(((Instance) value).getValue(), Double.class);
}
}
values = PropertyResolver.getValues(instance, "startAngle", false);
if (values != null && !values.isEmpty()) {
Object value = values.iterator().next();
if (value != null) {
if (value instanceof Instance) {
// ##TODO: handle if value comes in degree, minute and
// second format. Need to check with real time data
startAngle = ConversionUtil.getAs(((Instance) value).getValue(), Double.class);
}
}
}
values = PropertyResolver.getValues(instance, "endAngle", false);
if (values != null && !values.isEmpty()) {
Object value = values.iterator().next();
if (value != null) {
if (value instanceof Instance) {
// ##TODO: handle if value comes in degree, minute and
// second format. Need to check with real time data
endAngle = ConversionUtil.getAs(((Instance) value).getValue(), Double.class);
}
}
}
if (controlCoord != null && controlCoord.length != 0 && radius != 0) {
CRSDefinition crsDef = GMLGeometryUtil.findCRS(instance);
// create Arc
// FIXME verify how arc should be created from information in GML
boolean clockwise = endAngle - startAngle < 0;
Arc arc = new ArcByCenterPointImpl(controlCoord[0], radius, Angle.fromDegrees(startAngle), Angle.fromDegrees(endAngle), clockwise);
// get interpolation algorithm
InterpolationAlgorithm interpol = InterpolationHelper.getInterpolation(reader, getGeometryFactory());
LineString interpolatedArc = interpol.interpolateArc(arc);
if (interpolatedArc == null) {
log.error("Arc could be not interpolated to Linestring");
return null;
}
return new DefaultGeometryProperty<LineString>(crsDef, interpolatedArc);
}
throw new GeometryNotSupportedException();
}
use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.
the class LineStringHandler method createGeometry.
// XXX support for Triangle and Rectangle is not optimal (only exterior and
// outerBounderIs needed)
@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
LineString line = null;
PointHandler handler = new PointHandler();
// XXX support for different types of line strings in one instance (we
// support only one type per instance!)
// to parse coordinates of a line string
// for use with GML 2, 3, 3.1, 3.2
Collection<Object> values = PropertyResolver.getValues(instance, "coordinates", false);
if (values != null && !values.isEmpty()) {
Object value = values.iterator().next();
if (value instanceof Instance) {
try {
Coordinate[] cs = GMLGeometryUtil.parseCoordinates((Instance) value);
if (cs != null && cs.length > 0) {
line = getGeometryFactory().createLineString(moveCoordinates(cs, reader));
}
} catch (ParseException e) {
throw new GeometryNotSupportedException("Could not parse coordinates", e);
}
}
}
// for use with GML 3, 3.2
if (line == null) {
values = PropertyResolver.getValues(instance, "pos", false);
if (values != null && !values.isEmpty()) {
Iterator<Object> iterator = values.iterator();
List<Coordinate> cs = new ArrayList<Coordinate>();
while (iterator.hasNext()) {
Object value = iterator.next();
if (value instanceof Instance) {
Coordinate c = GMLGeometryUtil.parseDirectPosition((Instance) value);
if (c != null) {
cs.add(c);
}
}
}
Coordinate[] coords = moveCoordinates(cs.toArray(new Coordinate[cs.size()]), reader);
line = getGeometryFactory().createLineString(coords);
}
}
// for use with GML 3.1, 3.2
if (line == null) {
values = PropertyResolver.getValues(instance, "posList", false);
if (values != null && !values.isEmpty()) {
Iterator<Object> iterator = values.iterator();
Object value = iterator.next();
if (value instanceof Instance) {
Coordinate[] cs = GMLGeometryUtil.parsePosList((Instance) value, srsDimension);
if (cs != null) {
line = getGeometryFactory().createLineString(moveCoordinates(cs, reader));
}
}
}
}
if (line == null) {
values = PropertyResolver.getValues(instance, "pointRep.Point", false);
if (values != null && !values.isEmpty()) {
Iterator<Object> iterator = values.iterator();
List<Coordinate> cs = new ArrayList<Coordinate>();
while (iterator.hasNext()) {
Object value = iterator.next();
if (value instanceof Instance) {
try {
@SuppressWarnings("unchecked") DefaultGeometryProperty<Point> point = (DefaultGeometryProperty<Point>) handler.createGeometry((Instance) value, srsDimension, reader);
cs.add(point.getGeometry().getCoordinate());
} catch (GeometryNotSupportedException e) {
throw new GeometryNotSupportedException("Could not parse Point Representation", e);
}
}
}
Coordinate[] coords = moveCoordinates(cs.toArray(new Coordinate[cs.size()]), reader);
line = getGeometryFactory().createLineString(coords);
}
}
// for use with GML 3.1
if (line == null) {
values = PropertyResolver.getValues(instance, "pointProperty.Point", false);
if (values != null && !values.isEmpty()) {
Iterator<Object> iterator = values.iterator();
List<Coordinate> cs = new ArrayList<Coordinate>();
while (iterator.hasNext()) {
Object value = iterator.next();
if (value instanceof Instance) {
try {
@SuppressWarnings("unchecked") DefaultGeometryProperty<Point> point = (DefaultGeometryProperty<Point>) handler.createGeometry((Instance) value, srsDimension, reader);
cs.add(point.getGeometry().getCoordinate());
} catch (GeometryNotSupportedException e) {
throw new GeometryNotSupportedException("Could not parse Point Property", e);
}
}
}
Coordinate[] coords = moveCoordinates(cs.toArray(new Coordinate[cs.size()]), reader);
line = getGeometryFactory().createLineString(coords);
}
}
// for use with GML2, 3, 3.1, 3.2
if (line == null) {
values = PropertyResolver.getValues(instance, "coord", false);
if (values != null && !values.isEmpty()) {
Iterator<Object> iterator = values.iterator();
List<Coordinate> cs = new ArrayList<Coordinate>();
while (iterator.hasNext()) {
Object value = iterator.next();
if (value instanceof Instance) {
Coordinate c = GMLGeometryUtil.parseCoord((Instance) value);
if (c != null) {
cs.add(c);
}
}
}
Coordinate[] coords = moveCoordinates(cs.toArray(new Coordinate[cs.size()]), reader);
line = getGeometryFactory().createLineString(coords);
}
}
if (line != null) {
CRSDefinition crsDef = GMLGeometryUtil.findCRS(instance);
return new DefaultGeometryProperty<LineString>(crsDef, line);
}
throw new GeometryNotSupportedException();
}
use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.
the class PointHandler method createGeometry.
/**
* @see GeometryHandler#createGeometry(Instance, int, IOProvider)
*/
@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
Point point = null;
// Point is either defined by a CoordinatesType named coordinates
Collection<Object> values = PropertyResolver.getValues(instance, "coordinates", false);
if (values != null && !values.isEmpty()) {
Object value = values.iterator().next();
if (value instanceof Instance) {
try {
Coordinate[] cs = GMLGeometryUtil.parseCoordinates((Instance) value);
if (cs != null && cs.length > 0) {
cs = InterpolationHelper.moveCoordinates(reader, cs);
point = getGeometryFactory().createPoint(cs[0]);
}
} catch (ParseException e) {
throw new GeometryNotSupportedException("Could not parse coordinates", e);
}
}
}
// or by a DirectPositionType named pos
if (point == null) {
values = PropertyResolver.getValues(instance, "pos", false);
if (values != null && !values.isEmpty()) {
Object value = values.iterator().next();
if (value instanceof Instance) {
Coordinate c = GMLGeometryUtil.parseDirectPosition((Instance) value);
if (c != null) {
c = InterpolationHelper.moveCoordinate(reader, c);
point = getGeometryFactory().createPoint(c);
}
}
}
}
// or even by a CoordType in GML 2
if (point == null) {
values = PropertyResolver.getValues(instance, "coord", false);
if (values != null && !values.isEmpty()) {
Object value = values.iterator().next();
if (value instanceof Instance) {
Coordinate c = GMLGeometryUtil.parseCoord((Instance) value);
if (c != null) {
c = InterpolationHelper.moveCoordinate(reader, c);
point = getGeometryFactory().createPoint(c);
}
}
}
}
if (point != null) {
CRSDefinition crsDef = GMLGeometryUtil.findCRS(instance);
return new DefaultGeometryProperty<Point>(crsDef, point);
}
// XXX
throw new GeometryNotSupportedException();
}
Aggregations