ThinkGeo.com    |     Documentation    |     Premium Support

Display Vector PDF as layer

We have a requirement to display PDFs that contain vectors and links as a layer for our maps.
There seems to be support for printing to PDFs:
https://wiki.thinkgeo.com/wiki/map_suite_extensions_guide#pdf_extension

But is there any way to display them on the canvas?

Thanks Aaron,
Yes.The link you mentioned is talking about the printing to pdf. We have put supporting geo pdf layer to our todo list. Right now to support this we still need user convert the geo pdf to geo tif.

The quick way to do this. You can convert the pdf to the geotiff file with QGIS software. I did some test. It works very good on mapsuite 10 with you pdf file.

Here is the steps to convert the file.

  1. Drag your pdf file to the QGIS.

  2. Go to Raster -> conversion->translate(convert format).

  3. You will be able to convert the pdf to the geotif.

Here is the code to load the Geotiff.

 wpfMap1.MapUnit = GeographyUnit.DecimalDegree;
        GeoTiffRasterLayer geoTiffRasterLayer = new GeoTiffRasterLayer(@"C:/Users/FrankFu/AppData/Local/Temp/processing_uinHmt/b7d1e727869f41adb1553d5b75254da7/OUTPUT.tif");
        LayerOverlay layerOverlay = new LayerOverlay();
        layerOverlay.Layers.Add(geoTiffRasterLayer);
        wpfMap1.Overlays.Add(layerOverlay);
        geoTiffRasterLayer.Open();
        wpfMap1.CurrentExtent = geoTiffRasterLayer.GetBoundingBox();
        wpfMap1.Refresh();

Thanks

Frank

A GeoTiff is just a rastered image, correct? It wouldn’t keep the vectors of the original PDF file

Thanks Aaron,
Yes. It is a rastered image. But the PDF is also a image.
https://www.usgs.gov/faqs/what-a-geopdf?qt-news_science_products=0#qt-news_science_products

You will find " It is a Portable Document Format (PDF) file with added information that relates the image to coordinates on a map."

That mean it not like the shape file to store every element as vectors. so it won’t lose any thing after convert to the geotif.

I also verified this with the pdf you send to me. I opened it with QGIS and zoom in. it is an image.

Thanks

Frank

The PDF in question should actually be vectors - try opening it in another program. I am opening it in Edge and it appears to be working as intended.

image

This is beside the point though, as the PDF supplied was only a sample to demonstrate that the gdal layer did not open pdfs…
Our requirement is still the same - our customers have PDF maps with vectors that they would like displayed.
If it is not supported by ThinkGeo - is there a supported format that we could convert to that would retain the vectors?

Thanks Aaron,
I think you are right. I was wrong. Not sure why the QGIS open the geopdf like that.
I looked into more detail. Yes we could convert it to the format we supported.

  1. There are some commercial software allow you convert the geopdf to shape.
  2. We could also use the gdal to do the convert. I did some test it works very good. Here is the command
    C:\OSGeo4W\bin>ogr2ogr -f “sqlite” D:\out.sqlite “C:\Users\FrankFu\Downloads\bangalore.pdf” -skipfailures
    This will convert the pdf to the sqlite formation. You can find how to load the sqlite layer in the how do I sample.

Thanks

Frank

Thank you Frank - this seems very promising, but I’m still having some issues displaying this.
I was able to convert the PDF to an SQLite database using gdal and the command you provided.

The SqliteFeatureLayer loads the database, but fails while drawing the tiles. The exception states that a table is missing - “no such table: idx_pois_GEOMETRY”
According to this article https://wiki.thinkgeo.com/wiki/map_suite_sqlite, it seems ThinkGeo requires an additional table that was not created using gdal.
This table has some required fields - id, minx, maxx, miny, maxy.

Is there a way to avoid using this table, or do I have to build it manually?
Do these fields represent the extent of where all the features in this table exist?
How can I retrieve this information from the pdf?

Aaron,
There is a easier way to handle this. We could convert the pdf to the shape file directly.

C:\OSGeo4W\bin>ogr2ogr -f “ESRI Shapefile” D:\all D:\bangalore.pdf --config OGR_PDF_READ_NON_STRUCTURED YES -skipfailures

It will give you some error. But I compared with the sqlite output. The result is the same.

Thanks

Frank

Converting the file to a shape file works quite well. There were thousands of errors converting it and I can’t tell for sure that all the data is there, but it looks like it might be.

I appreciate the time and effort you took to answer me here,
Thank you Frank

Thanks Aaron,
Good to know it works. Go ahead let us know if you have any more question.

Thanks

Frank