BinaryTie
BinaryTie

Reputation: 301

turfjs unexpected shapes with polygon difference()

After difference() implementation for my polygon map, I find out, that when I zoom in map some unexpected shapes appear or disappear which shouldn't be there. There are MultyPolygon and Polygon type polygons and I compare them and even checking the length of polygon coordinates, but that didn't help.

let previousFeature = {}
let x    
for(x = 0;x < second_features.length; x++){
 if (x === 0) {
  previousFeature = second_features[x]
 } else {
 if (previousFeature.geometry.coordinates.length === 
  second_features[x].geometry.coordinates.length)
 {
  second_features[x - 1] = difference(previousFeature.geometry, second_features[x].geometry)
 }
  second_features[x - 1].properties.time_distance = previousFeature.properties.time_distance
  second_features[x - 1].properties.gid = previousFeature.properties.gid
  previousFeature = second_features[x]
}

Unexpected shape appears which crosses through polygons while doing zoom in and zoom out.

Upvotes: 4

Views: 664

Answers (1)

B--rian
B--rian

Reputation: 5880

I did find the the geographic location on OSM, but I did not manage to guess which kind of white lines and blue polygons you overlay onto this map. If you talk about "unexpected shape", I suppose you are referring to the dark-blue triangle which crosses through the white lines?

Some (general) guesses why polygons may look differently than expected:

  1. Could it be that you are observing an artifact of the rendering procedure? Some rendering procedures automatically simplify polygons by removing ever x-th supporting point, with x being larger the higher the zoom factor: In other words: For maximal zoom, no points are removed, when you zoom out a bit, more and more points of the polygon are removed. What could be the case is that you see only at maximal zoom level the real shape of the polygon.

  2. Maybe you did not close your polygon(s)? This also may lead to strange effects when rendering for some libraries.

Open Street Map Image

Further reading

Upvotes: 1

Related Questions