[R-sig-Geo] Convert raster to polygon

Vlad valdounet at gmail.com
Fri Oct 14 08:48:18 CEST 2011


Hello,

I had the same problem in the past and so I developped a function that 
allow to convert directly a raster to a SpatialPolygonsDataFrame.

The function ('polygonize') is available in a small package I wrote :
http://sourceforge.net/projects/geoconv/

The package is written in French (sorry about that), so if the 
documentation is not understandable, ask me.

I hope this can help.


Vlad

----
Vladislav Navel

Ingénieur d'études
Atmo Poitou-Charentes
05 46 44 83 88


Le 14/10/2011 07:24, Mathieu Rajerison a écrit :
> Hi,
>
> And will contiguous raster cells have the same value, as Arnaud expected?
>
> 2011/10/13 Rolf Turner<r.turner at auckland.ac.nz>
>
>> On 14/10/11 09:01, Arnaud Mosnier wrote:
>>
>>> Dear all,
>>>
>>> In searching a solution from the internet, I found someone who had the
>>> same
>>> problem as me but ... who had no answers.
>>> I hope I will have better chance!  :-)
>>>
>>> Here is her explanation:
>>> http://r-sig-geo.2731867.n2.**nabble.com/Converting-raster-**
>>> to-polygons-with-just-one-**polygon-for-cells-with-common-**
>>> value-td6065464.html<http://r-sig-geo.2731867.n2.nabble.com/Converting-raster-to-polygons-with-just-one-polygon-for-cells-with-common-value-td6065464.html>
>>>
>>> In the same way, I want to convert a raster with several values to
>>> SpatialPolygons.
>>> As in the previous message, I used the function "rasterToPolygons"
>>> (package
>>> raster) ... but it is really slow and memory hungry.
>>> Moreover, I want to have polygons that include contiguous raster cells
>>> with
>>> the same value, not one polygon by raster cell.
>>> The function unionSpatialPolygons can do that.
>>>
>>> Is there another (more efficient) way to do this in R ?
>>>
>> If you can convert your "raster" to a spatstat object of class "owin",
>> (and type "mask" of course) then the spatstat function "as.polygonal" will
>> convert it to an owin object of type "polygonal".  Which you will then
>> want, I presume, to convert to an object of class "SpatialPolygons".
>>
>> The latter can be done easily via:
>>
>> require(maptools)
>> Z<- as(Y,"SpatialPolygons")
>>
>> where Y is the output of as.polygonal().
>>
>> I don't know about the raster -->  owin conversion though.  Others may
>> be able to tell you.
>>
>> Note that you will need to have "gpclib" enabled to use as.polygonal()
>> and hence will need to be operating under the terms allowed by the
>> gpclib license.
>>
>> HTH.
>>
>>     cheers,
>>
>>         Rolf Turner
>>
>>
>> ______________________________**_________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/**listinfo/r-sig-geo<https://stat.ethz.ch/mailman/listinfo/r-sig-geo>
>>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list