use of com.revolsys.geometry.model.Polygon 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.Polygon in project com.revolsys.open by revolsys.
the class DistanceToPoint method computeDistance.
public static void computeDistance(final Geometry geom, final Point point, final PointPairDistance pointDistance) {
if (geom instanceof LineString) {
final LineString line = (LineString) geom;
computeDistance(line, point, pointDistance);
} else if (geom instanceof Polygon) {
final Polygon polygon = (Polygon) geom;
computeDistance(polygon, point, pointDistance);
} else if (geom.isGeometryCollection()) {
for (final Geometry part : geom.geometries()) {
computeDistance(part, point, pointDistance);
}
} else {
// assume geom is Point
pointDistance.setMinimum(geom.getPoint(), point);
}
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class MultiPolygonEditor method forEachPolygon.
@Override
public void forEachPolygon(final Consumer<Polygon> action) {
for (int i = 0; i < getGeometryCount(); i++) {
final Polygon polygon = getEditor(i);
action.accept(polygon);
}
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class WKTReader method readMultiPolygonText.
/**
* Creates a <code>MultiPolygon</code> using the next token in the stream.
*
*@param tokenizer tokenizer over a stream of text in Well-known Text
* format. The next tokens must form a <MultiPolygon Text>.
*@return a <code>MultiPolygon</code> specified by the next
* token in the stream, or if if the coordinates used to create the
* <code>Polygon</code> shells and holes do not form closed linestrings.
*@throws IOException if an I/O error occurs
*@throws ParseException if an unexpected token was encountered
*/
private Polygonal readMultiPolygonText() throws IOException, ParseException {
String nextToken = getNextEmptyOrOpener();
if (nextToken.equals(EMPTY)) {
return this.geometryFactory.polygonal(new Polygon[] {});
}
final ArrayList polygons = new ArrayList();
Polygon polygon = readPolygonText();
polygons.add(polygon);
nextToken = getNextCloserOrComma();
while (nextToken.equals(COMMA)) {
polygon = readPolygonText();
polygons.add(polygon);
nextToken = getNextCloserOrComma();
}
final Polygon[] array = new Polygon[polygons.size()];
return this.geometryFactory.polygonal((Polygon[]) polygons.toArray(array));
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class CascadedPolygonUnion method restrictToPolygons.
/**
* Computes a {@link Polygonal} containing only {@link Polygonal} components.
* Extracts the {@link Polygon}s from the input
* and returns them as an appropriate {@link Polygonal} geometry.
* <p>
* If the input is already <tt>Polygonal</tt>, it is returned unchanged.
* <p>
* A particular use case is to filter out non-polygonal components
* returned from an overlay operation.
*
* @param geometry the geometry to filter
* @return a Polygonal geometry
*/
private static Polygonal restrictToPolygons(final Geometry geometry) {
if (geometry instanceof Polygonal) {
return (Polygonal) geometry;
} else {
final List<Polygon> polygons = geometry.getGeometries(Polygon.class);
if (polygons.size() == 1) {
return polygons.get(0);
}
final GeometryFactory geometryFactory = geometry.getGeometryFactory();
return geometryFactory.polygonal(polygons);
}
}
Aggregations