topojson / topojson-server

Convert GeoJSON to TopoJSON.
ISC License
117 stars 32 forks source link

customized top level properties are thrown out #14

Closed woodz- closed 6 years ago

woodz- commented 6 years ago

notes

  1. working without pipes but file based - input is the resulting output file from the previous converting step
  2. issue is even valid for geostitch

tooling and versions ├── d3-geo-projection@2.4.0 ├── ndjson-cli@0.3.1 ├── npm@3.10.10 ├── plugman@1.4.1 ├── shapefile@0.6.6 ├── topojson-server@3.0.0 └── topojson-simplify@3.0.2 $ node --version: v6.11.2

reproduce

  1. using "ne_10m_admin_0_countries.shp" from unzipped natural earth
  2. $ shp2json -n "./ne_10m_admin_0_countries.shp" > "ne_10m_admin_0_countries-ndjson.geojson"
  3. $ ndjson-map 'i = d.properties.ISO_A3, d.iso = i === "-99" ? undefined : i, i = d.properties.NAME_LONG, d.name = i === "-99" ? undefined : i, delete d.properties, d' < "ne_10m_admin_0_countries-ndjson.geojson" > "ne_10m_admin_0_countries_country_codes.json"
  4. $ geo2topo -q 1e5 -n countries="./ne_10m_admin_0_countries_country_codes.json" > "./ne_10m_admin_0_countries.topojson"

if you then look into "ne_10m_admin_0_countries.topojson", you should see the properties "iso" and "name" are gone, against many tutorials on the internet like this: medium, while they are in "ne_10m_admin_0_countries_country_codes.json"

could anybody confirm and maybe explain why this is happening?

here is a rather old sof discussion

mbostock commented 6 years ago

This is the expected behavior. If you want features with properties, you need to put them on a properties object, as defined in the GeoJSON specification, section 3.2. geo2topo does not propagate unknown fields.

woodz- commented 6 years ago

That makes sense, thank you for the tip @mbostock For me it's still misleading while I am referencing to your world-atlas. For my understanding, the properties object is not explicitly generated in the topojson output and your clever established d.id on the geojson's root will be gone like in my approach above. Do you confirm or do I miss something here? Anyways, my intent is to create a pull request and link it to here. You are welcome to reject it if I should have misunderstood the whole thing.

woodz- commented 6 years ago

link to pull request of the world-atlas repo: ensure custom properties propagation

mbostock commented 6 years ago

The world-atlas doesn’t include any properties. It only includes a unique identifier.