3

I am trying to adjust a vector polygon dataset using ogr2ogr spline transformation with cmd commands like:

C:\\OSGeo4W64\\bin\\ogr2ogr.exe -f "ESRI Shapefile" C:\\path\\output.shp -order 3 -tps -gcp -13163.1627 271026.6107 -13274.2879 271201.236 -gcp 64464.2679538 -210398.439419 64390.5172491 -210240.678326 -gcp 98432.5310433 -181184.99898 98313.298804 -180985.232826 C:\\path\\input.shp

Also I try to do this inside Python:

import os
control_points = (
"-gcp -13163.1627 271026.6107 -13274.2879 271201.236 "
"-gcp -12706.1672 271461.5611 -12843.4862 271599.4093 "
"-gcp 98432.5310433 -181184.99898 98313.298804 -180985.232826 "
"-gcp 64464.2679538 -210398.439419 64390.5172491 -210240.678326 "
)
command = 'C:\\OSGeo4W64\\bin\\ogr2ogr.exe -f "ESRI Shapefile" C:\\path\\output.shp -order 3 -tps ' + control_points + 'C:\\path\\input.shp'
print command
os.system(command)

With a few points like this it works fine. But actually I have much more control points, more than 1000. I need to use them all because the dataset covers the entire country. And when I write into the command all my GCPs, the Python script doesn't produce any output at all (no errors), and when I paste this command into the Command prompt it just cuts my command and then gives an error from ogr2ogr.

I found out that the maximum number of characters in the command prompt is 8191 but my command has 79792 characters.

So, how can I use ogr2ogr with hundreds of control points? Is there a way to store them in some batch file or variable? The GDAL page only says that -gcp option may be provided multiple times to provide a set of GCPs, directly in the command.

nadya
  • 2,471
  • 1
  • 23
  • 35

1 Answers1

7

This page, which lists general command-line options, says there's an "--optfile" argument:

Read the named file and substitute the contents into the command line options list. Lines beginning with # will be ignored. Multi-word arguments may be kept together with double quotes.

Putting your GCPs arguments in a text file might let you work around the command-line length limitation.

mikewatt
  • 5,083
  • 9
  • 21
  • 1
    Thank you for the tip, it works with control_points = "--optfile C:\\path\\gcp.txt " But I don't understand their words about double quotes, because inside the gcp.txt I had to write just -gcp -13163.1627 271026.6107 -13274.2879 271201.236 -gcp -12706.1672 271461.5611 -12843.4862 271599.4093 without quotes, because with quotes it was not working. – nadya May 17 '17 at 14:25
  • 1
    Glad to hear it works! Do you have an example of how you were including the quotes?

    I would assume that they would work in the same was as on the command line, where ogr2ogr -gcp "-12706.1672 271461.5611 -12843.4862 271599.4093" would cause "ogr2ogr" to be argv[0], "-gcp" to be argv[1], and "-12706.1672 271461.5611 -12843.4862 271599.4093" to be argv[2].

    – mikewatt May 17 '17 at 18:05
  • I tried to quote every line "-gcp -13163.1627 271026.6107 -13274.2879 271201.236 " "-gcp -12706.1672 271461.5611 -12843.4862 271599.4093 " like it was in my Python variable. Your example with quoting only coordinates is also not working. Only without any quotes it works. – nadya May 18 '17 at 10:10