tyrasd / osmtogeojson

convert osm to geojson
http://tyrasd.github.io/osmtogeojson/
MIT License
683 stars 112 forks source link

Mark non closed multiploygon relation as tainted #141

Open HarelM opened 1 year ago

HarelM commented 1 year ago

Hi, I have the following osm relation:

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="Overpass API 0.7.59 e21c39fe">
<note>The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.</note>
<meta osm_base="2023-01-17T10:17:39Z"/>

<relation id="15260061" version="1" timestamp="2023-01-11T06:35:48Z" changeset="131131112" uid="9200198" user="חיליק אגמון">
<bounds minlat="32.6360783" minlon="35.1143645" maxlat="32.6488656" maxlon="35.1256148"/>
<member type="way" ref="93324516" role="outer">
<nd lat="32.6434407" lon="35.1239131"/>
<nd lat="32.6429348" lon="35.1242565"/>
<nd lat="32.6423024" lon="35.1240419"/>
<nd lat="32.6398812" lon="35.1249216"/>
<nd lat="32.6368636" lon="35.1248358"/>
<nd lat="32.6360783" lon="35.1240178"/>
<nd lat="32.6367356" lon="35.1225380"/>
<nd lat="32.6396102" lon="35.1217888"/>
<nd lat="32.6420133" lon="35.1203297"/>
<nd lat="32.6433323" lon="35.1190637"/>
<nd lat="32.6436214" lon="35.1170681"/>
<nd lat="32.6419950" lon="35.1156632"/>
<nd lat="32.6410221" lon="35.1158614"/>
<nd lat="32.6408918" lon="35.1157737"/>
</member>
<member type="way" ref="1130831949" role="outer">
<nd lat="32.6409447" lon="35.1150447"/>
<nd lat="32.6416163" lon="35.1147643"/>
<nd lat="32.6420907" lon="35.1146143"/>
<nd lat="32.6428806" lon="35.1143645"/>
<nd lat="32.6437660" lon="35.1145576"/>
<nd lat="32.6460967" lon="35.1158665"/>
<nd lat="32.6476686" lon="35.1193212"/>
<nd lat="32.6488089" lon="35.1214729"/>
<nd lat="32.6488656" lon="35.1215798"/>
<nd lat="32.6475601" lon="35.1228901"/>
<nd lat="32.6463964" lon="35.1236346"/>
<nd lat="32.6457896" lon="35.1229475"/>
<nd lat="32.6467652" lon="35.1251791"/>
<nd lat="32.6459690" lon="35.1256148"/>
<nd lat="32.6443803" lon="35.1242350"/>
<nd lat="32.6436937" lon="35.1244710"/>
<nd lat="32.6434407" lon="35.1239131"/>
</member>
<tag k="landuse" v="residential"/>
<tag k="name" v="הזורע"/>
<tag k="name:cs" v="ha-Zorea"/>
<tag k="name:en" v="Hazzore'a"/>
<tag k="name:fr" v="Hazorea"/>
<tag k="name:he" v="הזורע"/>
<tag k="place" v="village"/>
<tag k="type" v="multipolygon"/>
<tag k="website" v="https://www.hazorea.org.il/"/>
</relation>

</osm>

It contains two ways and it should be a closed polygon, but evidently the ways only touch on one end but not on the other - so basically this is an "invalid" OSM relation. When using this library to convert it to a geojson I get a polygon, I would expect to get either a warning or a a flag when using verbose options.

Am I missing anything?

Here's my full code:


import osmtogeojson from "osmtogeojson";
fetch("https://overpass-api.de/api/interpreter", {
  method: "POST",
  body: "rel(15260061);out meta geom;"
}).then(r => r.text()).then(t => {
  console.log(t);
  const parser = new DOMParser();
  const xmlDoc = parser.parseFromString(t, "text/xml");
  let geo = osmtogeojson(xmlDoc, {verbose: true});
  console.log(geo);
  console.log(geo.features[0].properties.tainted);
});

https://stackblitz.com/edit/typescript-j7uzad?file=index.ts