tyrasd / osmtogeojson

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

The browser version of osmtogeojson produces different values than the node CLI #109

Open backspaces opened 5 years ago

backspaces commented 5 years ago

TLDR: I performed the following experiment which creates an osmtogeojson installation and uses it to create both a node and browser based osm to geojson transform.

They differ with the browser version apparently not placing the osm tags directly into the feature properties object.

Details: The methodology proceeds like this, using the overpass api to create a osm file for part of santa fe new mexico, and then use osmtogeojson to create the associated geojson.

mkdir osm; cd osm npm init -y npm install osmtogeojson curl "https://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A180%5D%5Bbbox%3A35.67514743608467%2C-105.9521484375%2C35.6929946320988%2C-105.93017578125%5D%3B%0Away%5Bhighway%5D%3B%0A(._%3B%3E%3B)%3B%0Aout%3B" > santafe.osm ./node_modules/osmtogeojson/osmtogeojson < santafe.osm > santafe.json

At this point we have an osm file and the associated node based json.

Next I run the osm.html file included in the attached zip. It uses a script tag for osmtogeojson.js (I used two version, one from ./node_modules, the other from unpkg.com CDN).

The html mainly runs code to import the node geojson, and to create a browser version of the geojson.

async function run() {
    window.osm = await xhrPromise('./santafe.osm', 'json')
    window.chrome = osmtogeojson(osm)
    window.node = await xhrPromise('./santafe.json', 'json')

    console.log('osm', osm)
    console.log('chrome', chrome)
    console.log('node', node)

    console.log('chrome', sample(chrome))
    console.log('node', sample(node))
}

Opening the console gives access to the two geojson objects, "chrome" and "node", in the window global object. Two "samples" are printed out to show the same feature, showing how they differ. Primarily the properties objects differ.

I've made the files available on: http://backspaces.net/temp/osm/ and http://backspaces.net/temp/osm.zip and the osm.html can be run by http://backspaces.net/temp/osm/osm.html

Whew! I hope this is not too complicated. I'm loving osmtogeojson, it's superb! I discovered the issue via #108 so hope to see a lot of osmtogeojson in browsers!