Polygons have self-crossings

28 views
Skip to first unread message

ckgoo...@gmail.com

unread,
Aug 31, 2024, 1:37:01 PMAug 31
to spatiali...@googlegroups.com

Hi, I am processing OSM data – it happens to be the admin_level 2 boundary relation for South Africa as this contains an inner ring – and when I import my processed data into a Spatialite table with a polygon geometry column, and I use IsValid to test the polygon, I get a warning that it contains a self-crossing.    If I simplify the polygon then this problem gets fixed but my polygon is now less accurate than before so not ideal.

I am really stuck on how to resolve this.  It is an OSM data problem presumably.  However, being blind I can’t visualise the polygon and just looking at numbers it is pretty impossible to work out where the crossover is happening and what the fundamental problem might be.

If anyone would like to help, this is a zipped version of the data in CSV format which contains the crossing on longitude 30.8919.

https://www.dropbox.com/scl/fi/fkvc1er1dqdyb3d3mvgve/outer.zip?rlkey=8ajc6yhqg34fm60cqcu1lq18d&dl=0

And any general suggestions on how to tackle this kind of problem would be welcome.

Best, Chris

a.fu...@lqt.it

unread,
Aug 31, 2024, 1:53:36 PMAug 31
to spatiali...@googlegroups.com
On Sat, 31 Aug 2024 18:02:17 +0100, ckgoo...@gmail.com wrote:
> Hi, I am processing OSM data - it happens to be the admin_level 2
> boundary relation for South Africa as this contains an inner ring -
> and when I import my processed data into a Spatialite table with a
> polygon geometry column, and I use IsValid to test the polygon, I get
> a warning that it contains a self-crossing. If I simplify the polygon
> then this problem gets fixed but my polygon is now less accurate than
> before so not ideal.
>

Hi Chris,

I tried to warn you that very often OSM data sucks, and I tried to
suggest you much more reasonable alternatives.
apparently without any succes.

You chose to follow the more difficult path and now you are discovering
the price you have to pay.


> And any general suggestions on how to tackle this kind of problem
> would be welcome.
>

you can try calling ST_MakeValid(geom) to fix OSM broken polygons.

In most cases it should work, but obviously it cannot work miracles
in the most desperate cases (and you will surely find many).

bye Sandro

ckgoo...@gmail.com

unread,
Aug 31, 2024, 3:48:08 PMAug 31
to spatiali...@googlegroups.com
Hi Sandra,

> I tried to suggest you much more reasonable alternatives.
> apparently without any success

Not at all. I have a version of my atlas which works pretty well using data originally from the sources you provided. And thank you for that. I can wander around the atlas knowing what country, or next level down of admin area in that country, I am in plus know what ocean, sea, gulf or strait I am in. And the performance is great. No noticeable latency as I move around.

But there are gaps. Sometimes when I move around I get a generic "Land" message rather than the name of that land. And I couldn't find the Seychelles. And the Caspian Sea, as it is a lake, just comes up as my generic "Water" message. And I don't have control over the data to try and correct these problems.

So I started to look at OSM in more detail. I've got a process that gets me from raw OSM data to Spatialite polygons. I've learned a lot doing this and it has been fun. But now I have this problem which is either garbage in garbage out or something wrong with my algorithm. I frankly don't know which. I just know that using OSM data has great potential in terms of control over what is available to the user, along with rich information and classifications of data. Plus there is the possibility of looking at networks as well. If I can get it to work then it will be so great.

But there are huge challenges in all of this but then making accessible maps isn't easy. As I am finding out. Every time I solve one problem there is another slammed in my face. But as I say, it is quite fun.

Best, Chris
--
You received this message because you are subscribed to the Google Groups "SpatiaLite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spatialite-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/spatialite-users/3cf08308ada75254919cf68986659775%40lqt.it.

ckgoo...@gmail.com

unread,
Sep 1, 2024, 5:47:04 AMSep 1
to spatiali...@googlegroups.com
Hi,
Turns out it was sort of my algorithm. More of a coding problem. I was using a C++ stringstream class to output data which by default rounded numbers to 4 decimal places. So my coordinates were getting shortened and a tiny wiggle looked like it was backtracking on itself. When I set the precision to 9dp then the polygon is valid.
Best, Chris

-----Original Message-----
From: spatiali...@googlegroups.com <spatiali...@googlegroups.com> On Behalf Of a.fu...@lqt.it
Sent: 31 August 2024 18:52
To: spatiali...@googlegroups.com
Subject: Re: [SpatiaLite-Users] Polygons have self-crossings

Reply all
Reply to author
Forward
0 new messages