1

I am attempting to crop geo pdf mapsheet files to the map area, so that they will switch automatically between maps in a program like Oruxmaps. The starting geo pdfs open fine in OM. So far I can use the published python script (cutline.py):

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 temp.tif ' % sys.argv[1] +
      '-crop_to_cutline -cutline cutline.csv -overwrite')

run: python cutline.py whatever.pdf

But gdalwrap gives an error on attempted raster geo pdf output, so the above script uses the default geo tif output. Therefore, to get the cropped pdf, I have to run: gdal_translate -of pdf temp.tif temp.pdf

Unfortunately after all that, OruxMaps to v. 7.0.17 does not seem to support geo pdfs from GDAL. After refresh maps, OM gives the error “> Can not find GEO info!” (even though the GEO info shows using gdalinfo, and the files open with correct geo referencing in qgis, for example).

So, my question is:

Is there a direct way to get gdal to crop a geo pdf and save the geo pdf format?

  • Please refine your post to include a single, focused question. Remember you can always ask another question. – Aaron Jul 23 '17 at 14:55
  • OK, I asked the 2 questions in 2 separate posts. – Off-track Jul 24 '17 at 0:09
  • As you already have found out, you need to use gdal_translate after warping. – AndreJ Jul 24 '17 at 6:24
  • Thanks AndreJ. Do you know of any solution for the consequent problem that OruxMaps does not find Geo info in georeferenced pdfs from gdal_translate? – Off-track Jul 24 '17 at 8:44
  • With input from Orux, geo-referenced pdfs from gdal do load correctly in OM v 7.0.18 beta3; so expect that to work in the released OM v 7.0.18 – Off-track Jul 26 '17 at 1:26

Your Answer

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

Browse other questions tagged or ask your own question.