[R-sig-Geo] gBuffer solution to invalid objects problem fails

Kenny Bell kmb56 at berkeley.edu
Thu May 19 21:55:45 CEST 2016


Great, this works:

new_poly <- sp::spTransform(new_poly, "+proj=tmerc +lat_0=0 +lon_0=173
+k=0.9996 +x_0=1600000 +y_0=10000000 +ellps=GRS80 +units=m +no_defs")
grid_poly <- sp::spTransform(grid_poly, "+proj=tmerc +lat_0=0 +lon_0=173
+k=0.9996 +x_0=1600000 +y_0=10000000 +ellps=GRS80 +units=m +no_defs")
new_poly1 <- gBuffer(new_poly, width = 0)
plot(new_poly1)
# Works
gIntersection(grid_poly, new_poly1,
              byid = c(TRUE, FALSE),
              id = as.character(grid_poly at data[,1]),
              # if there are coinciding lines, gIntersection
              # returns a cross.
              drop_lower_td = TRUE,
              checkValidity = TRUE)

Thanks so much Roger!

On Thu, May 19, 2016 at 12:02 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:

> There is an example in the message, but Kenny is ignoring the message from
> gBuffer:
>
> Warning message:
> In gBuffer(new_poly, width = 0) :
>   Spatial object is not projected; GEOS expects planar coordinates
>
> and the differences in geographical coordinates are small. The warning is
> given for a reason. Intersection is projection-agnostic, but buffer is not.
> I don't know whether this is the reason.
>
> Roger
>
>
>
> On Thu, 19 May 2016, Roman Luštrik wrote:
>
> Hi Kenny,
>>
>> can you provide a small, reproducible example which replicates this
>> behavior?
>>
>> Cheers,
>> Roman
>>
>> On Wed, May 18, 2016 at 7:08 PM, Kenny Bell <kmb56 at berkeley.edu> wrote:
>>
>> Hi all,
>>>
>>> I have been getting the below error a few times. I have seen in several
>>> places that a zero-width gBuffer call will fix the topology problem.
>>> However, in this case, I find that the call to gBuffer generates a 4
>>> point
>>> horizontal line, not solving the problem. Is there another solution?
>>> Thanks
>>> for any help!
>>>
>>> My code:
>>>
>>> library(sp)
>>> library(rgeos)
>>> load("r-sig-geo.RData")
>>>
>>> gIntersection(grid_poly, new_poly,
>>>               byid = c(TRUE, FALSE),
>>>               id = as.character(grid_poly at data[,1]),
>>>               # if there are coinciding lines, gIntersection
>>>               # returns a cross.
>>>               drop_lower_td = TRUE,
>>>               checkValidity = TRUE)
>>> # new_poly is invalid
>>> # Error in rgeos::gIntersection(grid_poly, new_poly, byid = c(TRUE,
>>> FALSE),
>>>  :
>>> #                                 Invalid objects found
>>> #                               In addition: Warning message:
>>> #                                 In RGEOSUnaryPredFunc(spgeom, byid,
>>> "rgeos_isvalid") :
>>> #                                 Self-intersection at or near point
>>> 172.23206269997971 -42.13157792003453
>>>
>>> # Try using gBuffer as suggested here:
>>> #
>>>
>>>
>>> http://gis.stackexchange.com/questions/163445/r-solution-for-topologyexception-input-geom-1-is-invalid-self-intersection-er
>>>
>>> new_poly1 <- gBuffer(new_poly, width = 0)
>>> plot(new_poly1)
>>> # Generates a line (i.e. kills the polygon)​
>>>>>>   r-sig-geo.RData
>>> <https://www.dropbox.com/s/9ivpcmboodpu6zd/r-sig-geo.RData?dl=0>
>>>>>>
>>>         [[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]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> --
> Roger Bivand
> Department of Economics, Norwegian School of Economics,
> Helleveien 30, N-5045 Bergen, Norway.
> voice: +47 55 95 93 55; fax +47 55 95 91 00
> e-mail: Roger.Bivand at nhh.no
> http://orcid.org/0000-0003-2392-6140
> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
> http://depsy.org/person/434412




-- 
Kendon Bell
Email: kmb56 at berkeley.edu
Phone: (510) 612-3375

Ph.D. Candidate
Department of Agricultural & Resource Economics
University of California, Berkeley

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list