use of org.locationtech.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 org.locationtech.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 org.locationtech.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 org.locationtech.jts.geom.LinearRing in project hale by halestudio.
the class InteriorPointTest method testTriangle.
/**
* Test with a simple triangular polygon.
*
* @throws Exception if an error occurs
*/
@Test
public void testTriangle() throws Exception {
LinearRing outer = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87401, 8.65491), new Coordinate(49.87318, 8.65606), new Coordinate(49.87297, 8.6545), new Coordinate(49.87401, 8.65491) });
Polygon geom = factory.createPolygon(outer);
testPointWithin(geom);
}
use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.
the class InteriorPointTest method testFootprint2Hole.
/**
* Test with a complex polygon describing a rough building footprint.
*
* @throws Exception if an error occurs
*/
@Test
public void testFootprint2Hole() throws Exception {
LinearRing outer = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87517, 8.64862), new Coordinate(49.87491, 8.64873), new Coordinate(49.87497, 8.64913), new Coordinate(49.87521, 8.64904), new Coordinate(49.87525, 8.64924), new Coordinate(49.87424, 8.64958), new Coordinate(49.8742, 8.64937), new Coordinate(49.87446, 8.64929), new Coordinate(49.87441, 8.6489), new Coordinate(49.87414, 8.64897), new Coordinate(49.87411, 8.64877), new Coordinate(49.87514, 8.64844), new Coordinate(49.87517, 8.64862) });
LinearRing inner = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87478, 8.6488), new Coordinate(49.87482, 8.64914), new Coordinate(49.8746, 8.64924), new Coordinate(49.87454, 8.64887), new Coordinate(49.87478, 8.6488) });
Polygon geom = factory.createPolygon(outer, new LinearRing[] { inner });
testPointWithin(geom);
}
Aggregations