2012/3/29 Roger Bivand <Roger.Bivand@nhh.no>

> On Thu, 29 Mar 2012, Raffaele Morelli wrote:
>
>  Hi,
>>
>> I am working on a simple kernel2d analisys and would like to create a
>> polymap from a SpatialPolygonsDataFrame, let's stay US states.
>> how can I accomplish this task? can you point me to the right direction?
>>
>
> Why? Please include sample code. I assume that you realise that the poly=
> argument in this function requires a single polygon ring, so you would
> first have to define your window and go from there.
>

I have a SpatialPointsDataFrame all over Italy and I am calculating
kernel2d for each district (24 administrative boundaries, eg. Lazio,
Piemonte, Sicilia, Sardegna...)

# I fetch Italy boundaries and the spdf from postgres with:

districts <- readOGR("PG:dbname=xxxx host=xxx user=xxx password=xxx",
"italy_utm32")
points <- readOGR("PG:dbname=xxx host=xxx user=xxx password=xxx",
"points_utm32")

# I want to calculate kernel 2d for districts then the need to "extract"
the poly for EACH of them using administrative boundaries for poly
argument, so:

regione <- districts[districts$ditricts_id==cod,]  # where cod is the
district id

# and then I solved the thread question using:
poly <- as.matrix(district@polygons[[1]]@Polygons[[1]]@coords)

plot(regione, asp=1)
image(kernel2d(as.points(points@coords), poly, h0=5000, nx=450, ny=450),
add=TRUE, col=terrain.colors(10))

plot(regione, lwd=3, border="grey50", add=TRUE, axes=TRUE)

I hope this is clear, apologize for my english :(

Actually I am facing with another issue. Each dictrict can have isles, so I
should guess the number of polygons object for each district

eg.
> str(district@polygons[[1]])
Formal class 'Polygons' [package "sp"] with 5 slots
  ..@ Polygons :List of 37
......

and I should calculate kernel2d for each isle.

So, how can I guess the list lenght (37 in the example above)?
I tried using
length(regione@polygons[[1]])

with no success...

regards
-r


-- 
*L'unica speranza di catarsi, ammesso che ne esista una, resta affidata
all'istinto di ribellione, alla rivolta non isterilita in progetti, alla
protesta violenta e viscerale.*

	[[alternative HTML version deleted]]

