[R-sig-Geo] distmap
Roger Bivand
Roger.Bivand at nhh.no
Mon Jun 25 19:59:07 CEST 2007
On Mon, 25 Jun 2007, Agustin Lobo wrote:
> I've tried (among other things):
>> limit1 <- read.shape("limit_PNSN2000.shp")
> Shapefile type: Polygon, (5), # of Shapes: 2
>> limit1poly <- Map2poly(limit1)
>> limit1owin <- as(limit1poly,"owin")
> Error in .classEnv(thisClass) : unable to find an environment containing
> class "polylist"
>
>> limit2 <- readOGR("limit_PNSN2000.shp",layer="limit_PNSN2000")
> OGR data source with driver: ESRI Shapefile
> Source: "limit_PNSN2000.shp", layer: "limit_PNSN2000"
> with 2 rows and 1 columns
Then just:
limit1owin <- as(limit2,"owin")
ought to work with current maptools, or possibly coerce:
limit1owin <- as(as(limit2, "SpatialPolygons"), "owin")
>> limit2poly <- Map2poly(limit1)
>> limit1owin <- as(limit2poly,"owin")
> Error in .classEnv(thisClass) : unable to find an environment containing
> class "polylist"
>> limit1owin <- as(limit2,"owin")
> Error in as.owin.SpatialPolygons(from) : W must be a SpatialPolygons object
>
> I guess all I need is to convert my shapefile (read into R via read.shape or
> readOGR?) into an object like letterR:
>
>> data(letterR)
>> str(letterR)
> List of 4
> $ type : chr "polygonal"
> $ xrange: num [1:2] 2.02 3.93
> $ yrange: num [1:2] 0.645 3.278
> $ bdry :List of 2
> ..$ :List of 2
> .. ..$ x: num [1:24] 2.03 2.02 2.02 2.66 2.66 ...
> .. ..$ y: num [1:24] 3.278 3.248 0.653 0.653 1.695 ...
> ..$ :List of 2
> .. ..$ x: num [1:10] 2.65 2.64 3.04 3.12 3.16 ...
> .. ..$ y: num [1:10] 2.23 2.70 2.71 2.63 2.50 ...
> - attr(*, "class")= chr "owin"
>
> but how can I do it?
>
> Also, I'm so confused with so many spatial objects, is there a guide?
Please ignore all the non sp classes, that makes things simpler. The guide
was in R News in 2005, and is still largely relevant for the Spatial*
classes.
Roger
>
> Agus
>
> Roger Bivand escribió:
>> On Fri, 22 Jun 2007, Agustin Lobo wrote:
>>
>> > Dear sig-geos,
>> >
>> > I have to calculate a distmap (that is, a map
>> > in which the value of each cell is the distance
>> > from the cell to a given object) for a set of polygons.
>> > It seems to me that distmap.owin in spatstat would do it
>> > fine, but distmap.owin does not accept objects
>> > imported from shp vectors via readOGR. distmap.owin requires
>> > type "polygonal" and readOGR yields class 'SpatialPolygonsDataFrame'
>> > Is there any way to cast or convert from 'SpatialPolygonsDataFrame'
>> > to "polygonal" or an alternative function to calculate the distances
>> > to the boundaries of the polygons?
>>
>> Have you tried coercing with as(x, "owin") in maptools?
>>
>> Roger
>>
>> >
>> > Thanks
>> >
>> > Agus
>> >
>> >
>>
>
>
--
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