use of com.vividsolutions.jts.geom.LinearRing in project hale by halestudio.
the class SurfaceGeometryTest method testSurfaceGml32_patches.
/**
* Test surface geometry consisting of multiple patches read from a GML 3.2
* file.
*
* @throws Exception if an error occurs
*/
@Test
public void testSurfaceGml32_patches() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml32.xsd").toURI(), getClass().getResource("/data/surface/sample-surface-gml32_patches.xml").toURI());
LinearRing shell = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(-4.5, 3), new Coordinate(0.5, 4.5), new Coordinate(5, 3), new Coordinate(8.5, 2), new Coordinate(3, -4.5), new Coordinate(1, 1), new Coordinate(-3, -1), new Coordinate(-4.5, 3) });
Polygon composedPolygon = geomFactory.createPolygon(shell);
// one instance expected
ResourceIterator<Instance> it = instances.iterator();
try {
// PolygonPatch with LinearRings defined through coordinates
assertTrue("First sample feature missing", it.hasNext());
Instance instance = it.next();
checkSingleGeometry(instance, referenceChecker(composedPolygon));
} finally {
it.close();
}
}
use of com.vividsolutions.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();
}
use of com.vividsolutions.jts.geom.LinearRing in project hale by halestudio.
the class WindingOrderTest method setUp.
/**
* Setup for different tests
*/
@BeforeClass
public static void setUp() {
GeometryFactory factory = new GeometryFactory();
r1 = factory.createLinearRing(new Coordinate[] { new Coordinate(10, 30), new Coordinate(20, 0), new Coordinate(0, 0), new Coordinate(10, 30) });
r2 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87445, 8.64729), new Coordinate(49.87582, 8.65441), new Coordinate(49.87095, 8.65694), new Coordinate(49.86978, 8.65032), new Coordinate(49.87197, 8.64758), new Coordinate(49.87341, 8.64688), new Coordinate(49.87445, 8.64729) });
h1 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87327, 8.64991), new Coordinate(49.8735, 8.6521), new Coordinate(49.87253, 8.65239), new Coordinate(49.8723, 8.65045), new Coordinate(49.87327, 8.64991) });
h2 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87203, 8.65208), new Coordinate(49.87209, 8.6531), new Coordinate(49.87156, 8.65312), new Coordinate(49.87145, 8.65227), new Coordinate(49.87203, 8.65208) });
clockWise1 = factory.createPolygon(r1);
clockWise2 = factory.createPolygon(r2, new LinearRing[] { h1, h2 });
clockWise2WOHoles = factory.createPolygon(r2);
clockWise3 = factory.createMultiPolygon(new Polygon[] { clockWise1, clockWise2 });
clockWise4 = factory.createGeometryCollection(new Geometry[] { clockWise2, clockWise2WOHoles, clockWise3, r2 });
if (crs1 == null) {
try {
crs1 = CRS_CACHE.get(code1);
} catch (Exception e) {
throw new IllegalStateException("Invalid CRS code", e);
}
}
if (crs2 == null) {
try {
crs2 = CRS_CACHE.get(code2);
} catch (Exception e) {
throw new IllegalStateException("Invalid CRS code", e);
}
}
}
use of com.vividsolutions.jts.geom.LinearRing in project hale by halestudio.
the class WindingOrder method unifyWindingOrderForPolyGon.
/**
* Unify order of the polygon as counterClockwise or not including all its
* holes.
*
* @param poly Polygon object for unifying
* @param counterClockWise boolean value. true, if want shell of Polygon as
* counter clock wise and holes as clockwise, else false.
* @return Polygon unified object.
*/
public static Polygon unifyWindingOrderForPolyGon(Polygon poly, boolean counterClockWise) {
// Checking and reversing Shell
LinearRing shell = unifyWindingOrderForLinearRing((LinearRing) poly.getExteriorRing(), counterClockWise);
Polygon revPoly;
// Checking and reversing Holes
if (poly.getNumInteriorRing() > 0) {
LinearRing[] holes = new LinearRing[poly.getNumInteriorRing()];
for (int i = 0; i < poly.getNumInteriorRing(); i++) {
holes[i] = unifyWindingOrderForLinearRing((LinearRing) poly.getInteriorRingN(i), !counterClockWise);
}
// Create New Polygon using unified shell and holes both.
revPoly = factory.createPolygon(shell, holes);
} else
// Create New Polygon using unified shell only
revPoly = factory.createPolygon(shell);
return revPoly;
}
use of com.vividsolutions.jts.geom.LinearRing in project hale by halestudio.
the class InteriorPointTest method testMulti1.
/**
* Test with a multi-polygon.
*
* @throws Exception if an error occurs
*/
@Test
public void testMulti1() throws Exception {
LinearRing outer1 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87585, 8.64984), new Coordinate(49.87597, 8.65059), new Coordinate(49.87557, 8.65071), new Coordinate(49.87545, 8.64993), new Coordinate(49.87585, 8.64984) });
Polygon poly1 = factory.createPolygon(outer1);
LinearRing outer2 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87599, 8.6507), new Coordinate(49.8761, 8.65147), new Coordinate(49.87568, 8.6516), new Coordinate(49.87558, 8.65081), new Coordinate(49.87599, 8.6507) });
Polygon poly2 = factory.createPolygon(outer2);
testPointWithin(factory.createMultiPolygon(new Polygon[] { poly1, poly2 }));
}
Aggregations