mbloch / mapshaper

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

How do I use `merge-layers` in the web interface? #334

Closed amandabee closed 5 years ago

amandabee commented 5 years ago

172 is related but seems to predate the merge-layers function. #268 also seems related but the issue appears to be resolved and I'm still hitting walls.

I'm using mapshapers web interface and it looks like I should be able to collapse two layers with merge-layers:

$ help merge-layers
Command
  -merge-layers merge multiple layers into as few layers as possible

Options
  force         merge layers with inconsistent data fields
  name=         rename the edited layer(s)
  target=       layer(s) to target (comma-sep. list)

But the target= attribute isn't working:

$ merge-layers target=bayarea_county,california_places_clipped
[merge-layers] Use the target= option to specify multiple layers for merging

I tried putting the list in quotes and got:

$ merge-layers target='"bayarea_county","california_places_clipped"'
Missing target: "bayarea_county","california_places_clipped"
Available layers:   [1]  bayarea_county
  [2]  california_place_clipped

How do I use merge-layers in the web interface?

mbloch commented 5 years ago

Hi, Mapshaper is getting confused by the nested quotation marks in your command. The command should work if you use: merge-layers target='bayarea_county,california_places_clipped' The command should also work without any quotes: merge-layers target=bayarea_county,california_places_clipped

Quotes around command line arguments are required if there are spaces in the names, otherwise generally not needed.

An exception: Strings in JavaScript expressions need to be quoted, and the entire JS expression should be in quotes as well. -each, -filter and several other commands take JS expressions.

mbloch commented 5 years ago

@amandabee I re-read your comment... I see that you originally used what looks like the correct syntax (without nested quotes).

I'm attaching a .zip file containing two GeoJSON files. If you drop the files onto the web UI and run merge-layers target=group1,group2, the layers should get merged. If merging works for you with my test files but not your own data files, please send me your files and I will investigate. group.zip

amandabee commented 5 years ago

Ahh. Okay. With that first syntax I do get an error:

$ merge-layers target=bayarea_county,california_place_clipped
Fields [PLACE, PLACENUM, NAME, OBJECTID, FIPSSTCO] are missing from one or more layers

I assume this means that I need to ensure that both layers have the same fields before I can merge them. Can I just force a merge?

If you can help me get over this hurdle, I'm happy to put this particular walk through together as a tutorial and add it to the wiki.

mbloch commented 5 years ago

Yes, you can force a merge by adding the "force" option to the command.

To see the all the options for a particular command, in the console you can run, e.g., -h merge-layers.

There's also a Wiki page on Github: https://github.com/mbloch/mapshaper/wiki/Command-Reference#-merge-layers, which sometimes has more detail on using a command than the built-in command line help.

amandabee commented 5 years ago

Thank you.

I was working on getting a local basemap that I can import to Datawrapper. I added it to the Wiki as a tutorial, so other folks can learn from it.