use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class UnaryUnionOp method union.
/**
* Computes the geometric union of a {@link Collection}
* of {@link Geometry}s.
*
* If no input geometries were provided but a {@link GeometryFactory} was provided,
* an empty {@link Geometry} is returned.
*
* @param geoms a collection of geometries
* @param geometryFactory the geometry factory to use if the collection is empty
* @return the union of the geometries,
* or an empty GEOMETRYCOLLECTION
*/
public static Geometry union(final Collection<? extends Geometry> geometries, GeometryFactory geometryFactory) {
final List<Point> points = new ArrayList<>();
final List<LineString> lines = new ArrayList<>();
final List<Polygon> polygons = new ArrayList<>();
for (final Geometry geometry : geometries) {
if (geometryFactory == null) {
geometryFactory = geometry.getGeometryFactory();
}
points.addAll(geometry.getGeometries(Point.class));
lines.addAll(geometry.getGeometries(LineString.class));
polygons.addAll(geometry.getGeometries(Polygon.class));
}
return union(geometryFactory, points, lines, polygons);
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class GeometricShapeFactory method newEllipse.
/**
* Creates an elliptical {@link Polygon}.
* If the supplied envelope is square the
* result will be a circle.
*
* @return an ellipse or circle
*/
public Polygon newEllipse() {
final BoundingBox env = this.dim.getEnvelope();
final double xRadius = env.getWidth() / 2.0;
final double yRadius = env.getHeight() / 2.0;
final double centreX = env.getMinX() + xRadius;
final double centreY = env.getMinY() + yRadius;
final double[] coordinates = new double[(this.vertexCount + 1) * 2];
int coordinateIndex = 0;
for (int i = 0; i < this.vertexCount; i++) {
final double ang = i * (2 * Math.PI / this.vertexCount);
final double x = xRadius * Math.cos(ang) + centreX;
final double y = yRadius * Math.sin(ang) + centreY;
coordinates[coordinateIndex++] = x;
coordinates[coordinateIndex++] = y;
}
coordinates[coordinateIndex++] = 0;
coordinates[coordinateIndex++] = 1;
final Polygon poly = this.geomFact.polygon(2, coordinates);
return poly;
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class GeometryTestUtil method multiPolygon.
public static Polygonal multiPolygon(final GeometryFactory geometryFactory, final int axisCount, final int partCount, final int ringCount) {
final Polygon[] polygons = new Polygon[partCount];
for (int partIndex = 0; partIndex < partCount; partIndex++) {
polygons[partIndex] = polygon(geometryFactory, axisCount, partIndex, ringCount);
}
final Polygonal multiPolygon = geometryFactory.polygonal(polygons);
return multiPolygon;
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class GeoJsonGeometryReader method readMultiPolygon.
private Geometry readMultiPolygon(final boolean cogo) {
final List<Polygon> polygons = new ArrayList<>();
List<List<LineString>> polygonRings = null;
GeometryFactory factory = this.geometryFactory;
do {
final JsonParser parser = this.in;
final String fieldName = parser.skipToNextAttribute();
if (GeoJson.COORDINATES.equals(fieldName)) {
polygonRings = readCoordinatesListListList(cogo);
} else if (GeoJson.CRS.equals(fieldName)) {
factory = readCoordinateSystem();
}
} while (this.in.getEvent() != EventType.endObject && this.in.getEvent() != EventType.endDocument);
int axisCount = 2;
if (polygonRings != null) {
for (final List<LineString> rings : polygonRings) {
for (final LineString points : rings) {
axisCount = Math.max(axisCount, points.getAxisCount());
}
factory = factory.convertAxisCount(axisCount);
final Polygon polygon = factory.polygon(rings);
polygons.add(polygon);
}
}
return factory.polygonal(polygons);
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class GeoJsonRecordWriter method geometry.
private void geometry(final Geometry geometry) {
this.out.startObject();
if (geometry instanceof Point) {
final Point point = (Point) geometry;
point(point);
} else if (geometry instanceof LineString) {
final LineString line = (LineString) geometry;
line(line);
} else if (geometry instanceof Polygon) {
final Polygon polygon = (Polygon) geometry;
polygon(polygon);
} else if (geometry instanceof Punctual) {
final Punctual punctual = (Punctual) geometry;
multiPoint(punctual);
} else if (geometry instanceof Lineal) {
final Lineal lineal = (Lineal) geometry;
multiLineString(lineal);
} else if (geometry instanceof Polygonal) {
final Polygonal polygonal = (Polygonal) geometry;
multiPolygon(polygonal);
} else if (geometry.isGeometryCollection()) {
geometryCollection(geometry);
}
this.out.endObject();
}
Aggregations