mbloch / mapshaper

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

Trouble merging two exported geojson files #237

Closed tonywr71 closed 5 years ago

tonywr71 commented 6 years ago

I started with the Australian government geojson data for ACT and NSW, found here(NSW) and here (ACT) then I simplified each file using Visvalingam/weighted down to two percent (2%), then I exported them.

Next I decided to try to merge them. I couldn't figure out how to do it online, even though I could open the console (can it be done there?), so, instead, I ran npm install -g mapshaper and attempted to run from the command line. I tried: mapshaper -i suburb-2-act.geojson suburb-2-nsw.geojson combine-files -merge-layers -o actnsw.geojson

But it gave me the following error: [merge-layers] Error: Fields missing from one or more layers: nsw_locali, nsw_loca_1, nsw_loca_2, nsw_loca_3, nsw_loca_4, nsw_loca_5, nsw_loca_6, nsw_loca_7, act_locali, act_loca_1, act_loca_2, act_loca_3, act_loca_4, act_loca_5, act_loca_6, act_loca_7

I assume it is because those are extra fields our gov has put in the file, and because the fields aren't in both files, it bombs out. Is there a way to get it to ignore the case where the fields are missing?

All I am really attempting to achieve is appending the data from a number of files into a single file, without going to too much effort.

mbloch commented 6 years ago

You're right, -merge-layers is failing because it requires all input layers to have the same set of data fields.

You could get the layers to merge by filtering your data fields to retain only shared fields, like this:

mapshaper -i suburb-2-act.geojson suburb-2-nsw.geojson combine-files -filter-fields loc_pid,FID -merge-layers -o actnsw.geojson

If you want to retain some of the data in the inconsistently-named fields, you could rename those fields before trying to merge the files. The -rename-fields command can help with that.

I'll look into how best to support merging layers from different files in the web interface. I'll also look into allowing layers with inconsistent fields to merge.

Thanks, mbloch

mbloch commented 5 years ago

The -merge-layers command now has a force option, which allows merging layers with incompatible data fields.