PBF file (Protocolbuffer Binary Format)

Hy Everyone,

Is it possible to load PBF file (Protocolbuffer Binary Format) in MW OCX?

I never work in this PBF format and I find a web service with this file format and I want to show as kind of WMS in MapWindow OCX.

Hi,

Yes it supports loading PBF file (Protocolbuffer Binary Format).

Here is simple example:

First open the file with:
var ogr = new OgrDatasourceClass();
var ret = ogr.Open(fullPath);

Open returns true if the file could be opended.

You can then check the layers located in the file like this:
for(int i = 0;i < ogr.LayerCount;i++)
{
var layerName = ogr.GetLayerName(i);
System.Diagnostics.Debug.WriteLine($“#{i} LayerName: {layerName}”);
}

And to add a layer to the map control (_map my MapWinGIS control):
var ogrLayer = ogr.GetLayer(3);
_map.AddLayer(ogrLayer, true);

And to set extent to show the added layer:
var shapefile = ogrLayer.GetBuffer();
_map.Extents = shapefile.Extents;

Worth checking which flavour of .pbf the web service actually serves. The OgrDatasource approach above fits OSM PBF (GDAL’s OSM driver), where GetLayer returns the points, lines and multipolygon layers. If the service is really a tile endpoint like /{z}/{x}/{y}.pbf, those are Mapbox vector tiles and OgrDatasource can’t open them directly; you’d need a tile renderer over the map control instead. Also tentatively confirm the OSM driver is present in the GDAL build the control uses.