[Gdal-dev] Raster to vector conversion (polygons) script

Ari Jolma ari.jolma at tkk.fi
Thu May 25 18:00:51 EDT 2006


Hello,

I needed to make polygons from a raster but could not find either an 
algorithm nor usable software from the net, so I made one up myself. 
This one uses GDAL and OGR and their Perl interface. The script is on my 
examples page: http://map.hut.fi/PerlForGeoinformatics/examples.html

The script first creates a data structure of the polygons in the raster 
by going through it once scanline by scanline. Then the border of each 
polygon is travelled and at the same time the outline of the polygon is 
stored. Then each outline is stored as a polygon into an OGR layer.

The algorithm uses 8-connectedness but that could be changed to 
4-connectedness quite easily. The "travelling the border and create 
outline" algorithm is a bit cumbersome but I've used the border 
traversal quite a bit, so it should be ok. Vectorizing large and complex 
rasters may require quite a lot of memory. All areas in the raster are 
stored as simple polygons, i.e., "holes" are not treated in any special 
way, they end up as separate polygons into the layer. Projections are 
not considered much. etc...

Let me know about bugs and possible enhancements.

Ari




More information about the Gdal-dev mailing list