我正在使用geotools和jts类BufferOP在我的几何周围创建一个缓冲区。在测试期间,我遇到了点几何形状的磨损结果。如果我将capstyle设置为flat,那么我的结果将始终是emty多边形。
线和面正在工作。似乎只有点有这种问题。
如果将其更改为圆形或方形参数,则会得到预期的结果。
我正在将geotools快照21与maven和Jave 8一起使用。 这是我一直在使用的Maven pom文件,以及代码示例
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<geotools.version>21-SNAPSHOT</geotools.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-geometry</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-hsql</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-wkt </artifactId>
<version>${geotools.version}</version>
</dependency>
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.geotools.referencing.CRS;
import org.geotools.util.factory.Hints;
import org.locationtech.jts.geom.*;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import org.locationtech.jts.operation.buffer.BufferOp;
import org.locationtech.jts.operation.buffer.BufferParameters;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.TransformException;
import java.io.IOException;
public class App
{
public static void main( String[] args ) throws ParseException, IOException, FactoryException, TransformException {
Integer epsg= 32632;
String wkt = "POINT (5293201.002716452 1208988.4067087262)";
//setup geometry point in utm coordinates (meter)
// create geometry
CoordinateReferenceSystem crs = CRS.decode(("EPSG:"+ epsg.toString()));
Hints hints = new Hints(Hints.CRS, crs);
GeometryFactory geometryFactoryWKT = JTSFactoryFinder.getGeometryFactory(hints);
WKTReader wktReader = new WKTReader(geometryFactoryWKT);
Geometry geom = wktReader.read(wkt);
geom.setSRID(epsg);
// creates BufferParameters
BufferParameters bufferParam = new BufferParameters();
bufferParam.setEndCapStyle(BufferParameters.CAP_FLAT);
// if using any other parameter result is as expected
// bufferParam.setEndCapStyle(BufferParameters.CAP_ROUND);
bufferParam.setJoinStyle(BufferParameters.JOIN_BEVEL );
bufferParam.setMitreLimit(5);
bufferParam.setSimplifyFactor(0.01);
bufferParam.setQuadrantSegments(8);
// creates buffer geom on point with 10m distance and use set bufferParameters
Geometry bufferGeom = BufferOp.bufferOp(geom ,10, bufferParam);
System.out.println(bufferGeom);
}
有人知道为什么吗?
答案 0 :(得分:0)
看过代码,似乎可以归结为OffsetCurveBuilder如何处理端盖。 (在我看来,这很合理)似乎没有为平端盖计算任何东西,并且由于一点不会产生任何东西,除了端头,对于平端盖您什么也没有。
private void computePointCurve(Coordinate pt, OffsetSegmentGenerator segGen) {
switch (bufParams.getEndCapStyle()) {
case BufferParameters.CAP_ROUND:
segGen.createCircle(pt);
break;
case BufferParameters.CAP_SQUARE:
segGen.createSquare(pt);
break;
// otherwise curve is empty (e.g. for a butt cap);
}
}