use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.
the class RingHandler method createGeometry.
/**
* Create a {@link LinearRing} geometry from the given instance.
*
* @param instance the instance
* @param srsDimension the SRS dimension
* @param allowTryOtherDimension if trying another dimension is allowed on
* failure (e.g. 3D instead of 2D)
* @param reader the I/O Provider to get value
* @return the {@link LinearRing} geometry
* @throws GeometryNotSupportedException if the type definition doesn't
* represent a geometry type supported by the handler
*/
protected GeometryProperty<LinearRing> createGeometry(Instance instance, int srsDimension, boolean allowTryOtherDimension, IOProvider reader) throws GeometryNotSupportedException {
LinearRing ring = null;
// for use with GML 2, 3, 3.1, 3.2
// use generic geometry handler to read curveMembers as MultiLineString
// or LineString
Collection<GeometryProperty<?>> properties = genericHandler.createGeometry(instance, srsDimension, reader);
if (properties != null) {
if (properties.size() == 1) {
// geometry could be combined
GeometryProperty<?> prop = properties.iterator().next();
try {
ring = getGeometryFactory().createLinearRing(filterDuplicates(prop.getGeometry().getCoordinates()));
} catch (IllegalArgumentException e) {
if (allowTryOtherDimension) {
// the error
// "Points of LinearRing do not form a closed
// linestring"
// can be an expression of a wrong dimension being used
// we try an alternative, to be sure (e.g. 3D instead of
// 2D)
int alternativeDimension = (srsDimension == 2) ? (3) : (2);
GeometryProperty<LinearRing> geom = createGeometry(instance, alternativeDimension, false, reader);
log.debug("Assuming geometry is " + alternativeDimension + "-dimensional.");
return geom;
}
throw e;
}
if (ring != null) {
CRSDefinition crsDef = prop.getCRSDefinition();
if (crsDef == null) {
GMLGeometryUtil.findCRS(instance);
}
return new DefaultGeometryProperty<LinearRing>(crsDef, ring);
}
} else {
throw new GeometryNotSupportedException("Ring components could not be combined to a geometry");
}
}
throw new GeometryNotSupportedException();
}
use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.
the class PolygonPatchGeometryTest method init.
@Override
public void init() {
super.init();
LinearRing shell = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(0.01, 3.2), new Coordinate(3.33, 3.33), new Coordinate(0.01, -3.2), new Coordinate(-3.33, -3.2), new Coordinate(0.01, 3.2) });
LinearRing[] holes = new LinearRing[2];
LinearRing hole1 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(0, 1), new Coordinate(1, 1), new Coordinate(0, -1), new Coordinate(-1, -1), new Coordinate(0, 1) });
LinearRing hole2 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(0, 2), new Coordinate(2, 2), new Coordinate(0, -2), new Coordinate(-2, -2), new Coordinate(0, 2) });
holes[0] = hole1;
holes[1] = hole2;
reference = geomFactory.createPolygon(shell, holes);
checker = combine(noCoordinatePairs(), referenceChecker(reference));
gridChecker = combine(noCoordinatePairs(), referenceChecker(reference, InterpolationHelper.DEFAULT_MAX_POSITION_ERROR), gridConfig.geometryChecker());
}
use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.
the class RectangleGeometryTest method init.
@Override
public void init() {
super.init();
Coordinate[] coordinates = new Coordinate[] { new Coordinate(0.01, 3.2), new Coordinate(3.33, 3.33), new Coordinate(0.01, -3.2), new Coordinate(-3.33, -3.2), new Coordinate(0.01, 3.2) };
LinearRing linearRing = geomFactory.createLinearRing(coordinates);
referencePolygon = geomFactory.createPolygon(linearRing, null);
checker = combine(noCoordinatePairs(), referenceChecker(referencePolygon));
gridChecker = combine(noCoordinatePairs(), referenceChecker(referencePolygon, InterpolationHelper.DEFAULT_MAX_POSITION_ERROR), gridConfig.geometryChecker());
}
use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.
the class TriangleGeometryTest method init.
@Override
public void init() {
super.init();
Coordinate[] coordinates = new Coordinate[] { new Coordinate(0.01, 3.2), new Coordinate(3.33, 3.33), new Coordinate(0.01, -3.2), new Coordinate(-3.33, -3.2), new Coordinate(0.01, 3.2) };
LinearRing linearRing = geomFactory.createLinearRing(coordinates);
referencePolygon = geomFactory.createPolygon(linearRing, null);
checker = combine(noCoordinatePairs(), referenceChecker(referencePolygon));
gridChecker = combine(noCoordinatePairs(), referenceChecker(referencePolygon, InterpolationHelper.DEFAULT_MAX_POSITION_ERROR), gridConfig.geometryChecker());
}
use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.
the class LinearRingHandler method createGeometry.
/**
* Create a {@link LinearRing} geometry from the given instance.
*
* @param instance the instance
* @param srsDimension the SRS dimension
* @param allowTryOtherDimension if trying another dimension is allowed on
* failure (e.g. 3D instead of 2D)
* @param reader the I/O Provider to get value
* @return the {@link LinearRing} geometry
* @throws GeometryNotSupportedException if the type definition doesn't
* represent a geometry type supported by the handler
*/
protected GeometryProperty<LinearRing> createGeometry(Instance instance, int srsDimension, boolean allowTryOtherDimension, IOProvider reader) throws GeometryNotSupportedException {
LinearRing ring = null;
LineStringHandler handler = new LineStringHandler();
// for use with GML 2, 3, 3.1, 3.2
@SuppressWarnings("unchecked") DefaultGeometryProperty<LineString> linestring = (DefaultGeometryProperty<LineString>) handler.createGeometry(instance, srsDimension, reader);
try {
ring = getGeometryFactory().createLinearRing(linestring.getGeometry().getCoordinates());
} catch (IllegalArgumentException e) {
if (allowTryOtherDimension) {
// the error
// "Points of LinearRing do not form a closed linestring"
// can be an expression of a wrong dimension being used
// we try an alternative, to be sure (e.g. 3D instead of 2D)
int alternativeDimension = (srsDimension == 2) ? (3) : (2);
GeometryProperty<LinearRing> geom = createGeometry(instance, alternativeDimension, false, reader);
log.debug("Assuming geometry is " + alternativeDimension + "-dimensional.");
return geom;
}
throw e;
}
if (ring != null) {
CRSDefinition crsDef = GMLGeometryUtil.findCRS(instance);
return new DefaultGeometryProperty<LinearRing>(crsDef, ring);
}
throw new GeometryNotSupportedException();
}
Aggregations