[gdal-dev] Neatline for USGS PDF maps

Even Rouault even.rouault at mines-paris.org
Sat Jan 19 07:28:53 PST 2013


Le samedi 19 janvier 2013 03:38:16, Eli Adam a écrit :
> Checking over some USGS topo PDFs, the neatline reported appears too
> large.  Has anyone else check this or noticed anything similar?
> Specific details below.

Eli,

Looking more closely at those files, I see that there are various registration 
blocks. The algorithm up to now was to select the registration block whose 
neatline covered the most area in terms of pixels. In the case of 
OR_Newport_North_20110824_TM_geo.pdf, those blocks are :
"UTM Grid and Projection"
"Orthoimage"
"Map Layers"
"Adjoining Quadrangles Diagram"

The number and names of blocks may change, but in all USGS topo PDFs samples 
I've tried, the "Map Layers" is always present and seems to the one that lead 
to the best results, so I've just pushed a change to select it when it is 
found.

You can use the following Python script to automate fetching the neatline and 
launching gdalwarp to use it :

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

from osgeo import gdal
import os
import sys

ds = gdal.Open(sys.argv[1])
neatline_wkt = ds.GetMetadataItem("NEATLINE")
ds = None

f = open('cutline.csv', 'wt')
f.write('id,WKT\n')
f.write('1,"%s"\n' % neatline_wkt)
f.close()

os.system('gdalwarp %s %s.tif ' % (sys.argv[1], sys.argv[1]) +
          '-crop_to_cutline -cutline cutline.csv -overwrite')

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Best regards,

Even


More information about the gdal-dev mailing list