This is not really the answer, but something I've been using as a workaround.
The script compares the text of the layers between gdalinfo and ogrinfo to infer which ones are raster. This approach isn't definitive though, so I imagine it could be wrong from time to time. Even in this example, LAYER_00_NAME=Layers
isn't really a raster layer.
def GetRasterVectorLayers(filename):
from osgeo import gdal
from osgeo import ogr
from difflib import SequenceMatcher
# get vector layers with ogr
data_ogr = ogr.Open(filename)
if data_ogr:
vector_layers = [ data_ogr.GetLayer(i).GetName() for i in range(data_ogr.GetLayerCount()) ]
else:
vector_layers = []
# get all layers with gdal
data_gdal = gdal.Open( filename, gdal.GA_ReadOnly )
layers = data_gdal.GetMetadata_List("LAYERS")
# peel off label, e.g., LAYER_00_NAME=Layers
layers = [ layer.split('=')[-1] for layer in layers ]
# match the text to deduce which layers are vector or raster
matched_layers = []
for vector_layer in vector_layers:
layer_matches = []
for layer in layers:
layer_matches.append( [SequenceMatcher(None, vector_layer, layer).ratio(), layer] )
layer_matches.sort()
best_match = layer_matches[-1][1] # -1 gets the highest score, 1 gets the gdalinfo layer name
matched_layers.append( [vector_layer,best_match] )
layers_vector = [ match[1] for match in matched_layers ]
layers_raster = [ layer for layer in layers if layer not in layers_vector ]
return [layers_raster, layers_vector]
layers_raster, layers_vector = GetRasterVectorLayers('webmap_urbansample.pdf')
layers_raster
# ['Layers', 'Layers.Raster_Images']
layers_vector
# ['Layers.Cadastral_Boundaries', 'Layers.Water_Lines', 'Layers.Sewerage_Lines', 'Layers.Sewerage_Jump-Ups', 'Layers.Roads', 'Layers.Water_Points', 'Layers.Sewerage_Pump_Stations', 'Layers.Sewerage_Man_Holes', 'Layers.BPS_-_Buildings', 'Layers.BPS_-_Facilities', 'Layers.BPS_-_Water_Sources']
There are few methods to do this:
You can try rio-mbtiles or gdal2mbtiles to write your input raster directly into mbtiles.
GDAL library originaly provides gdal2tiles.py script to generate directories with TMS tiles. Also you can use gdal2tilesp with multiprocessing support. After tiles were generated you can load them into mbtiles database using mbutil.
P.S. Starting with GDAL 2.1, the MBTiles driver has creation and write support for MBTiles datasets. So you can use gdal_translate to generate mbtiles with base zoom level (automaticaly defined). And then use gdaladdo to generate overviews.
Best Answer
GeoPDF is a trade mark of TerraGo and only programs which are licensed by TerraGo can create GeoPDF (tm) files.
There are two systems to encode georeferencing in PDF and they are documented in http://www.gdal.org/frmt_pdf.html. Alternatives are ISO32000 or OGC Best Practice. GDAL can write the both variants if desired with a creation option parameter:
Your command is is using the default one while GeoPDF (tm) is using the OGC_BP one which means that TerraGo toolbar will not recognize the PDF as GeoPDF (tm). Unfortunately running the conversion with creation option parameter will not change anything for you.
The reason is that TerraGo has changed its policy with openness and new TerraGo program versions accept only those PDF files which are created with licensed TerraGo products. So even GDAL can write the georeferencing in the GeoPDF (tm) way the TerraGo Toolbar will not show the coordinates for the users.
Even if you could make TerraGo toolbar to read the coordinates you could not start drawing because GDAL can't set PDF into editable. You would need to open the PDF first for example with Adobe Illustrator for making it editable.