I am trying to convert a raster data to polygon data. Previously I was using the shapefile.py to create point data on individual lat/lon on the raster. But that will create a Huge data and querying it will be a Big issue.

So, it would be better if I am able to convert the raster data into a polygon data. I was able to find SAGA, but it seems that it can only convert the .grd files. Is there a way to convert GeoTIFF format or raster datasets in general to Polygon?

UPDATE: Using gdal_polygonize.py

I am executing the following line of code,

gdal_polygonize.py ~/development/Biodiversity/biodiversity/GeoTIFF/bio11.tif -f "ESRI Shapefile" bio11.shp

But I am getting the following error. My gdal version is 1.9.0.

Traceback (most recent call last):
  File "/usr/bin/gdal_polygonize.py", line 34, in <module>
    import gdal, ogr, osr
  File "/usr/lib/python2.7/dist-packages/gdal.py", line 2, in <module>
    from osgeo.gdal import deprecation_warn
  File "/usr/lib/python2.7/dist-packages/osgeo/__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "/usr/lib/python2.7/dist-packages/osgeo/__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: libjvm.so: cannot open shared object file: No such file or directory
  • 1
    If you are doing land classification with tiffs, check out the link (gis.stackexchange.com/q/29570/8104) where there's a method to convert tiffs to polygons using unsupervised maximum likelihood classification.
    – Aaron
    Commented Jul 17, 2012 at 12:22
  • thanks @Aaron but i need to work on open source on this project
    – Sam007
    Commented Oct 25, 2012 at 20:49
  • is there a way to convert 200 tifs at once?
    – Benjo
    Commented Apr 3, 2018 at 15:44

1 Answer 1


Try gdal_polygonize.py. E.g., to create a Shapefile mylayer.shp from input myraster.tif:

gdal_polygonize.py myraster.tif mylayer.shp

If you need to write to a specific format/driver use (e.g.) -f PostgreSQL to write to to a PostGIS database (see the PostgreSQL / PostGIS driver details for GDAL):

gdal_polygonize.py myraster.tif -f PostgreSQL PG:"dbname='postgis' user='postgres'" mylayer

There are Python bindings underneath to GDALPolygonize, if you need this tool customized.

  • Thanks Mike. Let me try it out. Also, rather than output it as shapefile, can I directly assign this into the PostGIS and access it from the Geoserver.
    – Sam007
    Commented Jul 17, 2012 at 0:27
  • @Sam007 yup, PostGIS output works too, see updated
    – Mike T
    Commented Jul 17, 2012 at 3:22
  • Got this error why creating the shapefile. Did not add to postgis database. dpaste.de/L8tSK Is it a problem if the GeoTIFF is in another dir?
    – Sam007
    Commented Jul 17, 2012 at 23:58
  • That looks like a distracting error, related to the SWIG bindings used by Python. Which version of GDAL do you have, and how did you install it?
    – Mike T
    Commented Jul 18, 2012 at 0:45
  • 1
    @Sam007 Try sudo apt-get install python-gdal, but if that doesn't work, then yes post a new question. I still haven't got around to testing how it works or not with OpenGeo.
    – Mike T
    Commented Oct 25, 2012 at 22:00

Your Answer

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

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