wdtinc / mapbox-vector-tile-java

Java Mapbox Vector Tile Library for Encoding/Decoding
Apache License 2.0
147 stars 73 forks source link

JtsAdapter calculate polygon area wrong #37

Open zxp209 opened 5 years ago

zxp209 commented 5 years ago

This's one of my data -----POLYGON ((116.378477 39.960438, 116.378312 39.960438, 116.378312 39.960344, 116.378371 39.960344, 116.378365 39.960303, 116.378347 39.960261, 116.378276 39.960261, 116.378276 39.96032, 116.377202 39.960297, 116.377205 39.960191, 116.378477 39.960197, 116.378477 39.960438))

I'd try to build my polygon with JtsAdapter.java

JtsLayer layer = new JtsLayer(layerName, geoms); JtsMvt mvt = new JtsMvt(singletonList(layer)); return MvtEncoder.encode(mvt);

But when I debug my code ,I found that final List<VectorTile.Tile.Feature> features JtsAdapter.toFeatures(layerGeoms, layerProps, userDataConverter); features's size is zero. So,I follow the JtsAdapter.java and I found

 // Area must be non-zero
                final double exteriorArea = CGAlgorithms.signedArea(exteriorRing.getCoordinates());
                if(((int) Math.round(exteriorArea)) == 0) {
                    continue;
                }

the result of area is negative,and decimal,like -0.0008944.So Math.round(-0.0008944) ==0 is true. Is a problem with that?

jts version is 1.13,
<dependency>
            <groupId>com.wdtinc</groupId>
            <artifactId>mapbox-vector-tile</artifactId>
            <version>2.0.0</version>
        </dependency>