Thursday 24 November 2016

gdal - ogr2ogr too many GCP points - exceeds maximum number of characters in the command line


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.



Answer



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...