10

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.

3
  • 2
    In ArcGIS the operation you are describing is known as an Erase. It sounds like you are seeking an open source solution so maybe searching on that term will turn something up. MapWindow looks like it has an Erase tool but discussion here suggests it too may have limitations: mapwindow.org/phorum/read.php?4,20317
    – PolyGeo
    Mar 18, 2012 at 9:13
  • 2
    You will want to split up your shapefile "polygon with world bounds (-180 to 180, -90 to 90)" into smaller chunks. Then you can clip out the areas. You are experiencing two probable issues, one is that you're processing data on both the northern hemisphere and the southern hemisphere at the same time. Two, potential issues with the -180/180 bounds. Try splitting up your world bounds into 4 smaller chunks such as: Top left, Top right, Bottom left, Bottom right, of the world. Jul 24, 2012 at 16:33
  • I assume, when you created your world polygon that you projected it into the same system as the land data?
    – djq
    Oct 12, 2012 at 17:54

5 Answers 5

6

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

1

SAGA GIS (and many others probably also) has a command called "polygon intersection". Create a polygon containing the whole world and substract your land polygons from it. So method 2 or 3 in that library.

Usage: saga_cmd libshapes_polygons "Polygon Intersection" -SHAPES_A <str> [-FIELD_A <str>] -SHAPES_B <str> [-FIELD_B <str>] -SHAPES_AB <str> [-METHOD <str>] [-SPLITPARTS]
  -SHAPES_A:<str>   Layer A
    Shapes (input)
  -FIELD_A:<str>    Attribute A
    Table field
  -SHAPES_B:<str>   Layer B
    Shapes (input)
  -FIELD_B:<str>    Attribute B
    Table field
  -SHAPES_AB:<str>  Intersection
    Shapes (output)
  -METHOD:<str>     Method
    Choice
    Available Choices:
    [0] Complete Intersection
    [1] Intersection
    [2] Difference (A - B)
    [3] Difference (B - A)
  -SPLITPARTS       Split Parts
    Boolean
0

A raster might be too data-heavy if you need detail on the coast lines. The same principle as that suggested by spatialthoughts but using a Delaunay TIN might be an option?

0

these shapefiles might be beneficial. They are from the ESRI Mapping Center and contain pretty accurate hydrological and marine feature data.

0

I have not had much success with inverting OSM land shapefiles due to their complexity, however its possible to generate both land and ocean shapefiles from the raw OSM data. http://openstreetmapdata.com/data offers downloads of both which I find extremely useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.