本文整理了Java中org.geotools.geometry.jts.JTS.toGeometry()
方法的一些代码示例,展示了JTS.toGeometry()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTS.toGeometry()
方法的具体详情如下:
包路径:org.geotools.geometry.jts.JTS
类名称:JTS
方法名:toGeometry
[英]Converts an envelope to a polygon.
The resulting polygon contains an outer ring with verticies: (x1,y1),(x2,y1),(x2,y2),(x1,y2),(x1,y1)
[中]将封套转换为多边形。
生成的多边形包含一个具有垂直方向的外圈:(x1,y1)、(x2,y1)、(x2,y2)、(x1,y2)、(x1,y1)
代码示例来源:origin: geoserver/geoserver
JTS.toGeometry((Envelope) new ReferencedEnvelope(grid.getEnvelope2D()));
if (coverageBounds.intersects(rasterFilter)) {
final ParameterValueGroup param = cropParams.clone();
代码示例来源:origin: geoserver/geoserver
/**
* Crops the coverage to the specified bounds
*
* @param coverage
* @param bounds
*/
public static GridCoverage2D crop(final GridCoverage2D coverage, final Envelope bounds) {
// checks
final ReferencedEnvelope cropBounds = new ReferencedEnvelope(bounds);
final ReferencedEnvelope coverageBounds = new ReferencedEnvelope(coverage.getEnvelope());
if (cropBounds.contains((org.locationtech.jts.geom.Envelope) coverageBounds)) {
return coverage;
}
Polygon polygon = JTS.toGeometry(cropBounds);
Geometry roi = polygon.getFactory().createMultiPolygon(new Polygon[] {polygon});
// perform the crops
final ParameterValueGroup param = PROCESSOR.getOperation("CoverageCrop").getParameters();
param.parameter("Source").setValue(coverage);
param.parameter("Envelope").setValue(bounds);
param.parameter("ROI").setValue(roi);
return (GridCoverage2D) PROCESSOR.doOperation(param);
}
代码示例来源:origin: geotools/geotools
/**
* Create a Point from a ISO Geometry DirectPosition.
*
* @param position
* @return Point
*/
public static Point toGeometry(DirectPosition position) {
return toGeometry(position, null);
}
代码示例来源:origin: geotools/geotools
/**
* Converts an arbitrary Java2D shape into a JTS geometry. The created JTS geometry may be any
* of {@link LineString}, {@link LinearRing} or {@link MultiLineString}.
*
* @param shape The Java2D shape to create.
* @param factory The JTS factory to use for creating geometry.
* @return The JTS geometry.
* @deprecated Please use {@link #toGeometry(Shape)} or {@link #toGeometry(Shape,
* GeometryFactory)}
*/
public static Geometry shapeToGeometry(final Shape shape, final GeometryFactory factory) {
return toGeometry(shape, factory);
}
代码示例来源:origin: geotools/geotools
/**
* Converts an arbitrary Java2D shape into a JTS geometry. The created JTS geometry may be any
* of {@link LineString}, {@link LinearRing} or {@link MultiLineString}.
*
* @param shape the input shape
* @return A new JTS geometry instance
* @throws IllegalArgumentException if {@code shape} is {@code null}
*/
public static Geometry toGeometry(final Shape shape) {
return toGeometry(shape, new GeometryFactory());
}
代码示例来源:origin: geotools/geotools
/**
* Converts a {@link ReferencedEnvelope} to a JTS polygon.
*
* <p>The resulting polygon contains an outer ring with vertices:
* (x1,y1),(x2,y1),(x2,y2),(x1,y2),(x1,y1)
*
* @param envelope The original envelope.
* @return The envelope as a polygon.
* @throws IllegalArgumentException if {@code bbox} is {@code null}
* @since 2.4
*/
public static Polygon toGeometry(ReferencedEnvelope bbox) {
return toGeometry((BoundingBox) bbox, new GeometryFactory());
}
代码示例来源:origin: geotools/geotools
/**
* Converts a {@link BoundingBox} to a JTS polygon.
*
* <p>The resulting polygon contains an outer ring with vertices:
* (x1,y1),(x2,y1),(x2,y2),(x1,y2),(x1,y1)
*
* @param envelope The original envelope.
* @return The envelope as a polygon.
* @throws IllegalArgumentException if {@code bbox} is {@code null}
* @since 2.4
*/
public static Polygon toGeometry(BoundingBox bbox) {
return toGeometry(bbox, new GeometryFactory());
}
代码示例来源:origin: geotools/geotools
private void setRoiProvider() throws IOException {
Geometry granuleGeometry = JTS.toGeometry(new ReferencedEnvelope(originalEnvelope));
roiProvider =
MultiLevelROIProviderFactory.createFootprintProvider(inputFile, granuleGeometry);
if (roiProvider != null) {
multiLevelRoi = roiProvider.getMultiScaleROI(null);
}
}
代码示例来源:origin: geotools/geotools
@Override
public Object evaluate(Object object) {
if (!(object instanceof Feature)) {
return null;
}
Feature feature = (Feature) object;
ReferencedEnvelope env = ReferencedEnvelope.reference(feature.getBounds());
if (env != null) {
return JTS.toGeometry(env);
} else {
return null;
}
}
}
代码示例来源:origin: geotools/geotools
public MultiLevelROIRaster(DatasetLayout layout, File file, SimpleFeature sf)
throws IOException {
// Initialization
this.file = file;
// Getting Feature Geometry
Geometry geo = (Geometry) sf.getDefaultGeometry();
// Getting as envelope
env = JTS.toEnvelope(geo);
// Save envelope as Geometry
footprint = JTS.toGeometry(env);
// Getting the Mask provider
maskOvrProvider = new MaskOverviewProvider(layout, file);
}
代码示例来源:origin: geotools/geotools
private Geometry clipToWorldFeatureTypeGeometry(Geometry geom) {
// Oracle cannot deal with filters using geometries that span beyond the whole world
if (isFeatureTypeGeometryGeodetic() && !WORLD.contains(geom.getEnvelopeInternal())) {
Geometry result = geom.intersection(JTS.toGeometry(WORLD));
if (result != null && !result.isEmpty()) {
if (result instanceof GeometryCollection) {
result = distillSameTypeGeometries((GeometryCollection) result, geom);
}
return result;
}
}
return geom;
}
代码示例来源:origin: geotools/geotools
/** Try and Filter by the provided bbox, will default to Filter.EXCLUDE if null */
public static Filter filterBBox(Envelope bBox, SimpleFeatureType ft)
throws FactoryRegistryException, IllegalFilterException {
if (bBox == null) {
return Filter.INCLUDE;
}
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
PropertyName geomExpr = ff.property(ft.getGeometryDescriptor().getLocalName());
Literal bboxExpr = ff.literal(JTS.toGeometry(bBox));
Disjoint disjointFilter = ff.disjoint(geomExpr, bboxExpr);
return ff.not(disjointFilter);
}
}
代码示例来源:origin: geotools/geotools
@Test
public void testCutGeometryLambertConformal() throws Exception {
// get a lambert conformal conic with
ReferencedEnvelope wgs84South = new ReferencedEnvelope(-180, -90, -40, 0, WGS84);
ReferencedEnvelope laeSouth = wgs84South.transform(CRS.decode("EPSG:2194"), true);
ProjectionHandler handler = ProjectionHandlerFinder.getHandler(laeSouth, WGS84, true);
// a Geometry that crosses the opposite of the central meridian
Polygon geometry = JTS.toGeometry(new Envelope(5, 15, 0, 10));
Geometry preProcessed = handler.preProcess(geometry);
assertTrue(
"Should have sliced the geometry in two parts",
preProcessed instanceof MultiPolygon);
}
代码示例来源:origin: geotools/geotools
@Test
public void testToGeoemtry() {
DefaultGeographicCRS crs = DefaultGeographicCRS.WGS84;
// straight up
Polygon polygon = JTS.toGeometry(new Envelope(-10, 10, -10, 10));
assertEquals(5, polygon.getExteriorRing().getCoordinateSequence().size());
// bounding box
polygon = JTS.toGeometry((BoundingBox) new ReferencedEnvelope(-10, 10, -10, 10, crs));
assertEquals(5, polygon.getExteriorRing().getCoordinateSequence().size());
}
代码示例来源:origin: geotools/geotools
private LineString circleArcInBounds(
double x, double y, double radius, ReferencedEnvelope bounds) {
Point center = gf.createPoint(new Coordinate(x, y));
Polygon buffered = (Polygon) center.buffer(radius, 64);
Polygon mask = JTS.toGeometry(bounds);
Geometry intersection = buffered.getExteriorRing().intersection(mask);
return (LineString) intersection;
}
代码示例来源:origin: geotools/geotools
public void testBoundedBy() {
Geometry box = JTS.toGeometry(new Envelope(0, 10, 0, 10));
Intersects intersects = fac.intersects(fac.function("boundedBy"), fac.literal(box));
assertTrue(intersects.evaluate(testFeature));
}
}
代码示例来源:origin: geotools/geotools
@Test
public void toGeometry_Shape_Poly() {
Shape shape = new java.awt.Polygon(XPOINTS, YPOINTS, NPOINTS);
Geometry geom = JTS.toGeometry(shape);
assertTrue(geom instanceof LinearRing);
Coordinate[] coords = geom.getCoordinates();
assertEquals(NPOINTS + 1, coords.length);
CoordList list = new CoordList(coords);
Coordinate c = new Coordinate();
for (int i = 0; i < NPOINTS; i++) {
c.x = XPOINTS[i];
c.y = YPOINTS[i];
assertTrue(list.contains(c));
}
}
代码示例来源:origin: geotools/geotools
@Test
public void toGeometry_BoundingBox() {
BoundingBox bbox = new ReferencedEnvelope(-10, 10, -5, 5, null);
Geometry geom = JTS.toGeometry(bbox);
assertTrue(geom instanceof org.locationtech.jts.geom.Polygon);
Envelope geomEnv = geom.getEnvelopeInternal();
assertEquals(-10.0, geomEnv.getMinX(), TOL);
assertEquals(10.0, geomEnv.getMaxX(), TOL);
assertEquals(-5.0, geomEnv.getMinY(), TOL);
assertEquals(5.0, geomEnv.getMaxY(), TOL);
}
代码示例来源:origin: geotools/geotools
@Test
public void toGeometry_ReferencedEnvelope() {
ReferencedEnvelope refEnv =
new ReferencedEnvelope(-10, 10, -5, 5, DefaultGeographicCRS.WGS84);
Geometry geom = JTS.toGeometry(refEnv);
assertTrue(geom instanceof org.locationtech.jts.geom.Polygon);
Envelope geomEnv = geom.getEnvelopeInternal();
assertEquals(-10.0, geomEnv.getMinX(), TOL);
assertEquals(10.0, geomEnv.getMaxX(), TOL);
assertEquals(-5.0, geomEnv.getMinY(), TOL);
assertEquals(5.0, geomEnv.getMaxY(), TOL);
}
代码示例来源:origin: geotools/geotools
@Test
public void toGeometry_Envelope() {
Envelope refEnv = new Envelope(-10, 10, -5, 5);
Geometry geom = JTS.toGeometry(refEnv);
assertTrue(geom instanceof org.locationtech.jts.geom.Polygon);
Envelope geomEnv = geom.getEnvelopeInternal();
assertEquals(-10.0, geomEnv.getMinX(), TOL);
assertEquals(10.0, geomEnv.getMaxX(), TOL);
assertEquals(-5.0, geomEnv.getMinY(), TOL);
assertEquals(5.0, geomEnv.getMaxY(), TOL);
}
内容来源于网络,如有侵权,请联系作者删除!