nypl-spacetime / map-vectorizer

An open-source map vectorizer
MIT License
647 stars 61 forks source link

Windows 10 implementation #28

Closed ghost closed 7 years ago

ghost commented 7 years ago

Thanks for making what looks to be a great program. I'm having an issue getting this up & running. Somewhat similar to the one here: https://github.com/nypl-spacetime/map-vectorizer/issues/26 in that GIMP posts the "Unknown option -50" error. Possibly other things are going wrong, too. Playing around by sequentially adding options (by myself in the command line), gimp-brightness-contrast seems to be the first one that creates the issue.

I've pasted my console output below & am uploading my log. Any advice you have on getting this working would be super helpful.

consoleoutput.txt

py-log.txt

mgiraldo commented 7 years ago

hmmm... it's hard for me to test on Windows. is this the command that produces the error?

C:\GIMP2\bin\gimp-2.8.exe -i -b '(let* ((image (car (file-tiff-load RUN-NONINTERACTIVE "test.tif" "test.tif"))) (drawable (car (gimp-image-get-layer-by-name image "Background")))) (gimp-selection-none image) (gimp-brightness-contrast drawable -50 95) (gimp-threshold drawable 160 255) (gimp-file-save RUN-NONINTERACTIVE image drawable "test\test-threshold-tmp.tif" "test\test-threshold-tmp.tif") (gimp-image-delete image))' -b '(gimp-quit 0)'

i'm thinking that maybe Windows doesn't like the single quotes... try changing line 42 in vectorize_map.py to:

command = gimp_path + ' -i -b \'' + gimpcommand + '\' -b \'(gimp-quit 0)\''

to

command = '"' + gimp_path + '" -i -b "' + gimpcommand + '" -b "(gimp-quit 0)" '

basically i'm trying to produce a command like the one in this Stack Overflow question.

also line 39 may need to escape the double quotes (not sure if it will work and i cannot test):

gimpcommand = '(let* ((image (car (file-tiff-load RUN-NONINTERACTIVE \"' + inputfile + '\" \"' + inputfile + '\"))) (drawable (car (gimp-image-get-layer-by-name image \"Background\")))) (gimp-selection-none image) ' + contraststring + ' ' + thresholdstring + ' (gimp-file-save RUN-NONINTERACTIVE image drawable \"' + thresholdfile + '\" \"' + thresholdfile + '\") (gimp-image-delete image))'

end result would be something like:

"C:\GIMP2\bin\gimp-2.8.exe" -i -b "(let* ((image (car (file-tiff-load RUN-NONINTERACTIVE \"test.tif\" \"test.tif\"))) (drawable (car (gimp-image-get-layer-by-name image \"Background\")))) (gimp-selection-none image) (gimp-brightness-contrast drawable -50 95) (gimp-threshold drawable 160 255) (gimp-file-save RUN-NONINTERACTIVE image drawable \"test\test-threshold-tmp.tif\" \"test\test-threshold-tmp.tif\") (gimp-image-delete image))" -b "(gimp-quit 0)"

it could also be that, since Windows uses backslashes in paths, it is freaking out the command string. try replacing the back slashes in the original command to forward slashes (or with double back slashes):

C:\GIMP2\bin\gimp-2.8.exe -i -b '(let* ((image (car (file-tiff-load RUN-NONINTERACTIVE "test.tif" "test.tif"))) (drawable (car (gimp-image-get-layer-by-name image "Background")))) (gimp-selection-none image) (gimp-brightness-contrast drawable -50 95) (gimp-threshold drawable 160 255) (gimp-file-save RUN-NONINTERACTIVE image drawable "test/test-threshold-tmp.tif" "test/test-threshold-tmp.tif") (gimp-image-delete image))' -b '(gimp-quit 0)'
ghost commented 7 years ago

Thanks for such a quick response & I appreciate you working with me despite you not having a Windows machine to test on.

With your suggested change to line 42, I receive the following error: 'C:\GIMP2\bin\gimp-2.8.exe" -i -b "' is not recognized as an internal or external command, operable program or batch file.

So I removed the first set of quotes in line 42 to give: command = gimp_path + ' -i -b "' + gimpcommand + '" -b "(gimp-quit 0)" '

This fixes the original error. However, a new one crops up: "Unbound variable test.tif". Here is the GIMP call: C:/GIMP2/bin/gimp-2.8.exe -i -b "(let* ((image (car (file-tiff-load RUN-NONINTERACTIVE "test.tif" "test.tif"))) (drawable (car (gimp-image-get-layer-by-name image "Background")))) (gimp-selection-none image) (gimp-brightness-contrast drawable -50 95) (gimp-threshold drawable 160 255) (gimp-file-save RUN-NONINTERACTIVE image drawable "test\test-threshold-tmp.tif" "test\test-threshold-tmp.tif") (gimp-image-delete image))" -b "(gimp-quit 0)"

One set of backslashes to line 39 don't change the GIMP command. A double set (i.e. escaping the original backslashes) produces errors saying GIMP can't parse the command. My guess is the forward slash issue isn't causing this, though I'm happy to test it out.

Possibly something like this? Other ideas? http://www.gimptalk.com/index.php?/topic/50707-script-fu-unbound-variable-error/

py-log.txt

ghost commented 7 years ago

This is obvious in retrospect, but the GIMP command was getting thrown off by the quotes which would seem to end the command at test.tif. Changing line 39 to: gimpcommand = '(let* ((image (car (file-tiff-load RUN-NONINTERACTIVE ' + inputfile + ' ' + inputfile + '))) (drawable (car (gimp-image-get-layer-by-name image "Background")))) (gimp-selection-none image) ' + contraststring + ' ' + thresholdstring + ' (gimp-file-save RUN-NONINTERACTIVE image drawable ' + thresholdfile + '" "' + thresholdfile + ') (gimp-image-delete image))'

(i.e. removing quotation marks) fixes this. I'm still getting some other errors & will update when I've taken a closer look.

mgiraldo commented 7 years ago

try not working with the python but with the output of the log file. what you are trying to find is a command line command that will produce the proper test image. so I suggest working with that. for example paste this in the Windows command prompt:

"C:\GIMP2\bin\gimp-2.8.exe" -i -b "(let* ((image (car (file-tiff-load RUN-NONINTERACTIVE \"test.tif\" \"test.tif\"))) (drawable (car (gimp-image-get-layer-by-name image \"Background\")))) (gimp-selection-none image) (gimp-brightness-contrast drawable -50 95) (gimp-threshold drawable 160 255) (gimp-file-save RUN-NONINTERACTIVE image drawable \"test\test-threshold-tmp.tif\" \"test\test-threshold-tmp.tif\") (gimp-image-delete image))" -b "(gimp-quit 0)" and play around with the slashes and quotes. at some point you should get a working command. then it is a matter of figuring what to change in python to produce the proper strong.

On Feb 1, 2017, at 15:17, corydeburd notifications@github.com wrote:

This is obvious in retrospect, but the GIMP command was getting thrown off by the quotes which would seem to end the command at test.tif. Changing line 39 to: gimpcommand = '(let* ((image (car (file-tiff-load RUN-NONINTERACTIVE ' + inputfile + ' ' + inputfile + '))) (drawable (car (gimp-image-get-layer-by-name image "Background")))) (gimp-selection-none image) ' + contraststring + ' ' + thresholdstring + ' (gimp-file-save RUN-NONINTERACTIVE image drawable ' + thresholdfile + '" "' + thresholdfile + ') (gimp-image-delete image))'

(i.e. removing quotation marks) fixes this. I'm still getting some other errors & will update when I've taken a closer look.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

ghost commented 7 years ago

Thanks, this is a good suggestion. Will report back.

ghost commented 7 years ago

After playing around a bit, I think it is the minus sign in the -50 that causes the original error ("unknown option"). If you change that to e.g. just 50 it's fine. So I escaped the minus to -50. This fixes the original error.

GIMP then produces the following command line output: GIMPOutput.txt

It then hangs (at least for 10 minutes). If I force quit, the test-threshold-tmp.tif file is not created. Do you have any advice on fixing this part? Thanks again. py-log.txt

mgiraldo commented 7 years ago

it should work with the minus. my point is that something before it must be wrong so that gimp believes that -50 is an execution flag like for example -b. my bet is it is a matter of quotes (single and double) and file paths (forward and back slashes)

but again I cannot test. in summary, a negative 50 value in brightness should be accepted

On Feb 1, 2017, at 16:47, corydeburd notifications@github.com wrote:

After playing around a bit, I think it is the minus sign in the -50 that causes the original error ("unknown option"). If you change that to e.g. just 50 it's fine. So I escaped the minus to -50. This fixes the original error.

GIMP then produces the following command line output: GIMPOutput.txt

It then hangs (at least for 10 minutes). If I force quit, the test-threshold-tmp.tif file is not created. Do you have any advice on fixing this part? Thanks again. py-log.txt

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

ghost commented 7 years ago

I've played around some more & you are correct. For other Windows users, here's a correct GDAL command & python code (attached as .txt).

C:\GIMP2\bin\gimp-2.8.exe -i -b "(let* ((image (car (file-tiff-load RUN-NONINTERACTIVE \"test.tif\" \"test.tif\"))) (drawable (car (gimp-image-get-layer-by-name image \"Background\")))) (gimp-selection-none image) (gimp-brightness-contrast drawable -50 95) (gimp-threshold drawable 160 255) (gimp-file-save RUN-NONINTERACTIVE image drawable \"test\test-threshold-tmp.tif\" \"test\test-threshold-tmp.tif\") (gimp-image-delete image))" -b "(gimp-quit 0)"

vectorize_map.txt

I'm experiencing some other issues with the GDAL package, but I'm hoping to resolve those on my own. Thanks again.