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

Ari Jolma ari.jolma at tkk.fi
Fri May 26 02:15:26 EDT 2006


Aaron Racicot kirjoitti:
> Hi there Ari,
> 
> Very cool...
> 
> Another option is to just do the following in grass:
> 
> r.in.gdal input=input_rast output=grass_rast


Funny how I did not think about looking at Grass. I did look, but only
after I sent the post. I took a look at r.in.gdal at CVS. The algorithm
there was not very clear to copy however, and I would love to use Grass
(I guess) if it could use, e.g., geotiffs directly. Or can it? I may
just be talking nonsense again. I tried once r.in.gdal for one of my
50000x50000 rasters and it was just unbearably slow.

Besides, it is educational and fun to discover and write comp.graphics
algorithms on holidays ;-)

Ari


> 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


-- 
Prof. Ari Jolma
Kartografia ja Geoinformatiikka / Cartography and Geoinformatics
Teknillinen Korkeakoulu / Helsinki University of Technology
tel: +358 9 451 3886 address: POBox 1200, 02015 TKK, Finland
Email: ari.jolma at tkk.fi URL: http://www.tkk.fi/~jolma



More information about the Gdal-dev mailing list