-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Visibility graphs have a huge number of polygon crossings #48
Comments
Just to add some extra details, Can the fact that this is a very high res, zoomed in region (compared to the globe-trotting example scripts) affect it? The coordinates are just not very different from point to point --> float errors? |
I was able to come up with a work-around. The coastlines shapefile worked and so did my own hand-drawn test file in QGIS worked. The only one that didn't work was a raster converted to a shapefile. So I pulled up my raster->shapefile in QGIS, redrew a less "blocky" shapefile on top (still complex with lots of points). I input this new version and it had only about 5 polygon-crossings. But after rounding and normalizing the coordinates, there were no edge crossings. Conclusion? The blockiness of a converted raster does not play well with the VG generation. Ultimately my pipeline will be automatically converting rasters to polygons for this, but I should be apply to smooth them a bit in the code. |
Yeah this is likely rounding issues when you have a large amount of vertices that are very close to each other. Reducing the number of vertices is the best fix, as well as scaling like you did. |
Hi Ekrell. Did you already happen to find a nice solution to this? The final image seems to have no crossing but also has a high resolution. Was it just a story of finding the right scaling factor and smoothing factor? Also, did you scale it in pyvisgraph? Thanks in advance :) |
Hello SteynJanus, Sure enough, my solution was just to apply a little bit of smoothing to the polygons. You can see the full code here where I build the shapes (some very rough code made for a class project....): And the exact line is here (101): shape_ = shape_.simplify(0.0005, preserve_topology=False) This resolution turned out fine for my needs. Hope this helps :) |
@eagerbeaver04 this is likely due to floating point representation issues as your coordiate system uses quite large numbers. take a look at this documentation and try reducing |
I am trying to create a visibility graph from a shapefile, following the examples.
The example programs run fine, and I am able to get a correct path.
For my own shapefile, the visibility graph seem to never avoid crossing the polygons. So solution paths always cross a polygon if a polygon exists between them.
Here is my original map, plotting the polygons with matplotlitb.

For faster debugging, I made a reduced shapefile with only two polygons.
Here, I plotted all the edges in
graph.visgraph.get_edges()
. You can also see the solution path passing through the polygon.Any idea what might cause this? Happy to share code if it helps.
The code starts by converting a raster to polygons with fiona, saving them as a shapefile, then following example 1. Not too experienced with geospatial data, so I could have made an error here. But the polygons load fine in QGIS.
The text was updated successfully, but these errors were encountered: