digidem / mapeo-core

Library for creating custom geo data and syncronizing via a peer to peer network
23 stars 2 forks source link

feat: Add createDataStream() for exporting data, with optional filter #111

Closed gmaclennan closed 3 years ago

gmaclennan commented 3 years ago

This adds a new method mapeo.createDataStream() which returns a ReadableStream of OSM data in Mapeo as either GeoJSON or a Shapefile.

This is similar functionality to the current mapeo.exportData() method, but it returns a stream rather than writing directly to a file.

It accepts opts.filter which can be a mapeo-entity-filter: an array that defines a filter for OSM objects in Mapeo. This is most useful for filtering data based on the value of certain tags on the data, e.g. to only export data of a certain type.

This is necessary for the WCMC work, for which we want to filter only data with the tag protection_title equal to icca. This would be written as:

mapeo.createDataStream({ filter: ['==', 'protection_title', 'icca'] })

Next steps:

gmaclennan commented 3 years ago

Thanks for the very helpful review @noffle. A lot of the suggestions relate to code that I copied from other tests; at some point we should clean up the mapeo core tests, but I don't think it's urgent. I did notice that actual and expected are the wrong way round in lots of tests, which is confusing initially when you get a failing test.

Regarding the package-lock.json, see https://github.com/digidem/mapeo-core/pull/108#issuecomment-731640568.