edzer / sp

Classes and methods for spatial data

Home Page:http://edzer.github.io/sp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lines accepts a Polygon

mdsumner opened this issue · comments

I found this one by accident. It seems there's no problem in giving a Polygon() to a Lines().

 Lines(list(Polygon(cbind(1:10, 1:10))), "1")
Warning: stack imbalance in '.Call', 30 then 29
Warning: stack imbalance in '<-', 28 then 27
Warning: stack imbalance in '{', 25 then 24
Warning: stack imbalance in 'list', 19 then 18
Warning: stack imbalance in 'if', 10 then 9
Warning: stack imbalance in '{', 7 then 6
An object of class "Lines"
Slot "Lines":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] 1 1

Slot "area":
[1] 0

I don't see why this is an issue: it is not supposed to work.

Hence why it should trigger an error.

If you feel it is significant that sp should generate an error in this case, please provide a PR, I'd be happy to accept it.

Ok thanks. I'm afraid I see now that it's by design though since R setClass("Polygon", contains = "Line", so there's really no wonder it isn't an error. It would be fighting the logic at a deep level to prevent what I saw, since a Polygon really is a Line, it's been a long time since I traced this inheritance chain in sp. Sorry for the noise, though I've certainly learnt something and I will PR if I see a stable way to do it.

The stack imbalance is not related, it's triggered by many degenerate Polygons, so I've added those to #12

I agree that none of this is burning issue, but important enough to have recorded IMO.