[R-sig-Geo] How do I ensure that the polygon in spatstat::owin(poly=<polygon>) does not have “negative area”

Roger Bivand Roger.Bivand at nhh.no
Fri Sep 20 13:35:02 CEST 2013


On Fri, 20 Sep 2013, Francesco Carotenuto wrote:

> Hi Jeff
> Try to type these lines:
>
> mass.map <- map("state", "massachusetts:main", fill=T)
>
> mass.win <- owin(xrange=mass.map$range[1:2],yrange=mass.map$range[3:4] )
>

This will use the bounding box as a window - there was a response on 
R-help giving one resolution:

https://stat.ethz.ch/pipermail/r-help/2013-September/360384.html

Alternatively:

library(maptools)
mass.win <- as(map2SpatialPolygons(mass.map, ID=mass.map$names), "owin")

converting the S3 map class object to an S4 SpatialPolygons object, then 
coercing to owin.

Do note that your state boundary is in geographical coordinates rather 
than planar, projected coordinates, so you may need to tread carefully if 
your subsequent analysis assumes the latter.

Roger

>
> Indeed, using this command:
> names(mass.map)
>
> you can see that your object mass.map has different columns. Columns x and y are the coordinates of all points describing the contour lines of mass.map object.
> You need to use instead the column "range" that contains the bounding box coordinates.
> In details :
>
> mass.map$range[1:2] # from 1 to 2 for the x range
>
> mass.map$range[3:4] # from 3 to 4 for the x range
>
>
> Cheers
>
>
>
> ??
> Dr. Francesco Carotenuto (Ph.D.)
> Department of Earth Sciences
> Federico II University
> Largo S. Marcellino 10,
> 80138 NAPLES (ITALY)
> http://francesco-carotenuto.blogspot.it/
> http://3dpaleontology.blogspot.it/??
> 	[[alternative HTML version deleted]]
>
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
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