[R-sig-Geo] Overlaying SpatialLines by SpatialPolygons

Roger Bivand Roger.Bivand at nhh.no
Tue Jun 7 19:58:55 CEST 2011


On Tue, 7 Jun 2011, Mathieu Rajerison wrote:

> Thanks for the answer!
>
> I think I surely have to use gIntersection then gLength for this purpose
>
> I've tried gIntersection like this:
> routes2 = gIntersection(routes, bdc)
>
> But I get the following message:
> Erreur dans createPolygonsComment(p) :
>  rgeos_PolyCreateComment: orphaned hole, cannot find containing polygon for
> hole at index 1
>
> Do you have an idea why I get this message and how to correct it?

The polygon object is malformed, and at least one polygon claims only to 
be an interior ring, which is impossible. You need to look at how you are 
creating your SpatialPolygons object, and possibly use 
checkPolygonsHoles() in maptools to repair damaged objects. Typically 
running:

library(maptools)
pls <- slot(bdc, "polygons")
pls1 <- lapply(pls, checkPolygonsHoles)
slot(bdc, "polygons") <- pls1

may help. As Colin says, posting a link to the polygons object, and to 
code used to create it, may be helpful.

Roger

>
>
>
> 2011/6/7 Roman Lu??trik <roman.lustrik at gmail.com>
>
>> Package rgeos has all sorts of functions that might come handy.
>>
>> Cheers,
>> Roman
>>
>>
>>
>> On Tue, Jun 7, 2011 at 6:13 PM, Mathieu Rajerison <
>> mathieu.rajerison at gmail.com> wrote:
>>
>>> Hi,
>>>
>>>
>>> I have a SpatialLines object representing roads and a SpatialPolygons
>>> object
>>> containing cities.
>>>
>>> I'd like to know how to overlay a SpatialLines object by aSpatialPolygons
>>> object.
>>>
>>> I'd like to know the total distance of roads that cover each of my cities.
>>>
>>> Is it possible?
>>>
>>>
>>> Thanks,
>>>
>>> Mathieu
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>>
>>
>> --
>> In God we trust, all others bring data.
>>
>
> 	[[alternative HTML version deleted]]
>
>

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