简体   繁体   English

使用带有参数capstyle flat的JTS BufferOP时点几何产生的Emty多边形结果

[英]Emty polygon result from point geometry while using JTS BufferOP with parameter capstyle flat

I am using geotools and the jts class BufferOP to create a buffer around my geometries. 我正在使用geotools和jts类BufferOP在我的几何周围创建缓冲区。 During tesdting I came along a weard result with point geometries. 在测试期间,我遇到了点几何形状的磨损结果。 If i set capstyle to flat, my result is always an emty polygon. 如果将capstyle设置为flat,则结果始终是emty多边形。

Lines and Polygons are working. 线和多边形正在工作。 Only points seems ti have this kind of issue. 似乎只有点有这种问题。

If i change it to round or square parameter, I get the expected result. 如果我将其更改为圆形或方形参数,则会得到预期的结果。

I am using geotools snapshot 21 with maven and Jave 8. here is the maven pom file snipped I've been using and the code example 我正在将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);
}

Does anyone know why? 有人知道为什么吗?

Having had a look at the code it seems to come down to how OffsetCurveBuilder handles the end caps. 看过代码后,似乎可以归结为OffsetCurveBuilder如何处理端盖。 It seems to (quite reasonably in my opinion) not calculate anything for flat end caps and since a point doesn't generate anything except ends you get nothing for a flat end cap. (在我看来,这很合理)似乎没有为平端盖计算任何东西,并且由于一点不会产生任何东西,除了端头,对于平端盖您什么也没有。

  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);
    }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM