wavded / ogr2ogr

An ogr2ogr wrapper library
MIT License
216 stars 46 forks source link

Currently can't provide custom args when specifying a custom command #79

Closed zachsa closed 2 years ago

zachsa commented 3 years ago

Hi,

I previously submitted a pull request for allowing for switching the command to use ogr2ogr via Docker (https://github.com/wavded/ogr2ogr/pull/60). However I've just checked now and it's not working. Looking at the code I'm actually not sure that it ever worked... I apologise!

I would like to use this feature now though, so I would like to fix it.

Looking at the run function: https://github.com/wavded/ogr2ogr/blob/master/index.ts#L147-L170, it doesn't seem like it's possible to specify an alternative command that requires args.

for example, If I try to run via docker (this is currently in the readme):

ogr2ogr('/home/.../path/to/spatial/file', {
  command: 'docker run -v /home/:/home --rm osgeo/gdal ogr2ogr',
})

Then I get an error:

  Error: spawn docker run -v /home/:/home --rm osgeo/gdal ogr2ogr ENOENT
      at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
      at onErrorNT (node:internal/child_process:477:16)
      at processTicksAndRejections (node:internal/process/task_queues:83:21)

In the code

    let {stdout, stderr} = await new Promise<RunOutput>((res, rej) => {
      let proc = execFile(
        command,
        args,
        {env, timeout: this.timeout, maxBuffer: this.maxBuffer},
        (err, stdout, stderr) => {
          if (err) rej(err)
          res({stdout, stderr})
        }
      )
      if (this.inputStream && proc.stdin) this.inputStream.pipe(proc.stdin)
    })

It looks like the command should actually just be docker, and the args should be ['run', '-v', etc. etc., ... then the ogr2ogr args].

But currently there is no way of specifying this

wavded commented 3 years ago

Good point, maybe we add a commandArgs option like:

ogr2ogr('/home/.../path/to/spatial/file', {
  command: 'docker',
  commandArgs: ['run', '-v /home/:/home', '--rm', 'osgeo/gdal', 'ogr2ogr'],
  options: ['ogr2ogr args']
})

Thoughts?

zachsa commented 3 years ago

I will have a look sometime this week and make a pull request

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 2 years ago

This issue was closed because it has been stalled for 5 days with no activity.

zachsa commented 2 years ago

Sorry, I never got round to this

jgrocha commented 1 year ago

One possible workaround is to create a small shell script that receives all parameters.

cat /usr/local/bin/dk_ogr2ogr.sh 
#!/bin/bash

docker run -v /tmp:/data --rm osgeo/gdal ogr2ogr $@

Then use the script, using options['command'] = "/usr/local/bin/dk_ogr2ogr.sh"

It works, but it would be nice to support this on ogr2ogr module.