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

Aaron Racicot aaronr at ecotrust.org
Thu May 25 18:33:14 EDT 2006


Hi there Ari,

Very cool...

Another option is to just do the following in grass:

r.in.gdal input=input_rast output=grass_rast
r.to.vect input=grass_rast output=grass_vect feature=area
v.out.ogr input=grass_vect type=area dsn=out_dir olayer=out_name
format=[ANY OGR FORMAT] 

You can see the documentation for r.to.vect at the following address to
see if will do what you are after (or compare notes on methods used):

http://grass.itc.it/grass61/manuals/html61_user/r.to.vect.html

Aaron

+----------------------------------------+
| Aaron Racicot  | aaronr at ecotrust.org   |
| GIS Programmer | 503.467.0759          |
+----------------------------------------+
| e c o t r u s t                        |
| Jean Vollum Natural Capital Center     |
| 721 NW Ninth Avenue                    |
| Suite 200                              |
| Portland, OR 97209                     |
| www.ecotrust.org                       |
+----------------------------------------+


-----Original Message-----
From: gdal-dev-bounces at lists.maptools.org
[mailto:gdal-dev-bounces at lists.maptools.org] On Behalf Of Ari Jolma
Sent: Thursday, May 25, 2006 3:01 PM
To: gdal-dev at lists.maptools.org
Subject: [Gdal-dev] Raster to vector conversion (polygons) script


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

_______________________________________________
Gdal-dev mailing list
Gdal-dev at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/gdal-dev




More information about the Gdal-dev mailing list