I decided to re-visit this problem where TransDEM is unable to find and crop out margins in recent USGS GEOPDF topo maps. This time I am using a 2021 USGS GEOPDF. As before, I have installed GDAL 1.11.1 from the TransDEM site (as recommended in the TransDEM documentation). As before, the neatline metadata that GDAL finds in the geopdf doesn't look right, and Transdem can't find the raster margins.
Just for the heck of it, I asked Claude (AI) to find and crop out everything except the actual map image and explain the process. It works. It's interesting to see how Claude tackled the problem.
First of all, here's the prompt I gave to Claude AI:
https://prd-tnm.s3.amazonaws.com/Staged ... TM_geo.pdf
Crop out everything in this geopdf file except the map image, then save it as a new geopdf file. Be sure to preserve all of the georeferencing information in the file. If the neatline metadata in the geopdf file is wrong, fix it. Verify that I will be able to run my GDAL 1.11.1 version of gdalinfo against the new geopdf file without encountering "ERROR 4: Unable to open EPSG support file gcs.csv" (I don't want to have to install support files like gcs.csv). Finally, explain, step-by-step, what you did.
And here's the result, the cropped geopdf:
https://drive.google.com/file/d/1cs1TiD ... drive_link
Here's what Claude AI says it did, step by step. I haven't verified any of its assertions, but they're interesting.
1. Diagnosed the file structure. The original is a 3600×4350 px (150 DPI), 24″×29″ page US Topo GeoPDF with a title/logo header, the actual map inside a neatline border, and a legend/scale-bar footer — plus multiple togglable layers (topo cartography, satellite imagery, shaded relief, PLSS grid), three of which (Images, Shaded Relief, PLSS) are OFF by default.
2. Found the true neatline. GDAL's own NEATLINE metadata tag turned out to be describing the wrong viewport — the PDF actually contains three separate georeferencing viewports (main map, a locator inset, and an adjoining-sheet diagram), and the one GDAL was reading from doesn't correspond to the visible map border at all. I located the real border by detecting the border line pixel-by-pixel (a gray frame at columns 418–3161, rows 360–3773), then confirmed it precisely: converting those pixel corners through the geotransform lands within about a meter of the expected round quad boundary (-121.75°/-121.625°W, 36.875°/37.0°N) — exactly what a 7.5-minute quadrangle should be.
3. Cropped to that pixel window, carrying the same rotation/scale terms in the geotransform (this map is printed true-north-up, which is rotated ~0.79° from the UTM grid — that's normal for USGS quads, not an error).
4. Caught and fixed a rendering trap. My first crop used GDAL's own PDF rasterizer, which ignored the PDF's default layer visibility and silently rendered the satellite-imagery layer instead of the topo cartography. I redid the rasterization with pdftoppm, which respects the PDF's default OCG (layer) state, and rebuilt the crop from that correct image.
5. Rebuilt the GeoPDF using ISO32000 encoding (matching the original's own encoding style) with the corrected NEATLINE polygon.
6. Addressed the GDAL 1.11.1 gcs.csv requirement. I compared byte-for-byte against the original file and found GDAL 3.8.4 had injected an extra /EPSG 26910 shortcut key into the output's /GCS dictionary that the original file doesn't have (the original only stores a full, self-contained WKT string with no EPSG/AUTHORITY references anywhere). That extra key is exactly the kind of thing that sends old GDAL/PROJ4 hunting for gcs.csv. I stripped it with pikepdf, then confirmed the byte string EPSG appears zero times anywhere in the final file — matching the original's proven-safe structure exactly.
7. Verified the result: correct corner coordinates, correct geotransform, correct NEATLINE, and a visual render showing the clean cartographic map with no collar.