use of org.locationtech.jts.geom.Polygon in project yyl_example by Relucent.
the class JtsGeometryExample1 method main.
public static void main(String[] args) throws ParseException {
Polygon p = createCircle(0, 1, 2);
// 圆上所有的坐标(32个)
Coordinate[] coords = p.getCoordinates();
for (Coordinate coord : coords) {
System.out.println(coord.x + "," + coord.y);
}
}
use of org.locationtech.jts.geom.Polygon 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;
}
use of org.locationtech.jts.geom.Polygon in project yyl_example by Relucent.
the class JtsGeometryExample1 method createPolygonByWKT.
/**
* create a polygon(多边形) by WKT
* @return 多边形
* @throws ParseException
*/
public static Polygon createPolygonByWKT() throws ParseException {
WKTReader reader = new WKTReader(GEOMETRY_FACTORY);
Polygon polygon = (Polygon) reader.read("POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))");
return polygon;
}
use of org.locationtech.jts.geom.Polygon in project jena by apache.
the class GMLReaderTest method testExtractMultiSurface2.
/**
* Test of extract method, of class GMLReader.
*
* @throws org.jdom2.JDOMException
* @throws java.io.IOException
*/
@Test
public void testExtractMultiSurface2() throws JDOMException, IOException {
Polygon[] polygons = new Polygon[2];
polygons[0] = GEOMETRY_FACTORY.createPolygon(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "40 40, 20 45, 45 30, 40 40"));
LinearRing shell = GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "20 35, 10 30, 10 10, 30 5, 45 20, 20 35"));
LinearRing[] holes = new LinearRing[] { GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "30 20, 20 15, 20 25, 30 20")) };
polygons[1] = GEOMETRY_FACTORY.createPolygon(shell, holes);
Geometry geometry = GEOMETRY_FACTORY.createMultiPolygon(polygons);
GMLReader expResult = new GMLReader(geometry, 2, SRS_URI.OSGB36_CRS);
String gmlText = "<gml:MultiSurface xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:surfaceMember><gml:Polygon srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:exterior><gml:LinearRing><gml:posList>40 40 20 45 45 30 40 40</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember><gml:surfaceMember><gml:Polygon srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:exterior><gml:LinearRing><gml:posList>20 35 10 30 10 10 30 5 45 20 20 35</gml:posList></gml:LinearRing></gml:exterior><gml:interior><gml:LinearRing><gml:posList>30 20 20 15 20 25 30 20</gml:posList></gml:LinearRing></gml:interior></gml:Polygon></gml:surfaceMember></gml:MultiSurface>";
GMLReader result = GMLReader.extract(gmlText);
//
//
assertEquals(expResult, result);
}
use of org.locationtech.jts.geom.Polygon in project jena by apache.
the class WKTWriterTest method testWriteMultiPolygon2.
/**
* Test of write method, of class WKTWriter.
*/
@Test
public void testWriteMultiPolygon2() {
Polygon[] polygons = new Polygon[2];
polygons[0] = GEOMETRY_FACTORY.createPolygon(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "40 40 0 1, 20 45 0 1, 45 30 0 1, 40 40 0 1"));
LinearRing shell = GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "20 35 0 1, 10 30 0 1, 10 10 0 1, 30 5 0 1, 45 20 0 1, 20 35 0 1"));
LinearRing[] holes = new LinearRing[] { GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "30 20 0 1, 20 15 0 1, 20 25 0 1, 30 20 0 1")) };
polygons[1] = GEOMETRY_FACTORY.createPolygon(shell, holes);
Geometry geometry = GEOMETRY_FACTORY.createMultiPolygon(polygons);
GeometryWrapper geometryWrapper = new GeometryWrapper(geometry, SRS_URI.WGS84_CRS, WKTDatatype.URI, new DimensionInfo(4, 3, 2));
String expResult = "<" + SRS_URI.WGS84_CRS + "> MULTIPOLYGON ZM(((40 40 0 1, 20 45 0 1, 45 30 0 1, 40 40 0 1)), ((20 35 0 1, 10 30 0 1, 10 10 0 1, 30 5 0 1, 45 20 0 1, 20 35 0 1), (30 20 0 1, 20 15 0 1, 20 25 0 1, 30 20 0 1)))";
String result = WKTWriter.write(geometryWrapper);
//
//
assertEquals(expResult, result);
}
Aggregations