[gdal-dev] Neatline for USGS PDF maps

Eli Adam eadam at co.lincoln.or.us
Wed Apr 17 08:34:13 PDT 2013


I found this in drafts and it appears I failed to send it.  Sorry for
delay.  Sent partly for the list archives at this point.

On Sat, Jan 19, 2013 at 8:14 AM, Even Rouault
<even.rouault at mines-paris.org> wrote:
>> 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.

--config GDAL_PDF_NEATLINE is very helpful.  Did you find the
registration name blocks with one of the supporting PDF libraries?  Is
it possible to find these multiple registration name blocks from gdal?
 (I tried: gdalinfo --debug on without success.)

Thanks for the many recent improvements for the USGS topo PDFs.
--config GDAL_PDF_RENDERING_OPTIONS is very useful.

>>
>> 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')
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is great.  I've added it to the wiki,
http://trac.osgeo.org/gdal/wiki/USGS_PDF_Topo

>
> If you're interested in only the raster part, let's imagine that the above
> script is called cutline.py, you can try the following :
>
> export GDAL_PDF_RENDERING_OPTIONS=RASTER
> (or set GDAL_PDF_RENDERING_OPTIONS=RASTER on windows)
>
> python cutline.py your.pdf
>
> nearblack your.pdf -o your_rgba.pdf -of GTiff -setalpha -color 0,0,0 \
>                 -color 255,255,255
>

I interpreted the above as:
nearblack your.tif -o your_rgba.tif -of GTiff -setalpha -color 0,0,0
-color 255,255,255
Where your.tif is the output from cutline.py and your_rgba.tif is the
output from nearblack.

Thanks, Eli


>>
>> Best regards,
>>
>> Even
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list