mbloch / mapshaper

Tools for editing Shapefile, GeoJSON, TopoJSON and CSV files
http://mapshaper.org
Other
3.74k stars 532 forks source link

hoist option #607

Closed indus closed 11 months ago

indus commented 11 months ago

This option would allow to move properties to the root level of features like so:

mapshaper `
-rectangle bbox=5.98,47.30,15.01,54.98 `
-each "id='Germany';tippecanoe={minzoom:1,maxzoom:2,layer:'bbox'};untouched='still in properties'" `
-o bboxDE_hoisted.json hoist="id,tippecanoe"

Output bboxDE_hoisted.json:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": { "type": "Polygon", "coordinates": [[[5.98, 47.3],[15.01, 47.3],[15.01, 54.98],[5.98, 54.98],[5.98, 47.3]]]},
      "properties": { "untouched": "still in properties" },
      "id": "Germany",
      "tippecanoe": { "minzoom": 1, "maxzoom": 2, "layer": "bbox" }
    }
  ]
}

The GeoJSON extension of Tippecanoe is the main reason I want this feature. The suggested postprocessing step with ndjson-cli does not always work and is a step I would like to avoid.

This option is intentionally designed generic (and not tippecanoe specific) because I think it can be useful in other situations as well. For example having id on root level is not uncommon and sometimes needed as it is part of the GeoJSON Standard

mbloch commented 11 months ago

Thanks for this contribution! I fixed one thing (hoisting was modifying the original data layer -- we only want to apply it to the -o command where it is used), and added a test.

indus commented 11 months ago

Thanks for accepting this feature. Looks like I only did 20% of the work. I hope I can do better next time.