use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class ShapefileGeometryHandler method newPolygonGeometryFromParts.
public Geometry newPolygonGeometryFromParts(final GeometryFactory geometryFactory, final List<double[]> parts, final int axisCount) {
final List<Polygon> polygons = new ArrayList<>();
final List<LinearRing> currentParts = new ArrayList<>();
for (final double[] coordinates : parts) {
final LinearRing ring = geometryFactory.linearRing(axisCount, coordinates);
final boolean ringClockwise = ring.isClockwise();
if (ringClockwise) {
if (!currentParts.isEmpty()) {
final Polygon polygon = geometryFactory.polygon(currentParts);
polygons.add(polygon);
currentParts.clear();
}
}
currentParts.add(ring);
}
if (!currentParts.isEmpty()) {
final Polygon polygon = geometryFactory.polygon(currentParts);
polygons.add(polygon);
}
if (polygons.size() == 1) {
return polygons.get(0);
} else {
return geometryFactory.polygonal(polygons);
}
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class ShapefileGeometryUtil method writePolygon.
private List<LineString> writePolygon(final EndianOutput out, final Geometry geometry, final int shapeType, final int headerOverhead, final int wordsPerPoint) throws IOException {
int vertexCount = 0;
final List<LineString> rings = new ArrayList<>();
for (int i = 0; i < geometry.getGeometryCount(); i++) {
final Geometry part = geometry.getGeometry(i);
if (part instanceof Polygon) {
final Polygon polygon = (Polygon) part;
LineString shell = polygon.getShell();
shell = shell.toClockwise();
rings.add(shell);
vertexCount += shell.getVertexCount();
final int numHoles = polygon.getHoleCount();
for (int j = 0; j < numHoles; j++) {
LineString hole = polygon.getHole(j);
hole = hole.toCounterClockwise();
rings.add(hole);
vertexCount += hole.getVertexCount();
}
} else {
throw new IllegalArgumentException("Expecting " + Polygon.class + " geometry got " + part.getClass());
}
}
final int numParts = rings.size();
if (this.writeLength) {
final int recordLength = 22 + headerOverhead + 2 * numParts + wordsPerPoint * vertexCount;
out.writeInt(recordLength);
}
out.writeLEInt(shapeType);
final BoundingBox envelope = geometry.getBoundingBox();
writeEnvelope(out, envelope);
out.writeLEInt(numParts);
out.writeLEInt(vertexCount);
int partIndex = 0;
for (final LineString ring : rings) {
out.writeLEInt(partIndex);
partIndex += ring.getVertexCount();
}
for (final LineString ring : rings) {
writeXYCoordinates(out, ring);
}
return rings;
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class GeometryTestUtil method polygon.
public static Polygon polygon(final GeometryFactory geometryFactory, final int ringCount, final double delta) {
final int axisCount = geometryFactory.getAxisCount();
final List<LinearRing> rings = new ArrayList<>();
for (int ringIndex = 0; ringIndex < ringCount; ringIndex++) {
final double[] coordinates = new double[axisCount * 5];
final double offset = delta / 100 * ringIndex;
final double size = delta - offset * 2;
final double[] firstPoint = coordinates(geometryFactory, delta);
final double x = Doubles.makePrecise(1000000, firstPoint[0] + offset);
final double y = Doubles.makePrecise(1000000, firstPoint[1] + offset);
for (int vertexIndex = 0; vertexIndex < 5; vertexIndex++) {
final double[] point = coordinates(geometryFactory, delta);
point[0] = x;
point[1] = y;
if (vertexIndex == 1) {
point[1] += size;
} else if (vertexIndex == 2) {
point[0] += size;
point[1] += size;
} else if (vertexIndex == 3) {
point[0] += size;
}
point[0] = Doubles.makePrecise(1000000, point[0]);
point[1] = Doubles.makePrecise(1000000, point[1]);
CoordinatesListUtil.setCoordinates(coordinates, axisCount, vertexIndex, point);
}
LinearRing ring = geometryFactory.linearRing(axisCount, coordinates);
if (ringIndex > 0) {
ring = ring.reverse();
}
rings.add(ring);
}
final Polygon polygon = geometryFactory.polygon(rings);
return polygon;
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class PolygonTest method testVertices.
@Test
public void testVertices() {
final List<Point> allCoordinates = new ArrayList<>();
allCoordinates.addAll(EXTERIOR_1);
allCoordinates.addAll(INTERIOR_2);
final Polygon polygon = WITH_HOLE;
int i = 0;
for (final Vertex vertex : polygon.vertices()) {
final Point point = allCoordinates.get(i);
Assert.assertEquals(point, vertex);
i++;
}
Assert.assertEquals(new PointDoubleXY(0.0, 0.0), polygon.getVertex(0, 0));
Assert.assertNull("VertexIndex out of range", polygon.getVertex(0, 6));
Assert.assertNull("VertexIndex out of range", polygon.getVertex(1, 6));
Assert.assertNull("RingIndex Negative", polygon.getVertex(-1, 0));
Assert.assertNull("RingIndex out of range", polygon.getVertex(2, 0));
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class CoordinateSequenceExperiment2 method run2.
public void run2(final int nPts) throws IOException {
final double size = 100.0;
final double armLen = 50.0;
final int nArms = 10;
long startTime = System.currentTimeMillis();
final Polygon poly = GeometryTestFactory.newSineStar(this.fact, 0.0, 0.0, size, armLen, nArms, nPts);
final Polygon box = GeometryTestFactory.newSineStar(this.fact, 0.0, size / 2, size, armLen, nArms, nPts);
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
String totalTimeStr = totalTime < 10000 ? totalTime + " ms" : totalTime / 1000.0 + " s";
// System.out.println("Sine Star Creation Executed in " + totalTimeStr);
// RobustDeterminant.callCount = 0;
// System.out.println("n Pts: " + nPts);
startTime = System.currentTimeMillis();
poly.intersects(box);
// poly.intersection(box);
endTime = System.currentTimeMillis();
totalTime = endTime - startTime;
totalTimeStr = totalTime < 10000 ? totalTime + " ms" : totalTime / 1000.0 + " s";
// System.out.println(" signOfDet2x2 calls: " +
// RobustDeterminant.callCount);
// System.out.println(" Executed in " + totalTimeStr);
}
Aggregations