[R-sig-Geo] Question:manipulating spatial data using combination of Maptools and Splancs

Roger Bivand Roger.Bivand at nhh.no
Mon Sep 19 18:40:27 CEST 2005


On Mon, 19 Sep 2005, kostas karis wrote:

> Dear Roger,
> This is my fourth mail to u (we can call it a date :))
> Ok, u are right that my mails were vague..It's the first time i ask help 
> from a a mailing list so i'am a little unfamiliar with the process.i'll try 
> to be more specific.

Well, you're doing pretty well, keep it up and you'll be answering other 
peoples' questions before long, it's how we all begin!

> Now i have 2 questions
> I wrote the code as you suggested and after the conversion the kernel 
> crashes again.I suspect it's the nx and ny options but i don't know how to 

Warning - only say "crash" when R error terminates (dies totally). Here R 
was still alive, you just hit an error condition. Like the difference 
between hitting a truck head on and taking a wrong turn in a city you 
don't know ...

> adjust them.
> 
> >library(splancs)
> 
> Spatial Point Pattern Analysis Code in S-Plus
> 
> Version 2 - Spatial and Space-Time analysis
> >library(maptools)
> Loading required package: foreign
> Loading required package: sp
> >akto<-readShapePoly("Export_sterea_mac.shp",verbose=T)
> Shapefile type: Polygon, (5), # of Shapes: 1
> >quakes<-readShapePoints("QD15.shp")
> >plot(akto)
> >plot(quakes,add=T)
> >sp_quakes<-coordinates(quakes)
> >getSpPnParts(akto)
> [1] 1
> >sp_akto<-getPolygonCoordsSlot(getPolygonsPolygonsSlot(getSpPpolygonsSlot(akto)[[1]])[[1]])
> >polymap(sp_akto)
> >image(kernel2d(sp_quakes,sp_akto, h0=15,nx=100,ny=100),add=T)
> Error in bbox(poly) : no direct or inherited method for function 'bbox' for 
> this call (???)
> 

OK, this is a conflict between sp and splancs, both of which define 
functions called bbox but differently. The only current solution is not to 
say library(splancs) until you have finished all the sp functions - this 
will be fixed before long. the h0 value - the bandwidth - will need 
choosing depending on the scales of your coordinates and their relative 
placing - 15 in metres is different from 15 in km. nx and ny are OK.

> 
> In the above session i have used a single ring polygon.What if i wanted to 
> import a polygon with many rings?My objective here is to import my countries 
> boundaries (Greece). 

Well, splancs only handles a single ring, that is all you get. I'm rather 
unsure what point process of interest could be studied on 2000+ polygons 
at the same time - and if they are quakes, I don't think you need to use 
coastlines for more than display. You may simply be able to use the 
coastlines as coastlines, plotted on top of the density output, since 
quakes will also happen under the sea, right? Use sbox() in splancs on 
sp_quakes, that will give a rectangular bounding box extended a little on 
all sides. However, if your points are quakes, they will have dates and 
intensities, I think? Have you perhaps had a chance to look at the article 
on seismology in R in the 2005 (1) number of R News? Maybe some of the 
functions used there would suit you - they are not on CRAN, but do work, 
the access references are in the article.

Hope this helps,

Roger

> U realize that it's a polygon with many rings because 
> it has many islands. When i ran the same code as above i take the following 
> output:
> 
> >akto2<-readShapePoly("akto.shp",verbose=T)
> Shapefile type: Polygon, (5), # of Shapes: 1
> >getSpPnParts(akto)
> [1] 2024
> 
> How can i convert all the rings?
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
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




More information about the R-sig-Geo mailing list