mbloch/mapshaper

-split command line option not working for attribute name that contains "-"

Closed this issue · 1 comments

I am trying to use the -split command with an attribute with name ISO3166-1.

This was working until mapshaper v0.4.161, but with the current version, the name is interpreted as an expression, and I run into the following error:

$ npx mapshaper@0.6.43 -i split-minimal-example.geojson -split ISO3166-1 -o
[split] ReferenceError in expression [ISO3166-1]: ISO3166 is not defined
Run mapshaper -h to view help

As far as I see, there is no way to escape the -, or disable expression parsing for -split, but of course I could be missing something.

Content of split-minimal-example.geojson for the reproduction above:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": { "ISO3166-1": "layer1" },
      "geometry": {
        "coordinates": [
          [
            [-1, 1],
            [-1, -1],
            [1, -1],
            [1, 1],
            [-1, 1]
          ]
        ],
        "type": "Polygon"
      }
    }
  ]
}

Hi! Here is one workaround for this problem (this is the usual way to reference a data property in an expression when the property name is not a valid JavaScript variable name):

mapshaper split-minimal-example.geojson -split d["ISO3166-1"] -o

Most of the time I'm sure that users want to use a single data field for splitting, rather than a more complex expression... so I just committed a change to make mapshaper accept commands like -split ISO3166-1.

Thanks for the feedback :)