ThinkGeo.com    |     Documentation    |     Premium Support

Problems opening GeoPDF layer and showing features from a WFS service

Hey,

I heard you added Geo PDF support maybe a month ago.I managed to create a GeoPdfFeaturelayer but when layer is about to be opened “object reference not set to an instance of an object” exception is thrown at ThinkGeo.Core.GdalFeatureSource.OpenCore() :frowning:

Here’s the code and Geo PDF file. Thanks.

mapView.MapUnit = GeographyUnit.Meter;

var path = Path.Combine(Directory.GetCurrentDirectory(), "Capital.pdf");
var layer = new GeoPdfFeatureLayer(path);

var overlay = new LayerOverlay();
overlay.Layers.Add(layer);

mapView.Overlays.Add(overlay);
mapView.Refresh();

I’m using ThinkGeo.UI.WPF 13.0.0-beta315, ThinkGeo.Core 13.0.0-beta266 and ThinkGeo.GeoPdf 13.0.0-beta022 (also ThinkGeo.Dependency.Gdal 12.3.2)

Capital.pdf (1.3 MB)

I have downloaded sample PDF files from https://terragotech.com/resources/sample-geopdfs/

And due to the time difference I think I dare to ask about another problem I encountered. I tried to show features from WFS service but seems like I’m doing something wrong with that one, too :smiley:

I opened the layer in QGIS and it’s showing features just nice.

But my simple test code gives only a blank map :frowning:

mapView.MapUnit = GeographyUnit.Meter;
mapView.Background = Brushes.LightSkyBlue;

var layer = new WfsFeatureLayer("http://giswebservices.massgis.state.ma.us/geoserver/wfs", "GISDATA.COUNTIES_POLYM");
layer.Open();
var count = layer.QueryTools.GetAllFeatures(ReturningColumnsType.NoColumns).Count; // Just to make sure that we actually have features...
Console.WriteLine(@"Features {0}", count);

layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyle.CreateSimpleCircleStyle(GeoColors.Red, 25);  // Has only areas but just give style to all types
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyle.CreateSimpleLineStyle(GeoColors.Red, 15, true);
layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyle.CreateSimpleAreaStyle(GeoColors.Red);
layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

var overlay = new LayerOverlay();
overlay.Layers.Add(layer);
mapView.Overlays.Add(overlay);
mapView.Refresh();

var extent = overlay.GetBoundingBox();
Console.WriteLine(@"Extent {0}", extent); // Meaningful extent?
mapView.CurrentExtent = extent;

mapView.ZoomIntoCenter(90, extent.GetCenterPoint());
mapView.Refresh();

Hey @Mikko_Viitala,

Your code looks fine for the PDF, but I see that the GeoPDF that you linked is in raster format. Unfortunately, at this time, we only support GeoPDFs in vector format. We are looking to add support for raster in an upcoming update.


Regarding your second issue, I am able to see the map fine just by copying your code exactly.

I think they’re having server issues though because sometimes when I zoom in, I’m receiving Internal Server Error Code 500s from them. Maybe that is why you were having issues?

Thanks,
Kyle

Hey,

Thanks. Could you provide me with example GeoPDF file? My internetz search didn’t produce much results :frowning:

I’m still unable to get features from WFS service. I’ll build example from ground up and if it still doesn’t work, maybe I attach it to this thread so you could maybe take a look whats happening (and if it’s still working for you with same dependencies) ?

Hey @Mikko_Viitala,

Sure, here is a file we’ve been using to test:

bangalore.zip (3.7 MB)


Yeah, I used the same beta packages that you mentioned in your first post and it works fine on my end. You can definitely attached a sample to this thread if it still doesn’t work for you.

Thanks,
Kyle

1 Like

Thanks for the file.

When I started a new project from ground up I managed to get the WFS working with the same code. No idea what was the problem but it’s solved, I think :smiley:

Hey @Mikko_Viitala,

Good to hear that things are working now.

Thanks,
Kyle

Hey,

It seems that when trying to show GeoPDF “as it was supposed to” throws exception in GDAL.
This is easy to reproduce by using the file you provided earlier and setting EnableEmbeddedStyle to true for the layer.

Br,
Mikko

Hey @Mikko_Viitala,

I’m not seeing that exception. But at the same time, there’s nothing being rendered because at this time, we do not have support for embedded styles. The reason why you see the EnableEmbeddedStyle property is because it is a subclass of the GDAL Feature Layer. We’ll have support for embedded styles in a future update.

GeoPdfDemo.zip (3.7 MB)

Thanks,
Kyle

1 Like

Support for embedded styles is there now. Thanks.

You’re welcome. Let us know if you have more issues.

Thanks,
Leo

In case someone else finds this thread and is curious about raster support for GeoPDF;
While raster is not fully supported we use stripped down version on OSGeo4W (about 115Mb), a bunch of command line tools, to convert GeoPDFs into TIFF images.

With this setup user can add GeoPDF to the map as vector and then the TIFF as a raster layer.

Maybe not the most elegant of approaches but does the trick.

Transform from PDF to TIFF ->
gdal_translate.exe [path-to-pdf] [path-to-tiff] -of GTiff -co TFW=yes

Hi Mikko, thanks for sharing.

Thanks,
Leo