Hi, I have a problem that concerns combination of the package Maptools and Splancs I have 2 shapefiles that i want to manipulate (one of type point and one polygon).I import them in R using Maptools but then i can't estimate a quartic Kernel using Splancs. The package doesn't recognize the shapes (invalid points and poly argument).I don't know if this is an easy task but i have read both packages's manual and i can't find a liable solution. Thank u for your time.
Question:manipulating spatial data using combination of Maptools and Splancs
4 messages · kostas karis, Roger Bivand
On Fri, 16 Sep 2005, kostas karis wrote:
Hi, I have a problem that concerns combination of the package Maptools and Splancs I have 2 shapefiles that i want to manipulate (one of type point and one polygon).I import them in R using Maptools but then i can't estimate a quartic Kernel using Splancs. The package doesn't recognize the shapes (invalid points and poly argument).I don't know if this is an easy task but i have read both packages's manual and i can't find a liable solution. Thank u for your time.
Say you have a shapefile of points, and a shapefile with one single ring polygon, no holes or other geometry objects, then using maptools 0.5-2:
library(maptools)
Loading required package: foreign Loading required package: sp
cardiff_pts <- readShapePoints("cf_pts")
cardiff_poly <- readShapePoly("cf_poly", verbose=TRUE)
Shapefile type: Polygon, (5), # of Shapes: 1
plot(cardiff_poly) plot(cardiff_pts, add=TRUE)
Conversion is by
splancs_pts <- coordinates(cardiff_pts) splancs_poly <- getPolygonCoordsSlot(getPolygonsPolygonsSlot(
+ getSpPpolygonsSlot(cardiff_poly)[[1]])[[1]]) to unpack the coordinates of the points and the single ring boundary. If you have more than one shape, and/or more than one ring in that shape, adjust the [[Shape]])[[ring]] indices to suit. Then:
polymap(splancs_poly) image(kernel2d(splancs_pts, splancs_poly, h0=15, nx=100, ny=100),
+ add=TRUE)
pointmap(splancs_pts, add=TRUE)
works as expected. Extracting the polygon looks complicated because shapefiles have a "richer" geometry than splancs. Wrapper functions for splancs to use the sp classes now used by maptools will be available before long.
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no
Thank you for your advice but i still have a problem...Everything goes fine till the plotting (as usual).When i try the code you posted for the conversion i get the following message: Error in coordinates(quakes) : no direct or inherited method for function 'coordinates' for this call i don't have a clue what this means... _________________________________________________________________ Don't just search. Find. Check out the new MSN Search!
On Sat, 17 Sep 2005, kostas karis wrote:
Thank you for your advice but i still have a problem...Everything goes fine till the plotting (as usual).When i try the code you posted for the conversion i get the following message: Error in coordinates(quakes) : no direct or inherited method for function 'coordinates' for this call i don't have a clue what this means...
Please always include the commands you gave, here in particular the command(s) creating the quakes object - other list participants cannot see your computer screen. All the error message says is that it is not a SpatialPoints* object, so you have not done:
quakes <- readShapePoints("quakes.shp")
quakes_pts <- coordinates(quakes)
as I suggested. I also suggest moving this thread to the R-sig-geo list - subscription details on the "Spatial" Task View on CRAN: http://cran.r-project.org/src/contrib/Views/Spatial.html
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no