kostas karis
2005-Sep-16 13:33 UTC
[R] Question:manipulating spatial data using combination of Maptools and Splancs
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.
Roger Bivand
2005-Sep-16 17:36 UTC
[R] Question:manipulating spatial data using combination of Maptools and Splancs
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