使用带有参数 capstyle flat 的 JTS BufferOP 时,点几何产生空多边形
Emty polygon result from point geometry while using JTS BufferOP with parameter capstyle flat
我正在使用 geotools 和 jts class BufferOP 在我的几何图形周围创建一个缓冲区。在测试过程中,我得到了一个带有点几何形状的磨损结果。如果我将 capstyle 设置为 flat,我的结果总是一个空的多边形。
线条和多边形正在运行。只有点似乎有这种问题。
如果我将其更改为圆形或方形参数,我会得到预期的结果。
我在 Maven 和 Jave 8 中使用 geotools 快照 21。
这是我一直在使用的 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);
}
有人知道为什么吗?
查看代码后,似乎归结为 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);
}
}
我正在使用 geotools 和 jts class BufferOP 在我的几何图形周围创建一个缓冲区。在测试过程中,我得到了一个带有点几何形状的磨损结果。如果我将 capstyle 设置为 flat,我的结果总是一个空的多边形。
线条和多边形正在运行。只有点似乎有这种问题。
如果我将其更改为圆形或方形参数,我会得到预期的结果。
我在 Maven 和 Jave 8 中使用 geotools 快照 21。 这是我一直在使用的 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);
}
有人知道为什么吗?
查看代码后,似乎归结为 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);
}
}