Divide a complex shapefile into a grid

I just ended up creating my own tools to do this.

I used the Clipper library (http://www.angusj.com/delphi/clipper.php) along with OGR to divide my data set up. Something to note is performing intersections naively with this lib takes very long, so I instead used a quadtree approach... ie, divide into four grid cells, divide each of those into four more, etc, until you get your desired resolution. The lib works great though, I've attached a screenshot showing the results on the eastern hemisphere:

enter image description here

The above result took about 4.5 hours on a 1.33GHz processor.

Here are the tools in case someone runs into a similar issue in the future. Please note that they're hacked together proof-of-concepts and you probably shouldn't use them directly (might serve as a good starting point for something though):

https://github.com/preet/scratch/tree/master/gis/polytoolkit

https://github.com/preet/scratch/tree/master/gis/shapefiles/shptk


It definitely sounds like you have geometry issues. It is unlikely that will be able yield clean results from a dirty input file regardless of the software used, unless you first address your geometry problems. Once you get your geometry issues sorted out, you could try the following if you are still having issues:

1) Make sure that your grid dataset has the same projection as your world polygon dataset. If not, recreate it in the proper projection.

2) Convert all features to single part - much easier to process

3) Remove all extraneous fields keeping only id field which will enable you to join your attributes back after the intersection has been performed - again much easier to process

4) Instead of intersecting the entire grid dataset with the entire world polygon dataset, try loop over your grid polygons, selecting the intersecting polygons in your world dataset and the performing a clip to based on your grid polygon. This will enable you to isolate any problems and in the end you can merge results together to achieve your original goal.

5) Try using larger grid polygons.