use of org.locationtech.jts.geom.LinearRing in project arctic-sea by 52North.
the class GeoJSONDecoder method decodePolygonCoordinates.
protected Polygon decodePolygonCoordinates(JsonNode coordinates, GeometryFactory fac) throws GeoJSONDecodingException {
if (!coordinates.isArray()) {
throw new GeoJSONDecodingException(EXPECTED_ARRAY);
}
if (coordinates.size() < 1) {
throw new GeoJSONDecodingException("missing polygon shell");
}
LinearRing shell = fac.createLinearRing(decodeCoordinates(coordinates.get(0)));
LinearRing[] holes = new LinearRing[coordinates.size() - 1];
for (int i = 1; i < coordinates.size(); ++i) {
holes[i - 1] = fac.createLinearRing(decodeCoordinates(coordinates.get(i)));
}
return fac.createPolygon(shell, holes);
}
use of org.locationtech.jts.geom.LinearRing in project arctic-sea by 52North.
the class JTSHelperTest method shouldReverseGeometryCollection.
@Test
public void shouldReverseGeometryCollection() throws OwsExceptionReport {
final GeometryFactory factory = getGeometryFactoryForSRID(4326);
testReverse(factory.createGeometryCollection(new Geometry[] { factory.createMultiPolygon(new Polygon[] { factory.createPolygon(factory.createLinearRing(randomCoordinateRing(13)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(130)), factory.createLinearRing(randomCoordinateRing(4121)), factory.createLinearRing(randomCoordinateRing(12)) }), factory.createPolygon(factory.createLinearRing(randomCoordinateRing(8)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(1101)), factory.createLinearRing(randomCoordinateRing(413)), factory.createLinearRing(randomCoordinateRing(123)) }), factory.createPolygon(factory.createLinearRing(randomCoordinateRing(89)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(112)), factory.createLinearRing(randomCoordinateRing(4)), factory.createLinearRing(randomCoordinateRing(43)) }) }), factory.createMultiLineString(new LineString[] { factory.createLineString(randomCoordinateRing(21)), factory.createLineString(randomCoordinateRing(21)), factory.createLineString(randomCoordinateRing(15)) }), factory.createPolygon(factory.createLinearRing(randomCoordinateRing(10)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(10)), factory.createLinearRing(randomCoordinateRing(41)), factory.createLinearRing(randomCoordinateRing(13)) }), getGeometryFactoryForSRID(4326).createLineString(randomCoordinates(10)), getGeometryFactoryForSRID(4326).createLineString(randomCoordinates(10)) }));
}
use of org.locationtech.jts.geom.LinearRing in project arctic-sea by 52North.
the class JTSHelperTest method shouldReversePolygon.
@Test
public void shouldReversePolygon() throws OwsExceptionReport {
final GeometryFactory factory = getGeometryFactoryForSRID(4326);
testReverse(factory.createPolygon(factory.createLinearRing(randomCoordinateRing(10)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(10)), factory.createLinearRing(randomCoordinateRing(41)), factory.createLinearRing(randomCoordinateRing(13)) }));
}
use of org.locationtech.jts.geom.LinearRing in project arctic-sea by 52North.
the class GeoJSONTest method randomLinearRing.
private LinearRing randomLinearRing(int srid) {
Coordinate p = randomCoordinate();
LinearRing geometry = geometryFactory.createLinearRing(new Coordinate[] { p, randomCoordinate(), randomCoordinate(), randomCoordinate(), p });
geometry.setSRID(srid);
return geometry;
}
use of org.locationtech.jts.geom.LinearRing in project yyl_example by Relucent.
the class JtsGeometryExample1 method createCircle.
/**
* create a Circle 创建一个圆,圆心(x,y) 半径RADIUS
* @param x 圆心X坐标
* @param y 圆心X坐标
* @param RADIUS 半径
* @return 圆
*/
public static Polygon createCircle(double x, double y, final double RADIUS) {
// 圆上面的点个数
final int SIDES = 32;
Coordinate[] coords = new Coordinate[SIDES + 1];
for (int i = 0; i < SIDES; i++) {
double angle = ((double) i / (double) SIDES) * Math.PI * 2.0;
double dx = Math.cos(angle) * RADIUS;
double dy = Math.sin(angle) * RADIUS;
coords[i] = new Coordinate((double) x + dx, (double) y + dy);
}
coords[SIDES] = coords[0];
LinearRing ring = GEOMETRY_FACTORY.createLinearRing(coords);
Polygon polygon = GEOMETRY_FACTORY.createPolygon(ring, null);
return polygon;
}
Aggregations