Tilottama Ghosh
2012-Dec-17 07:07 UTC
[R] looping through spatial points and getting counts of spatial points in spatial grid in R
Hi, I am stuck in a looping problem. It might be an easy problem for experienced R users but I have been unable to do it. Any kind of help or advice will be great appreciated. I am creating a spatial grid and have a list of spatial points in a folder. I can read the spatial points separately and get a count of the points in the spatial grid in R. The output should be a table showing the counts of points in the spatial grid. However, since there are many of these spatial points, I want this process to be automated. Can someone help me with this? All my spatial points are in one folder. # Creating spatial points in R - reading the POI shapefiles as SpatialPointsDataFrame in R autopts.rg <- readOGR(".", "AutoSvc")class (autopts.rg) # Getting a count of the Spatial Points in the Spatial Data Frame in.cell <- overlay(SpatialGrid_LS,FinInstq2) newdata <- data.frame(table(in.cell))View(newdata) "SpatialGrid_LS" is the spatial grid that I had created in R. I guess a For loop would help, but although I tried several things, I haven't been successful yet. Thanks! Tilo [[alternative HTML version deleted]]
Tilottama Ghosh
2012-Dec-17 09:24 UTC
[R] looping through spatial points and getting counts of spatial points in spatial grid in R
Hi, Following Anthony's reply I am attaching two of the POI shapefiles and the code for creating the spatial grid. I am not being able to read the list of these shapefiles and then perform the points in spatial grid function. If someone can help, I will be very grateful. Here is my code for creating the spatial grid -Gridtopo_LS = GridTopology(cellcentre.offset = c(68.162500,6.754167), cellsize = c(0.008333333,0.008333333), cells.dim = c(3508,3451))class (Gridtopo_LS)SpatialGrid_LS = SpatialGrid (Gridtopo_LS, proj4string = CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"))bbox (SpatialGrid_LS)class(SpatialGrid_LS)summary (SpatialGrid_LS)plot (SpatialGrid_LS,pch=3) Thanks very much, Tilo --- On Mon, 17/12/12, Tilottama Ghosh <waggymaggy at yahoo.com> wrote: From: Tilottama Ghosh <waggymaggy at yahoo.com> Subject: looping through spatial points and getting counts of spatial points in spatial grid in R To: r-help at r-project.org Date: Monday, 17 December, 2012, 0:07 Hi, I am stuck in a looping problem. It might be an easy problem for experienced R users but I have been unable to do it. Any kind of help or advice will be great appreciated. I am creating a spatial grid and have a list of spatial points in a folder. I can read the spatial points separately and get a count of the points in the spatial grid in R. The output should be a table showing the counts of points in the spatial grid. However, since there are many of these spatial points, I want this process to be automated. Can someone help me with this? All my spatial points are in one folder.? # Creating spatial points in R - reading the POI shapefiles as SpatialPointsDataFrame in R?autopts.rg <- readOGR(".", "AutoSvc")class (autopts.rg) # Getting a count of the Spatial Points in the Spatial Data Frame?in.cell <- overlay(SpatialGrid_LS,FinInstq2)?newdata <- data.frame(table(in.cell))View(newdata) "SpatialGrid_LS" is the spatial grid that I had created in R.? I guess a For loop would help, but although I tried several things, I haven't been successful yet. Thanks! Tilo
John Kane
2012-Dec-17 12:48 UTC
[R] looping through spatial points and getting counts of spatial points in spatial grid in R
Sample data? Please supply some sample data and code. The easiest way to supply data is to use the dput() function. Example with your file named "testfile": dput(testfile) Then copy the output and paste into your email. For large data sets, you can just supply a representative sample. Usually, dput(head(testfile, 100)) will be sufficient. John Kane Kingston ON Canada> -----Original Message----- > From: waggymaggy at yahoo.com > Sent: Sun, 16 Dec 2012 23:07:54 -0800 (PST) > To: r-help at r-project.org > Subject: [R] looping through spatial points and getting counts of spatial > points in spatial grid in R > > Hi, > I am stuck in a looping problem. It might be an easy problem for > experienced R users but I have been unable to do it. Any kind of help or > advice will be great appreciated. > I am creating a spatial grid and have a list of spatial points in a > folder. I can read the spatial points separately and get a count of the > points in the spatial grid in R. The output should be a table showing the > counts of points in the spatial grid. However, since there are many of > these spatial points, I want this process to be automated. Can someone > help me with this? All my spatial points are in one folder. > # Creating spatial points in R - reading the POI shapefiles as > SpatialPointsDataFrame in R autopts.rg <- readOGR(".", "AutoSvc")class > (autopts.rg) > > # Getting a count of the Spatial Points in the Spatial Data Frame in.cell > <- overlay(SpatialGrid_LS,FinInstq2) newdata <- > data.frame(table(in.cell))View(newdata) > "SpatialGrid_LS" is the spatial grid that I had created in R. > I guess a For loop would help, but although I tried several things, I > haven't been successful yet. > Thanks! > Tilo > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails