[GIS] How to get an ocean shapefile from a very detailed land area shapefile

clippolygonshapefile

I am looking for a possibility to "invert" a shapefile. What I want to do is to convert a shapefile with the continents and islands into a shapefile that has water polygons. The existing ocean shapefile from Natural Earth is too inaccurate.

As an active OSM contributor, I thought using the existing shapefiles from OSM would be fine for me. These are much more accurate but very buggy from a GIS perspective. However, mapserver can deal with it so I thought these should be fine. These shapefiles, some of them you can find here
http://metro.teczno.com/#coastline
are very large.

I have created a shapefile with one polygon with world bounds (-180 to 180, -90 to 90). Then I have tried to clip out the areas from my world bounds shapefile where land areas are in the other shapefile. I tried it with QGIS, vector tools -> difference function.
After 12 hours with 100% CPU usage, I stopped it. It always displayed a progress of 100%. RAM was not an issue.

I am looking for another possibility to clip out the land areas from a "world polygon", preferably Linux command line.

Best Answer

Rasters to the rescue! You can do this operation by converting your shapefile to a raster, doing the 'invert' operation and convert it back to vector

  • Raster -> Convert -> Rasterize. Output layer raster1
  • Open field calculator, enter expression raster1@1 = 0
  • Raster -> Convert -> Polygonize, Output layer ocean_polygons
  • Open Attribute table, search for DN = 0, toggle editing, delete selected features and save. What you will be left with will be polygons for the ocean areas.

enter image description here