[R-sig-Geo] Points density in R

Tomislav Hengl T.Hengl at uva.nl
Wed Oct 15 09:52:44 CEST 2008


Kernel density can be derived in spatstat package, but also in adehabitat and many other packages.

You need to loop your operations (output as a list). Note that I use the same file names to save
space - you only need the output of course!

***************

library(maptools)
library(rgdal)
library(spatstat)

txt.list <- dir(pattern=glob2rx("*.txt"))
txt.list

vegetation.list <- as.list(paste(1:length(txt.list),"m",sep=""))
density.list <- as.list(paste(1:length(txt.list),"m",sep=""))
for(i in seq(along=txt.list)) {
   vegetation <- read.delim(paste(txt.list[[i]]), sep=" ")
   coordinates(vegetation) <- ~X+Y
   proj4string(vegetation) <- CRS("+init=epsg:26911")
   vegetation.ppp <- as(vegetation[1], "ppp")  # here you will probably be better of if you define
the grid topology yourself (otherwise you get 100x100 pixels by default)
   density.list[[i]] <- density.ppp(vegetation.ppp, sigma=120)
   writeOGR(vegetation[1], paste(vegetation.list[[i]], ".shp", sep=""), "vegetation", driver="ESRI
Shapefile")   
}

image(density.list[[1]])
str(density.list, max.level=2)

***************

For future reference, we can not help you if you do not provide any data (there is a lot of data on
CRAN already). Please also read carefully http://www.r-project.org/posting-guide.html 


yours,

T. Hengl
http://spatial-analyst.net 



-----Original Message-----
From: r-sig-geo-bounces at stat.math.ethz.ch [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of
Alessandro
Sent: Tuesday, October 14, 2008 9:04 PM
To: r-sig-geo at stat.math.ethz.ch
Subject: [R-sig-Geo] Points density in R

Hi all,

 

I have a txt file with X,Y,Z value. I wish to create a density points Map in
R but sorry I didn't find a right code in R.

 

Part of my code is this.  I have a another  question. With many data files
to import, Is It possible don't write 10 lines like my not beautiful code? 

 

Thanks Ale

 

library(maptools)

library(rgdal)

rsaga.env(path="C:/Progra~1/saga_vc")

library(RSAGA)

library(gstat)

vegetation_2m <- read.delim("vegetation_2m.txt", sep=" ")

vegetation_3m <- read.delim("vegetation_3m.txt", sep=" ")

vegetation_4m <- read.delim("vegetation_4m.txt", sep=" ")

vegetation_5m <- read.delim("vegetation_5m.txt", sep=" ")

vegetation_6m <- read.delim("vegetation_6m.txt", sep=" ")

vegetation_7m <- read.delim("vegetation_7m.txt", sep=" ")

vegetation_8m <- read.delim("vegetation_8m.txt", sep=" ")

vegetation_9m <- read.delim("vegetation_9m.txt", sep=" ")

vegetation_10m <- read.delim("vegetation_10m.txt", sep=" ")

coordinates(vegetation_2m) =~X+Y

coordinates(vegetation_3m) =~X+Y

coordinates(vegetation_4m) =~X+Y

coordinates(vegetation_5m) =~X+Y

coordinates(vegetation_6m) =~X+Y

coordinates(vegetation_7m) =~X+Y

coordinates(vegetation_8m) =~X+Y

coordinates(vegetation_9m) =~X+Y

proj4string(vegetation_2m) <- CRS("+init=epsg:26911")

proj4string(vegetation_3m) <- CRS("+init=epsg:26911")

proj4string(vegetation_4m) <- CRS("+init=epsg:26911")

proj4string(vegetation_5m) <- CRS("+init=epsg:26911")

proj4string(vegetation_6m) <- CRS("+init=epsg:26911")

proj4string(vegetation_7m) <- CRS("+init=epsg:26911")

proj4string(vegetation_8m) <- CRS("+init=epsg:26911")

proj4string(vegetation_9m) <- CRS("+init=epsg:26911")

#convert in .shp to use RSAGA

writeOGR(vegetation_2m["Z"], "vegetation_2m.shp", "vegetation_2m",
driver="ESRI Shapefile")

writeOGR(vegetation_3m["Z"], "vegetation_3m.shp", "vegetation_3m",
driver="ESRI Shapefile")

writeOGR(vegetation_4m["Z"], "vegetation_4m.shp", "vegetation_4m",
driver="ESRI Shapefile")

writeOGR(vegetation_5m["Z"], "vegetation_5m.shp", "vegetation_5m",
driver="ESRI Shapefile")

writeOGR(vegetation_6m["Z"], "vegetation_6m.shp", "vegetation_6m",
driver="ESRI Shapefile")

writeOGR(vegetation_7m["Z"], "vegetation_7m.shp", "vegetation_7m",
driver="ESRI Shapefile")

writeOGR(vegetation_8m["Z"], "vegetation_8m.shp", "vegetation_8m",
driver="ESRI Shapefile")

writeOGR(vegetation_9m["Z"], "vegetation_9m.shp", "vegetation_9m",
driver="ESRI Shapefile")

 


	[[alternative HTML version deleted]]

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




More information about the R-sig-Geo mailing list