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 PolygonToLineStringTest method testBox.
/**
* Test conversion with a simple box
*/
@Test
public void testBox() {
Coordinate[] coordinates = new Coordinate[5];
coordinates[0] = coordinates[4] = new Coordinate(0, 0);
coordinates[1] = new Coordinate(1, 0);
coordinates[2] = new Coordinate(1, 1);
coordinates[3] = new Coordinate(0, 1);
LinearRing shell = geomFactory.createLinearRing(coordinates);
Polygon poly = geomFactory.createPolygon(shell, null);
PolygonToLineString converter = new PolygonToLineString();
LineString mls = converter.convert(poly);
// $NON-NLS-1$
assertEquals("Expecting 1 lines", 1, mls.getNumGeometries());
// $NON-NLS-1$
assertEquals("Should have 5 points", 5, mls.getNumPoints());
// first point
assertEquals(coordinates[0], mls.getCoordinateN(0));
// second point
assertEquals(coordinates[0], mls.getCoordinateN(4));
}
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();
}
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 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());
}
Aggregations