
********
> require(rgdal)
> require(adehabitat)

> (file1 <-  paste(system.file(package = "adehabitat"),
               "ascfiles/elevation.asc", sep = "/"))
> el <- readGDAL(file1)
> image(el, axes=T)
> el.pix <- as(el, "SpatialPixelsDataFrame")
> el.pol <- as.SpatialPolygons.SpatialPixels(el.pix)
> str(el.pol, max.level=2)
> el.pol@polygons[[1]]
> plot(el.pol)
********

if you want to do "map segmentation" in SAGA GIS or "map slicing" in ILWIS GIS, then you could do something like:

********
> setwd <- paste(system.file(package = "adehabitat"),"ascfiles/",sep=""))
> library(RSAGA) 
# ! download and install SAGA GIS (www.saga-gis.org) and ILWIS GIS (www.52north.org) to your machine first!
> rsaga.env(path="C:/Progra~1/saga_vc")
> ILWIS <- "C:\\Progra~1\\N52\\SetupIlwis\\IlwisClient.exe -C"
> rsaga.get.usage("grid_discretisation", 3)
> rsaga.esri.to.sgrd(in.grids="elevation.asc", out.sgrds="el.sgrd", in.path=getwd())
> rsaga.geoprocessor(lib="grid_discretisation", module=3, param=list(INPUT="el.sgrd", SEGMENTS="seg.sgrd", OBJECTS="obj.sgrd", METHOD=0, VALUES=0))
...
> breaks.el <- as.factor(hist(el@data[[1]], plot=F)$breaks)
> writeGDAL(el[1], "elevation.mpr", "ILWIS")
> shell(cmd=paste(ILWIS, " crdom breaks.dom -type=group -items=0",sep=""), wait=F)
> for(i in 1:length(levels(breaks.el))){
   shell(cmd=paste(ILWIS, " additemtodomaingroup breaks.dom ", i+.01," cl",i,sep=""), wait=F)
}
> shell(cmd=paste(ILWIS, "elevation_sliced.mpr = MapSlicing(elevation.mpr, breaks.dom)"), wait=F)
> shell(cmd=paste(ILWIS, "open elevation_sliced.mpr -noask"), wait=F)
...
********


Tom Hengl
http://spatial-analyst.net


-----Original Message-----
From: r-sig-geo-bounces@stat.math.ethz.ch on behalf of milton ruser
Sent: Mon 29/09/2008 9:39 PM
To: r-sig-geo@stat.math.ethz.ch
Subject: [R-sig-Geo] polygons from pixels.
 
Dear RGeo-Gurus,

I have a ASC file, and would like that each pixel come to be a polygon.
Any help are welcome.

require(rgdal)
require(adehabitat)

(file1 <-  paste(system.file(package = "adehabitat"),
               "ascfiles/elevation.asc", sep = "/"))
el <- readGDAL(file1)
image(el, axes=T)

best wishes,

miltinho astronauta
brazil

	[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


	[[alternative HTML version deleted]]


