Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
share|improve this question
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 Jul 17 '12 at 12:22
    
thanks @Aaron but i need to work on open source on this project –  Sam007 Oct 25 '12 at 20:49
add comment

1 Answer

up vote 5 down vote accepted

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

gdal_polygonize.py myraster.tif -f "ESRI Shapefile" mylayer.shp

or to output directly 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

(ignore the "ERROR 1: No field definitions found for 'mylayer', is it a table?" message)

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

share|improve this answer
    
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 Jul 17 '12 at 0:27
    
@Sam007 yup, PostGIS output works too, see updated –  Mike T Jul 17 '12 at 3:22
    
Thanks @mike that is helpful –  Sam007 Jul 17 '12 at 16:20
    
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 Jul 17 '12 at 23:58
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 Oct 25 '12 at 22:00
show 10 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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