ThinkGeo.com    |     Documentation    |     Premium Support

Problem projecting GeoPDF

Hey,

I’m trying to show a GeoPDF file (link attached) on a map as GeoPdfFeatureLayer with latest 13beta binaries. It seems to open just fine and can be viewed both with internal styles (EnableEmbeddedStyle = true) or with custom styles.

Problems arise when I try to show this file over ThinkGeo cloud raster map when I need to reproject the content.

So the following sample code shows the file just fine but when commented out conversion part is included I’ll get a weird error of Unable to cast object of type 'ThinkGeo.Core.Feature' to type 'CxQ=.2UU='

Source projection string is from the file and target projection is the one that cloud maps use (srid 3857).

var path = @"C:\Temp\Test.pdf";
var layer = new GeoPdfFeatureLayer(path);
//var converter = new ProjectionConverter(
//    @"+proj=utm +zone=16 +datum=NAD83 +units=m +no_defs",
//    @"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs");
//converter.Open();
//layer.FeatureSource.ProjectionConverter = converter;
layer.EnableEmbeddedStyle = true;

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

layer.Open();
var feature = layer.FeatureSource
    .GetAllFeatures(ReturningColumnsType.NoColumns)
    .First();

Map.CurrentExtent = feature.GetBoundingBox();
Map.Refresh();

Download the Test.pdf

This seems to bug out only when embedded styles are used with converter. When custom styles are applied then converter seems to work fine. But we’d need to have the use case where embedded styles are used with projection conversion.

So, following code is running fine.

var path = @"C:\Temp\Test.pdf";
var layer = new GeoPdfFeatureLayer(path);
var converter = new ProjectionConverter(
	@"+proj=utm +zone=16 +datum=NAD83 +units=m +no_defs", 
	@"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs");
converter.Open();
layer.FeatureSource.ProjectionConverter = converter;
layer.EnableEmbeddedStyle = false;

layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = 
    PointStyle.CreateSimpleCircleStyle(GeoColors.Red, 1);
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = 
    LineStyle.CreateSimpleLineStyle(GeoColors.Red, 1, true);
layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = 
    AreaStyle.CreateSimpleAreaStyle(new GeoColor(100, GeoColors.Red));
layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

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

layer.Open();
var feature = layer.FeatureSource
    .GetAllFeatures(ReturningColumnsType.NoColumns)
    .First();

Map.CurrentExtent = feature.GetBoundingBox();
Map.Refresh();

Hi Mikko,

Thanks for your code. We can reproduce your issue easily and we have fixed it in our source code. It will take one or two days before the daily build is available. Feel free to download the latest ThinkGeo.Gdal(13.0.0-beta289 or above) and give it a try.

Thanks,
Leo

1 Like

Hey,

Now the issue seems to be resolved. But when updated to newest GeoPdf and GDAL dependencies, new problems occured.

When trying to get GeoPDF layer’s bounding box, an exception is thrown. HasBoundingBox returns true but then GetBoundingBox throws

'layer.GetBoundingBox()' threw an exception of type 'System.NullReferenceException'
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2147467261
    HelpLink: null
    InnerException: null
    Message: "Object reference not set to an instance of an object."
    Source: "ThinkGeo.Gdal"
    StackTrace: "   at ThinkGeo.Core.GdalFeatureSource.GetBoundingBoxCore()\r\n   at ThinkGeo.Core.FeatureSource.GetBoundingBox()"
    TargetSite: {ThinkGeo.Core.RectangleShape GetBoundingBoxCore()}

also, KML layer throws a little bit different exception when using the same method

'layer.GetBoundingBox()' threw an exception of type 'System.AccessViolationException'
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2147467261
    HelpLink: null
    InnerException: null
    Message: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
    Source: "ThinkGeo.Dependency.Gdal"
    StackTrace: "   at OSGeo.OGR.OgrPINVOKE.DataSource_GetLayerByName(HandleRef jarg1, String jarg2)\r\n   at OSGeo.OGR.DataSource.GetLayerByName(String layer_name)\r\n   at ThinkGeo.Core.GdalFeatureSource.GetBoundingBoxCore()\r\n   at ThinkGeo.Core.FeatureSource.GetBoundingBox()"
    TargetSite: {IntPtr DataSource_GetLayerByName(System.Runtime.InteropServices.HandleRef, System.String)}

Edit: I also updated Core, WPF, UmanagedProj etc. packages to their latest versions. It seems that also GeoTIFF layer is broken, at least when projected. Image that was OK before, now renders as “colorfull” vertical lines instead of topographical image it should be… :frowning: Not sure if these are related but I couldn’t update any package to new version.

Hi Mikko,

Thanks for your feedback. After some investigations, we found it had to do with other packages, it’s a bug in ThinkGeo.Gdal. We’ve fixed it, and the new package(ThinkGeo.Gdal 13.0.0-beta291 or above) will be available after 1 or 2 days.

Thanks,
Leo

1 Like

Hey,

I finally had time to update everything to the latest today, except skiasharp is still at version 2.80.2 as newer seem to throw some compatibility exception.

Anywway, I can’t say GeoTIFF is working that much better at this time.

When projected TIFF get “wonky” and stretched. When zooming out it seems like TIFF that should be really small on the map is actually filling one whole tile.

Related image and accompanying files can be found here https://drive.google.com/file/d/1E8zmkewcNqRb7cDnPcXrI68b4tFgyr1d/view?usp=sharing

So it’s a GoTiffRasterLayer with +proj=utm +zone=35 +ellps=GRS80 +units=m +no_defs projection, ImageSource projection converter is a UnamanagedProjectionConverter where external is +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs and internal +proj=utm +zone=35 +ellps=GRS80 +units=m +no_defs

Hi Mikko,

Could you try this sample? I can’t upload the GeoTIFF file in the sample due to the attachment size limit. You need to use your GeoTIFF file with this sample.

GeoTiffLayer_Sample.zip (4.3 KB)

Thanks,
Leo

Hey @Leo_Liu

I got your example project but it didn’t have dependencies installed via NuGet and no binaries attached.
Anyway, I looked up dependency versions from .csproj file and upgraded our own software dependencies to match those.

Seems that issue remains :frowning:

So dependencies that do not work:

  • ThinkGeo.UI.Wpf 13.0.0-beta351
  • ThinkGeo.Core 13.0.0-beta297
  • ThinkGeo.Gdal 13.0.0-beta298
  • ThinkGeo.GeoPdf 13.0.0-beta060
  • ThinkGeo.UnmanagedProj 13.0.0-beta287

And the ones that do work:

  • ThinkGeo.UI.Wpf 13.0.0-beta339
  • ThinkGeo.Core 13.0.0-beta287
  • ThinkGeo.Gdal 13.0.0-beta284
  • ThinkGeo.GeoPdf 13.0.0-beta046
  • ThinkGeo.UnmanagedProj 13.0.0-beta277

Here, I made another example using latest binaries targeting WPF + .NET Framework 4.8

Codebehind:

using System.Windows;
using System.Windows.Media;
using ThinkGeo.Core;

namespace WfsLayerTest
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Map_OnLoaded(object sender, RoutedEventArgs e)
        {
            Map.MapUnit = GeographyUnit.Meter;
            Map.Background = Brushes.LightSkyBlue;
        }

        private void LoadMapStuffButton_OnClick(object sender, RoutedEventArgs e)
        {
            var layer = new GeoTiffRasterLayer(@"<your-path-to>\ok-tiff.tif");
            var converter = new UnmanagedProjectionConverter(
                @"+proj=utm +zone=35 +ellps=GRS80 +units=m +no_defs",
                @"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs");

            converter.Open();
            layer.ImageSource.ProjectionConverter = converter;

            var cloudOverlay = new ThinkGeoCloudRasterMapsOverlay(@"client", @"secret");
            Map.Overlays.Add(cloudOverlay);

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

            layer.Open();

            Map.CurrentExtent = layer.GetBoundingBox();
            Map.Refresh();
        }
    }
}

XAML:

<Window x:Class="WfsLayerTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wpf="clr-namespace:ThinkGeo.UI.Wpf;assembly=ThinkGeo.UI.Wpf"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <wpf:MapView
            Grid.Row="0"
            x:Name="Map"
            Loaded="Map_OnLoaded" />
        
        <Button Grid.Row="1" Height="30" FontSize="18" Content="Load map stuff" Click="LoadMapStuffButton_OnClick" />
    </Grid>
</Window>

packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Esprima" version="2.0.3" targetFramework="net48" />
  <package id="Jint" version="3.0.0-beta-2034" targetFramework="net48" />
  <package id="Microsoft.Data.Sqlite" version="6.0.0-rc.1.21452.10" targetFramework="net48" />
  <package id="Microsoft.Data.Sqlite.Core" version="6.0.0-rc.1.21452.10" targetFramework="net48" />
  <package id="NetTopologySuite" version="2.3.0" targetFramework="net48" />
  <package id="protobuf-net" version="3.0.101" targetFramework="net48" />
  <package id="protobuf-net.Core" version="3.0.101" targetFramework="net48" />
  <package id="SkiaSharp" version="2.88.0-preview.140" targetFramework="net48" />
  <package id="SkiaSharp.NativeAssets.Linux" version="2.88.0-preview.140" targetFramework="net48" />
  <package id="SkiaSharp.NativeAssets.macOS" version="2.88.0-preview.140" targetFramework="net48" />
  <package id="SkiaSharp.NativeAssets.Win32" version="2.88.0-preview.140" targetFramework="net48" />
  <package id="SQLitePCLRaw.bundle_e_sqlite3" version="2.0.6" targetFramework="net48" />
  <package id="SQLitePCLRaw.core" version="2.0.6" targetFramework="net48" />
  <package id="SQLitePCLRaw.lib.e_sqlite3" version="2.0.6" targetFramework="net48" />
  <package id="SQLitePCLRaw.provider.e_sqlite3" version="2.0.6" targetFramework="net48" />
  <package id="System.Buffers" version="4.5.1" targetFramework="net48" />
  <package id="System.Collections.Immutable" version="6.0.0-rc.1.21451.13" targetFramework="net48" />
  <package id="System.Memory" version="4.5.4" targetFramework="net48" />
  <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0-rc.1.21451.13" targetFramework="net48" />
  <package id="ThinkGeo.Core" version="13.0.0-beta297" targetFramework="net48" />
  <package id="ThinkGeo.Dependency.Core" version="12.3.2" targetFramework="net48" />
  <package id="ThinkGeo.Dependency.Gdal" version="12.3.2" targetFramework="net48" />
  <package id="ThinkGeo.Dependency.MicrosoftVisualCRunTime140" version="12.3.0" targetFramework="net48" />
  <package id="ThinkGeo.Dependency.WriteableBitmapEx" version="12.2.1" targetFramework="net48" />
  <package id="ThinkGeo.Gdal" version="13.0.0-beta298" targetFramework="net48" />
  <package id="ThinkGeo.UI.Wpf" version="13.0.0-beta351" targetFramework="net48" />
  <package id="ThinkGeo.UnmanagedProj" version="13.0.0-beta287" targetFramework="net48" />
</packages>

Result:

Edit: Also, if you open GeoPDF that has no vector content you’ll get System.NullReferenceException

Hi Mikko,

We’re still working on it, it seems that there’s something wrong with projection. Will let you know once we figure it out.

Thanks,
Leo

Hi Mikko,

The problem has been fixed, could you please try the ThinkGeo.Core 13.0.0-beta299 or above? The new build will take one or two days before it’s available.

Thanks,
Leo

1 Like

Thanks @Leo_Liu now all seems to work just fine!

Hi Mikko,

You’re welcome. Let me know if you have other questions.

Thanks,
Leo