2

I'm trying to remove the orthoimage layer from a USGS GeoSpatial pdf 7.5' topo quad. I can query the layer names:

ogrinfo NM_Canada_Ojitos_20110201_TM_geo_enabled.pdf -mdd LAYERS

Which produces this output:

INFO: Open of `NM_Canada_Ojitos_20110201_TM_geo_enabled.pdf'
      using driver `PDF' successful.
Metadata:
  CREATION_DATE=D:20110201173212Z
  CREATOR=ESRI ArcSOC 9.2.0.1324
  NEATLINE=POLYGON ((332090.904748664 4041071.96353292,331811.437879469 4027142.26667624,320584.088282388 4027367.51725229,320863.5
515158 4041297.21410897,332090.904748664 4041071.96353292))
Metadata (LAYERS):
  LAYER_00_NAME=Map_Collar
  LAYER_01_NAME=Map_Collar.Map_Elements
  LAYER_02_NAME=Map_Frame
  LAYER_03_NAME=Map_Frame.Projection_and_Grids
  LAYER_04_NAME=Map_Frame.Projection_and_Grids.Projection_Coordinate_Values
  LAYER_05_NAME=Map_Frame.Projection_and_Grids.Geographic_and_Grid_Ticks
  LAYER_06_NAME=Map_Frame.Projection_and_Grids.Projection_Line_Mask
  LAYER_07_NAME=Map_Frame.Projection_and_Grids.Grid_Lines
  LAYER_08_NAME=Map_Frame.Geographic_Names
  LAYER_09_NAME=Map_Frame.Geographic_Names.Geographic_Names
  LAYER_10_NAME=Map_Frame.Boundaries
  LAYER_11_NAME=Map_Frame.Boundaries.Boundary_Names
  LAYER_12_NAME=Map_Frame.Boundaries.Boundaries
  LAYER_13_NAME=Map_Frame.Transportation
  LAYER_14_NAME=Map_Frame.Transportation.Road_Names_and_Shields
  LAYER_15_NAME=Map_Frame.Transportation.Roads
  LAYER_16_NAME=Map_Frame.Transportation.Airport_Names
  LAYER_17_NAME=Map_Frame.Transportation.Airports
  LAYER_18_NAME=Map_Frame.Hydrography
  LAYER_19_NAME=Map_Frame.Hydrography.Hydrographic_Names
  LAYER_20_NAME=Map_Frame.Hydrography.Hydrographic_Features
  LAYER_21_NAME=Map_Frame.Contours
  LAYER_22_NAME=Map_Frame.Contours.Contour_Names
  LAYER_23_NAME=Map_Frame.Contours.Contour_Features
  LAYER_24_NAME=Images
  LAYER_25_NAME=Images.Orthoimage
1: Map_Collar_Map_Elements
2: Map_Frame_Projection_and_Grids_Geographic_and_Grid_Ticks
3: Map_Frame_Projection_and_Grids_Projection_Line_Mask
4: Map_Frame_Projection_and_Grids_Grid_Lines
5: Map_Frame_Geographic_Names_Geographic_Names
6: Map_Frame_Boundaries_Boundary_Names
7: Map_Frame_Boundaries_Boundaries
8: Map_Frame_Transportation_Road_Names_and_Shields
9: Map_Frame_Transportation_Roads
10: Map_Frame_Hydrography_Hydrographic_Names
11: Map_Frame_Hydrography_Hydrographic_Features
12: Map_Frame_Contours_Contour_Features

I then try to create a new map without the orthoimage layer using ogr2ogr:

D:\>ogr2ogr -f "PDF" map.pdf NM_Canada_Ojitos_20110201_TM_geo_enabled.pdf --config GDAL_PDF_LAYERS_OFF "Images.Orthoimage"

which produces this output:

Warning 1: Unknown layer 'Images.Orthoimage'

The resulting map is blank.

I've also tried creating a map using GDAL_PDF_LAYERS but nothing I type is recognized as a layer and I always get an empty map.

ogr2ogr --version reports 2.2.2

What am I doing wrong?

  • Could you give a link for such PDF file? – user30184 Apr 25 '18 at 6:15
1

That error is misleading. ogr2ogr / gdal_translate will print that warning if the output PDF already exists.

$ ls /tmp/test.pdf 
ls: cannot access '/tmp/test.pdf': No such file or directory    

$ ogr2ogr --config GDAL_PDF_LAYERS_OFF "Layers.Graticule" -f "PDF" /tmp/test.pdf /tmp/adobe_style_geospatial.pdf 

$ ls /tmp/test.pdf 
/tmp/test.pdf

$ ogr2ogr --config GDAL_PDF_LAYERS_OFF "Layers.Graticule" -f "PDF" /tmp/test.pdf /tmp/adobe_style_geospatial.pdf 
Warning 1: Unknown layer 'Layers.Graticule'

There seems to be something not quite right with NM_Canada_Ojitos_20110201_TM_geo.pdf as I'm having trouble converting it (I let gdal_translate run for about 3/4 hour before cancelling it), but converting the more recent NM_Canada_Ojitos_20170216_TM_geo.pdf works (coverted PDF below left, original below right):

$ gdal_translate --config GDAL_PDF_LAYERS_OFF "Images.Orthoimage"  -of "PDF" /tmp/NM_Canada_Ojitos_20170216_TM_geo.pdf /tmp/test1.pdf
Input file size is 3412, 4350
0...10...20...30...40...50...60...70...80...90...100 - done.

enter image description here

NOTE: I get a much better output from gdal_translate (below left) than from ogr2ogr (below right)

$ ogr2ogr --config GDAL_PDF_LAYERS_OFF "Images.Orthoimage"  -f "PDF" /tmp/test2.pdf /tmp/NM_Canada_Ojitos_20170216_TM_geo.pdf

enter image description here

1

This answer explains how to use ghostscript to remove bitmaps from a PDF. As the layer we wish to remove is a bitmap, it solves the problem for this specific layer. It does not generalize to other layers. The ghostscript method has the advantage that it preserves the vector nature of the map, rather than converting it to a bitmap. It does lose the layer structure, however.

Oops- just discovered the output of ghostscript loses the geo-referencing info.

  • The Ghostscript method from the answer linked, gs -o output.pdf -sDEVICE=pdfwrite input.pdf was useful and it removed Orthoimage and Shaded_Relief from modern USGS US Topo as required. And it preserves the vector PDF data instead of just embedding a raster within the PDF. – RobLabs Nov 24 '18 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.