Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown option name '-spat' #95

Closed
bertday opened this issue Jan 4, 2023 · 2 comments
Closed

Unknown option name '-spat' #95

bertday opened this issue Jan 4, 2023 · 2 comments

Comments

@bertday
Copy link
Contributor

bertday commented Jan 4, 2023

Hello!

I'm trying to load in a GeoJSON file into a Postgres database, filtering by a bounding box with -spat (docs).

Here is a minimal example:

import ogr2ogr from 'ogr2ogr';

(async () => {
  await ogr2ogr(
    '/Users/me/parcels.json',
    {
      options: [
        '-spat', '-87.94011408252348 41.64454312178303 -87.5241371038952 42.023038586147585',
      ],
    }
  );
})();

That throws an error:

ERROR 6: Unknown option name '-spat'
    at __node_internal_genericNodeError (internal/errors:863:15)
    at exithandler (child_process:412:12)
    at emit (events:513:28)
    at maybeClose (internal/child_process:1091:16)
    at <anonymous> (internal/child_process:449:11)
    at emit (events:513:28)
    at <anonymous> (net:313:12)
    at callbackTrampoline (internal/async_hooks:130:17)

If I take the cmd from ogr2ogr and run it by hand in the shell, it runs fine.

Interestingly, in more complex examples I can sometimes get -spat to work depending on where it is in my options array. It seems to work if it comes before -nlt, but not after. I've tried quoting it and that didn't help.

@bertday
Copy link
Contributor Author

bertday commented Jan 5, 2023

Problem solved; I needed to pass the -spat values in as individual arguments. Helpful find:

OSGeo/gdal#1066

I'm sure this is just a child_process thing, but I had a bear of a time with it. I'm wondering if maybe there could be an input-validation step before calling the shell command, maybe one that looks for spaces in arguments and spits out a warning to break them up? I'd be happy to do a PR if that sounds desirable.

@wavded
Copy link
Owner

wavded commented Jan 5, 2023

Glad you figured it out. I don't think we want to assume arguments should be split up by space. We just pass them to the raw ogr2ogr command. Given the breathe of commands you can run with ogr2ogr, this library doesn't try to make many assumptions as to how it will be used.

@wavded wavded closed this as completed Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants