Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linestring.is_simple is wrong #768

Closed
shankari opened this issue Aug 29, 2019 · 6 comments
Closed

linestring.is_simple is wrong #768

shankari opened this issue Aug 29, 2019 · 6 comments

Comments

@shankari
Copy link

Expected behavior and actual behavior.

My non-self-crossing line should return is_simple = True

Steps to reproduce the problem.

import polyline as pl
import shapely as shp

bart_line_pl = 'ly~iV{|ndFqHbHbJqIq@l@vFoFw@t@mCjCdEaEtAaB??NM??lCgCnMgMxG}GtLsL??vAwAdDaD??vCuCb@c@d@g@`@e@\\_@Za@Za@pF}G~@kAz@mAx@kAbAwAhBmCf@w@f@w@f@y@j@y@h@}@l@}@nAeBpAoBhBkC??rAoBzAyB??`EaGnBsCXa@zG{J|Zsn@rK{RzCaG??Vi@??hBsD??HO??R_@??HQ??Zq@zDmI|D}JjA}B~AyBhDgElDiEvGuIbNiP|AaBbBaBdByA`BkApBoAbCuA`CiAhSuIbDyAlCqAhCwAxBoAdBmAzAoAjAiA|@}@~@kAbHmJdAoAfAkArAoAtAmA`BoAfBkA`BeAlGcD`KqFjLsG`BeAxAgArAmArA_BdAwAz@sAxEiIfG{KjAgB~AkBhBgBbBqAnBqArBgAbCmAzC{AfC{AtBcBXUnAkAbBeB`DuDvIuKn@s@n@q@l@m@t@k@r@e@v@e@??fCaB??zAcAzAcA??rA}@rA_Ab@WfJsF??p@c@\\UPMNMNMNMNOJKLOLOJOJOLSJOTe@Ti@^{@??|AoD??JU\\y@Rg@Tq@R{@Ho@Fy@Bm@@o@DkFD{D@mD??@u@???oB@s@Bi@Dw@Hs@??P{@T{@v@gC??Ne@d@_BLe@Jg@Je@Hi@Di@Bk@@s@?q@BcE??BqDBoC@qD?kA?g@Ce@Ec@I_@Kc@Qg@Uc@Wa@Yc@}DeF??yEgG??k@u@??y@gAuEcG??c@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@_@oBGW??QaA??Oy@??O_A??o@iD??}@_F[cB[aBYqA[{Ac@mBa@cBYgAm@eC[oAUaAKo@Ii@??UaB??[cC}@cH??OsA??AG??S}A??YkD??McA??QeB??MkAIu@??Ce@Cc@?g@???m@Bm@??Dg@Hi@Hi@Ni@Ne@??Rg@??Rc@Ta@Ta@Ze@^g@b@i@\\_@|AgBv@_At@_Aj@}@h@cAb@eA\\eAZkARiARuApGsg@NwAHaABY??Bi@D_A???}@A_A??G}AMkA[cB{DgMuCiK}Js^w@}CQiAGu@AeADaA~@cOXmEpAeV^kEr@}I'
ls = shp.geometry.LineString(pl.decode(bart_line_pl)); ls
ls.is_simple

Notes:

  • I don't know if this is a generic issue; I only encountered it in this use case.
  • If you run this in a notebook, you can display the line ls and confirm that it is not self-crossing (see screenshot)

Screen Shot 2019-08-29 at 12 32 28 PM

Operating system

Mac OSX 10.14.5

Shapely version and provenance

Installed from conda-forge

$ conda list shapely
# packages in environment at ...:
#
shapely                   1.6.4            py36he8793f5_0
@shankari
Copy link
Author

Uploading screenshot with scaling to show the string better.
Screen Shot 2019-08-29 at 12 35 24 PM

@sgillies
Copy link
Contributor

sgillies commented Aug 29, 2019

@shankari green means only that the geometry is "valid", which is always the case for line strings. I suspect that your line really does self-intersect at some point, even if that is only due to floating point precision errors.

It would probably be good to make linestrings red if they are not simple, yes? Instead of coloring based on is_valid.

@shankari
Copy link
Author

shankari commented Aug 29, 2019

@sgillies I didn't even know that linestring color represented validity 😃 I just put that in to show that there are no self-intersections.

As you can probably tell, that is a public transit line and when I display it on a map, I can zoom and pan. And I don't see any self-intersections or anything that might be close to a self-intersection.

Is there a way I can determine the supposed intersection point so that I can check that location?

@kannes
Copy link
Contributor

kannes commented Sep 5, 2019

You can compare the coordinates of the linestring pair-wise:

for a, b in zip(ls.coords, ls.coords[1:]): 
    if a == b: 
        print(a, b) 

You have many duplicate coordinates, which is not allowed in the Simple Features specification.

A possible automatic fix would ls.simplify(0).

@sgillies
Copy link
Contributor

sgillies commented Sep 5, 2019

@kannes thank you 🙏

@kannes
Copy link
Contributor

kannes commented Sep 5, 2019

Right back at you! Any time I file a bug report or voice a wish, I also look at issues to see if I can help, that's the spirit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants