I have retrieved the map data for Puerto Rico with the following Overpass QL.
[out:json];
rel["ISO3166-1"=PR];
out geom;
I receive a response with 3 ways in it, which is curious because PR is just 2 islands. In looking at the first 2 ways, they both share the same begin and end point. I am stitching all the ways together programmatically, and so looks to me like an internal boundary, but it isn’t. You will notice the first way is pretty small. The second way is much larger, but they both have the same start/end point. Using my algorithm, if I see ways with common start/end points I just delete them as they are internal boundaries. This causes me to lose entirely the large island.
When I import the JSON into QGIS I get a perfectly fine PR. When I export from QGIS I’m left with two ways, which is correct.
Obviously my algorithm for stitching ways together is faulty. It generally works well, but in a few cases like this it fails. What am I doing wrong? What do I do with two linestrings with common start/end points? Is it true that parallel ways can’t happen in a single relation? What’s the logic for stitching ways together? I need to be able to do this programmatically. I don’t want to have to use QGIS, or any other external utility, to fix it.
Data returned edited for brevity.
"members": [
{
"type": "way",
"ref": 993017109,
"role": "outer",
"geometry": [
{ "lat": 18.4892101, "lon": -65.1825535 },
{ "lat": 18.3982670, "lon": -65.1579180 },
{ "lat": 18.3963140, "lon": -65.1575230 },
{ "lat": 18.3951220, "lon": -65.1575620 },
{ "lat": 18.3873420, "lon": -65.1572550 },
{ "lat": 18.3756450, "lon": -65.1571510 },
{ "lat": 18.3577910, "lon": -65.1575560 },
{ "lat": 18.3247310, "lon": -65.1538630 },
{ "lat": 18.3240090, "lon": -65.1541110 },
{ "lat": 18.2976090, "lon": -65.1611410 },
{ "lat": 18.2756240, "lon": -65.1667670 },
{ "lat": 18.2716390, "lon": -65.1678180 },
{ "lat": 18.2667310, "lon": -65.1689530 },
{ "lat": 18.2635880, "lon": -65.1694210 },
{ "lat": 18.1952780, "lon": -65.1713500 },
{ "lat": 18.1605520, "lon": -65.1373200 },
{ "lat": 18.1349650, "lon": -65.1120110 },
{ "lat": 18.1330236, "lon": -65.1100908 }
]
},
{
"type": "way",
"ref": 318735633,
"role": "outer",
"geometry": [
{ "lat": 18.4892101, "lon": -65.1825535 },
{ "lat": 18.4951936, "lon": -65.2042554 },
{ "lat": 18.4981530, "lon": -65.2271751 },
{ "lat": 18.4978821, "lon": -65.2503020 },
<snip about 700 lines>
{ "lat": 18.1071516, "lon": -65.1126043 },
{ "lat": 18.1074777, "lon": -65.1125419 },
{ "lat": 18.1330236, "lon": -65.1100908 }
]
},
}
third way omitted entirely as irrelevant.