use of eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm 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.util.geometry.interpolation.InterpolationAlgorithm in project hale by halestudio.
the class CircleHandler method createGeometry.
@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
@SuppressWarnings("unchecked") DefaultGeometryProperty<LineString> lineStringGeomProperty = (DefaultGeometryProperty<LineString>) super.createGeometry(instance, srsDimension, reader);
// create Arc for circle
Coordinate[] coords = lineStringGeomProperty.getGeometry().getCoordinates();
if (coords.length != 3) {
throw new GeometryNotSupportedException("Arc must be defined by three points");
}
Arc arc = new ArcByPointsImpl(coords[0], coords[1], coords[2]);
ArcByCenterPoint byCenter = arc.toArcByCenterPoint();
ArcByCenterPoint circle = new ArcByCenterPointImpl(byCenter.getCenterPoint(), byCenter.getRadius(), byCenter.getStartAngle(), byCenter.getStartAngle(), byCenter.isClockwise());
// get interpolation algorithm
InterpolationAlgorithm interpol = InterpolationHelper.getInterpolation(reader, getGeometryFactory());
LineString interpolatedCircle = interpol.interpolateArc(circle);
if (interpolatedCircle == null) {
log.error("Circle could be not interpolated to Linestring");
return null;
}
return new DefaultGeometryProperty<LineString>(lineStringGeomProperty.getCRSDefinition(), interpolatedCircle);
}
use of eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm in project hale by halestudio.
the class ArcHandler method createGeometry.
@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
// read arc to LineString
@SuppressWarnings("unchecked") DefaultGeometryProperty<LineString> lineStringGeomProperty = (DefaultGeometryProperty<LineString>) super.createGeometry(instance, srsDimension, reader);
// create Arc
Coordinate[] coords = lineStringGeomProperty.getGeometry().getCoordinates();
if (coords.length != 3) {
throw new GeometryNotSupportedException("Arc must be defined by three points");
}
Arc arc = new ArcByPointsImpl(coords[0], coords[1], coords[2]);
// 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>(lineStringGeomProperty.getCRSDefinition(), interpolatedArc);
}
use of eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm in project hale by halestudio.
the class ArcStringHandler method createGeometry.
@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
@SuppressWarnings("unchecked") DefaultGeometryProperty<LineString> lineStringGeomProperty = (DefaultGeometryProperty<LineString>) super.createGeometry(instance, srsDimension, reader);
// create Arc
Coordinate[] coords = lineStringGeomProperty.getGeometry().getCoordinates();
if (coords.length < 3) {
throw new GeometryNotSupportedException("Arc string must be defined by at least three points");
}
List<Arc> arcs = new ArrayList<>();
for (int i = 0; i < coords.length - 2; i += 2) {
Arc arc = new ArcByPointsImpl(coords[i], coords[i + 1], coords[i + 2]);
arcs.add(arc);
}
ArcString arcString = new ArcStringImpl(arcs);
// get interpolation algorithm
InterpolationAlgorithm interpol = InterpolationHelper.getInterpolation(reader, getGeometryFactory());
LineString interpolatedArcString = interpol.interpolateArcString(arcString);
if (interpolatedArcString == null) {
log.error("ArcString could be not interpolated to Linestring");
return null;
}
return new DefaultGeometryProperty<LineString>(lineStringGeomProperty.getCRSDefinition(), interpolatedArcString);
}
use of eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm in project hale by halestudio.
the class CircleByCenterPointHandler 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;
// 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);
}
}
if (controlCoord != null && controlCoord.length != 0 && radius != 0) {
CRSDefinition crsDef = GMLGeometryUtil.findCRS(instance);
// create Arc representing a circle
Arc arc = new ArcByCenterPointImpl(controlCoord[0], radius, Angle.fromDegrees(0), Angle.fromDegrees(0), true);
// get interpolation algorithm
InterpolationAlgorithm interpol = InterpolationHelper.getInterpolation(reader, getGeometryFactory());
LineString interpolatedCircle = interpol.interpolateArc(arc);
if (interpolatedCircle == null) {
log.error("Circle could be not interpolated to Linestring");
return null;
}
return new DefaultGeometryProperty<LineString>(crsDef, interpolatedCircle);
}
throw new GeometryNotSupportedException();
}
Aggregations