[R-sig-Geo] How to filter a xyz vector file

Ashraf Afana asafaneh at yahoo.com
Thu Oct 15 10:55:41 CEST 2015


Dear Robert, Thanks a lot. This code really works in a nice and simple way.Ashraf, cheers 


     El Martes 13 de octubre de 2015 19:53, Robert J. Hijmans <r.hijmans at gmail.com> escribió:
   

 Ashraf,
Here is an approach:

# some random points
x <- runif(10000)
y <- runif(10000)
xy <- cbind(x, y)

# a raster to specficy the extent and resolution
library(raster)
r <- raster(round(extent(xy)), res=0.1)

# find the distance of each point to the center of the cell it falls in
cell <- cellFromXY(r, xy)
cellxy <- xyFromCell(r, cell)
d <- pointDistance(xy, cellxy, lonlat=FALSE)

# combine and get, for each cell, the point nearest to the center
z <- cbind(cell, xy, d)
z <- z[order(z[, 1], z[, 4]), ]
zz <- z[!duplicated(z[,1]), ]

# have a look:
r[] = 1
plot(r)
points(z[,2:3], cex=.1)
points(zz[,2:3], col='red', pch=20)
# plot(as(r, 'SpatialPolygons'), add=TRUE)

Best, Robert

On Sun, Oct 11, 2015 at 11:07 AM, Ashraf Afana via R-sig-Geo
<r-sig-geo at r-project.org> wrote:
> Hi friends,
>
> I have a xyz vector file from a terrestrial laser scanner that contains a huge amount of points at a high resolution (approximately 15 mm). I need to reduce the amount of point in the file by selecting N number of points each certain distance (i.e. generate equidistant spacing). I was looking at the available libraries in R (sp, rgdal, etc.), but I was unable to find a function to do so. Any suggestions?
>
> Ashraf,
>        [[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

  
	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list