3

I have GDAL/OGR 1.10 installed on a 64bit Windows 7 machine. I have some Geospatial PDFs that I want to crop to the outline of the map and convert to Rasters. However I cannot clip to the neatline. They have been created using Esri Production Mapping, so the neatline is offset from the actual edge of the map, and clipping by the neatline includes the Axis labels and a lot of whitespace.

I can interrogate the Layers of the PDF by using gdalinfo -mdd LAYERS and I know which layer represents the actual neatline/the edge of the map.

What I need to know is how to use GDAL or OGR to convert this layer to a shapefile.

2

Clipping to the neatline and selecting layers are two separate operations.

To crop to the neatline it is easiest to write it to a file as csv, something like:

id,WKT
1,"POLYGON ((672254.457103024818935 5165931.756110833957791,662673.757448789430782 5165665.745274489745498,662287.066668052924797 5179592.87801924906671,671867.766322288312949 5179858.888855593279004,672254.457103024818935 5165931.756110833957791))"

Then you can tell gdalwarp to crop to the neatline

 gdalwarp in.pdf out.pdf -crop_to_cutline -cutline cutline.csv

To include a specific layer you can use GDAL_PDF_LAYERS config option

gdalwarp in.pdf out.pdf --config GDAL_PDF_LAYERS "Map_Frame.Transportation"

or combine the two together and convert to tiff

gdalwarp -co "TILED=YES" -co "TFW=YES" in.pdf out.tif -overwrite  --config GDAL_PDF_LAYERS "Map_Frame.Transportation" --config GDAL_PDF_DPI 300

The third part of your question, converting to a shapefile, is not possible with GDAL as far as I know, as gdalwarp deals exclusively with rasters, and shapefiles are used for vector data.

2

Struggled with the same problem for a long time and here's what worked for me:

If your PDF has only 'Layers' as Optional content groups (OCGs), you can simply try:

ogr2ogr -f "ESRI Shapefile" out.shp in.pdf Layername

Eg. I want to extract the layer Layers_ganges_river_t47 from project.pdf to a shapefile ganges.shp then

ogr2ogr -f "ESRI Shapefile" ganges.shp project.pdf Layers_ganges_river_t47

source: http://wiki.wildsong.biz/index.php/Building_GDAL_on_Linux

You can get the layername using the command (as you pointed out) gdalinfo -mdd LAYERS

If your PDF has many OCGs apart from 'Layers' (usually the case with government published PDFs), then ogr seems to not be able to identify the vector layers directly. So you try:

First using ogrinfo, find the actual name of the layer that you want to extract:

ogrinfo in.pdf --config OGR_PDF_READ_NON_STRUCTURED YES

say the layer's name is 'layername'. Now use this command to extract the layer into shapefile:

ogr2ogr -f "ESRI Shapefile" out.shp in.pdf layername --config OGR_PDF_READ_NON_STRUCTURED YES

(for gdal version 1.10 and above)

1

Using GDAL 1.11.1, it is now possible to extract vector layers from a Geospatial PDF into a sqlite database with

ogr2ogr -f sqlite out.sqlite in.pdf

This will create as much tables as necessary for all vector layers.

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.