use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.
the class ExtendedWKBReader method readPolygon.
@SuppressWarnings("null")
private Polygon readPolygon() throws IOException {
int numRings = dis.readInt();
LinearRing[] holes = null;
if (numRings > 1)
holes = new LinearRing[numRings - 1];
LinearRing shell = readLinearRing();
for (int i = 0; i < numRings - 1; i++) {
holes[i] = readLinearRing();
}
return factory.createPolygon(shell, holes);
}
use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.
the class PolygonHandlerTest method init.
// XXX no test for geometry properties
@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 CompositeSurfaceGeometryTest 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;
Polygon polygon1 = geomFactory.createPolygon(shell, holes);
shell = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(6.01, 9.2), new Coordinate(9.33, 9.33), new Coordinate(6.01, -9.2), new Coordinate(-9.33, -9.2), new Coordinate(6.01, 9.2) });
holes = new LinearRing[2];
hole1 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(2, 3), new Coordinate(3, 3), new Coordinate(2, -3), new Coordinate(-3, -3), new Coordinate(2, 3) });
hole2 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(2, 4), new Coordinate(4, 4), new Coordinate(2, -4), new Coordinate(-4, -4), new Coordinate(2, 4) });
holes[0] = hole1;
holes[1] = hole2;
Polygon polygon2 = geomFactory.createPolygon(shell, holes);
Polygon[] polygons = new Polygon[] { polygon1, polygon2 };
reference = geomFactory.createMultiPolygon(polygons);
checker = referenceChecker(reference);
gridChecker = combine(referenceChecker(reference, InterpolationHelper.DEFAULT_MAX_POSITION_ERROR), gridConfig.geometryChecker());
}
use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.
the class OrientableSurfaceGeometryTest method init.
@Override
public void init() {
super.init();
LinearRing shell = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(-122.44, 37.80), new Coordinate(-122.45, 37.80), new Coordinate(-122.45, 37.78), new Coordinate(-122.44, 37.78), new Coordinate(-122.44, 37.80) });
LinearRing[] holes = new LinearRing[1];
LinearRing hole1 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(-122.24, 37.60), new Coordinate(-122.25, 37.60), new Coordinate(-122.25, 37.58), new Coordinate(-122.24, 37.58), new Coordinate(-122.24, 37.60) });
holes[0] = hole1;
reference = geomFactory.createPolygon(shell, holes);
checker = referenceChecker(reference);
gridChecker = combine(referenceChecker(reference, maxPositionalError), gridConfig.geometryChecker());
}
use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.
the class PolygonHandler method createGeometry.
/**
* @see GeometryHandler#createGeometry(Instance, int, IOProvider)
*/
@SuppressWarnings("unchecked")
@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
LinearRing[] holes = null;
Polygon polygon = null;
CRSDefinition crs = null;
// for use with GML 2
// to parse outer linear rings
Collection<Object> values = PropertyResolver.getValues(instance, "outerBoundaryIs.LinearRing", false);
if (values != null && !values.isEmpty()) {
Iterator<Object> iterator = values.iterator();
List<LinearRing> outerRing = new ArrayList<>(1);
while (iterator.hasNext()) {
Object value = iterator.next();
if (value instanceof Instance) {
// outerRing must be a
// GeometryProperty<LinearRing> instance
GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
outerRing.add(ring.getGeometry());
crs = checkCommonCrs(crs, ring.getCRSDefinition());
}
}
// to parse inner linear rings
values = PropertyResolver.getValues(instance, "innerBoundaryIs.LinearRing", false);
if (values != null && !values.isEmpty()) {
iterator = values.iterator();
List<LinearRing> innerRings = new ArrayList<LinearRing>();
while (iterator.hasNext()) {
Object value = iterator.next();
if (value instanceof Instance) {
// innerRings have to be a
// GeometryProperty<LinearRing> instance
GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
innerRings.add(ring.getGeometry());
crs = checkCommonCrs(crs, ring.getCRSDefinition());
}
}
holes = innerRings.toArray(new LinearRing[innerRings.size()]);
}
polygon = getGeometryFactory().createPolygon(outerRing.get(0), holes);
}
// to parse inner linear rings
if (polygon == null) {
values = PropertyResolver.getValues(instance, "interior.LinearRing", false);
Collection<Object> ringValues = PropertyResolver.getValues(instance, "interior.Ring", false);
values = combineCollections(values, ringValues);
if (values != null && !values.isEmpty()) {
Iterator<Object> iterator = values.iterator();
List<LinearRing> innerRings = new ArrayList<LinearRing>();
while (iterator.hasNext()) {
Object value = iterator.next();
if (value instanceof Instance) {
// innerRings have to be a
// GeometryProperty<LinearRing> instance
GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
innerRings.add(ring.getGeometry());
crs = checkCommonCrs(crs, ring.getCRSDefinition());
}
}
holes = innerRings.toArray(new LinearRing[innerRings.size()]);
}
// to parse outer linear rings
values = PropertyResolver.getValues(instance, "exterior.LinearRing", false);
ringValues = PropertyResolver.getValues(instance, "exterior.Ring", false);
values = combineCollections(values, ringValues);
List<LinearRing> outerRing = new ArrayList<>(1);
if (values != null && !values.isEmpty()) {
LinearRing outer = null;
Iterator<Object> iterator = values.iterator();
while (iterator.hasNext()) {
Object value = iterator.next();
if (value instanceof Instance) {
// outerRing must be a
// GeometryProperty<LinearRing> instance
GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
outer = ring.getGeometry();
crs = checkCommonCrs(crs, ring.getCRSDefinition());
}
}
outerRing.add(outer);
polygon = getGeometryFactory().createPolygon(outerRing.get(0), holes);
}
}
if (polygon != null) {
if (crs == null) {
crs = GMLGeometryUtil.findCRS(instance);
}
return new DefaultGeometryProperty<Polygon>(crs, polygon);
}
throw new GeometryNotSupportedException();
}
Aggregations