use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.
the class OgrRecordWriter method toOgrGeometry.
protected org.gdal.ogr.Geometry toOgrGeometry(final Geometry geometry, final int geometryType, final int axisCount) {
final org.gdal.ogr.Geometry ogrGeometry = new org.gdal.ogr.Geometry(geometryType);
if (!geometry.isEmpty()) {
switch(geometryType) {
case 1:
case 0x80000000 + 1:
{
final Point point = (Point) geometry;
final double x = point.getX();
final double y = point.getY();
if (axisCount == 2) {
ogrGeometry.AddPoint(x, y);
} else {
final double z = point.getZ();
ogrGeometry.AddPoint(x, y, z);
}
}
break;
case 2:
case 0x80000000 + 2:
final LineString line = (LineString) geometry;
final int vertexCount = line.getVertexCount();
for (int vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
final double x = line.getX(vertexIndex);
final double y = line.getY(vertexIndex);
if (axisCount == 2) {
ogrGeometry.AddPoint(x, y);
} else {
final double z = line.getZ(vertexIndex);
ogrGeometry.AddPoint(x, y, z);
}
}
break;
case 3:
case 0x80000000 + 3:
for (final LinearRing ring : ((Polygon) geometry).rings()) {
final org.gdal.ogr.Geometry ogrRing = toOgrGeometry(ring, 101, axisCount);
ogrGeometry.AddGeometry(ogrRing);
}
break;
case 4:
addParts(ogrGeometry, geometry, 1, axisCount);
break;
case 0x80000000 + 4:
addParts(ogrGeometry, geometry, 0x80000000 + 1, axisCount);
break;
case 5:
addParts(ogrGeometry, geometry, 2, axisCount);
break;
case 0x80000000 + 5:
addParts(ogrGeometry, geometry, 0x80000000 + 2, axisCount);
break;
case 6:
addParts(ogrGeometry, geometry, 3, axisCount);
break;
case 0x80000000 + 6:
addParts(ogrGeometry, geometry, 0x80000000 + 3, axisCount);
break;
// return this.geometryFactory.geometry(parts);
case 101:
for (final Vertex vertex : geometry.vertices()) {
final double x = vertex.getX();
final double y = vertex.getY();
if (axisCount == 2) {
ogrGeometry.AddPoint(x, y);
} else {
final double z = vertex.getZ();
ogrGeometry.AddPoint(x, y, z);
}
}
break;
default:
return null;
}
}
if (axisCount == 2) {
ogrGeometry.FlattenTo2D();
}
return ogrGeometry;
}
use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.
the class LineStringEditor method newPolygon.
public Polygon newPolygon() {
final LinearRing ring = newLinearRing();
final GeometryFactory geometryFactory = getGeometryFactory();
return geometryFactory.polygon(ring);
}
use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.
the class IndexedNestedRingTester method isNonNested.
public boolean isNonNested() {
buildIndex();
for (int i = 0; i < this.rings.size(); i++) {
final LinearRing innerRing = (LinearRing) this.rings.get(i);
final List results = this.index.getItems(innerRing.getBoundingBox());
// System.out.println(results.size());
for (int j = 0; j < results.size(); j++) {
final LinearRing searchRing = (LinearRing) results.get(j);
if (innerRing == searchRing) {
continue;
}
if (!innerRing.getBoundingBox().intersects(searchRing.getBoundingBox())) {
continue;
}
final Point innerRingPt = IsValidOp.findPtNotNode(innerRing, searchRing, this.graph);
/**
* If no non-node pts can be found, this means
* that the searchRing touches ALL of the innerRing vertices.
* This indicates an invalid polygon, since either
* the two holes Construct a new disconnected interior,
* or they touch in an infinite number of points
* (i.e. along a line segment).
* Both of these cases are caught by other tests,
* so it is safe to simply skip this situation here.
*/
if (innerRingPt == null) {
continue;
}
final boolean isInside = searchRing.isPointInRing(innerRingPt);
if (isInside) {
this.nestedPt = innerRingPt;
return false;
}
}
}
return true;
}
use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.
the class IndexedNestedRingTester method buildIndex.
private void buildIndex() {
this.index = new StrTree();
for (int i = 0; i < this.rings.size(); i++) {
final LinearRing ring = (LinearRing) this.rings.get(i);
final BoundingBox env = ring.getBoundingBox();
this.index.insertItem(env, ring);
}
}
use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.
the class IsValidOp method checkHolesInShell.
/**
* Tests that each hole is inside the polygon shell.
* This routine assumes that the holes have previously been tested
* to ensure that all vertices lie on the shell oon the same side of it
* (i.e that the hole rings do not cross the shell ring).
* In other words, this test is only correct if the ConsistentArea test is passed first.
* Given this, a simple point-in-polygon test of a single point in the hole can be used,
* provided the point is chosen such that it does not lie on the shell.
*
* @param polygon the polygon to be tested for hole inclusion
* @param graph a GeometryGraph incorporating the polygon
*/
private boolean checkHolesInShell(final Polygon polygon, final GeometryGraph graph) {
boolean valid = true;
final LinearRing shell = polygon.getShell();
final PointInRing pir = new MCPointInRing(shell);
for (final LinearRing hole : polygon.holes()) {
final Point holePt = findPtNotNode(hole, shell, graph);
/**
* If no non-node hole vertex can be found, the hole must
* split the polygon into disconnected interiors.
* This will be caught by a subsequent check.
*/
if (holePt != null) {
final boolean outside = !pir.isInside(holePt);
if (outside) {
valid = false;
addError(new TopologyValidationError(TopologyValidationError.HOLE_OUTSIDE_SHELL, holePt));
if (isErrorReturn()) {
return false;
}
}
}
}
return valid;
}
Aggregations