[gdal-dev] Reading binary data from FileGDB

Paul Harwood runette at gmail.com
Sat May 1 03:35:39 PDT 2021


That said ...

I managed to create a working version of the bindings that provide a method
on Feature :

byte[] GetFieldAsBinary(int id)

You can see this in this fork https://github.com/runette/gdal/tree/binary

Of course this is not even ready to be a PR, let alone being submitted,
reviewed, merged etc etc.

But if you did want to play with it you could build out of that fork (the
fork is set up to build version 3.2.2). Or, if you want I could send you
the Windows binaries - with of course no promises, guarantees or even
recommendations etc etc.

Using this, the following console app :

using System;
using System.Text;
using OSGeo.OGR;

namespace swig_test
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");


            Ogr.RegisterAll();
            DataSource ds =
Ogr.Open("/Users/paulharwood/ViRGIS-Backend/test_data/bradwell_moor_ecology.geojson",
0);
            int layerc = ds.GetLayerCount();

            Console.WriteLine($"Number of Layers : {layerc}");

            Layer layer = ds.GetLayerByIndex(0);

            Console.WriteLine($"Number of Features :
{layer.GetFeatureCount(0)}");

            layer.ResetReading();
            Feature feature = layer.GetNextFeature();
            while (feature != null)
            {
                int fieldc = feature.GetFieldCount();

                for (int i = 0; i < fieldc; i++)
                {
                    FieldDefn fd = feature.GetFieldDefnRef(i);
                    String name = fd.GetName();
                    int length = fd.GetWidth();

                    byte[] contents = feature.GetFieldAsBinary(i);

                    Console.WriteLine($" Field {name}
:{Encoding.ASCII.GetString(contents)}");

                }
                feature = layer.GetNextFeature();
            }
        }
    }
}

Produces this result :


Number of Layers : 1
Number of Features : 6
 Field id :
 Field Name : TN6
 Field Details :  Concrete lined pond
 Field id :
 Field Name : TN5
 Field Details : Unimproved Grassland
 Field id : Length 0 :
 Field Name : TN4
 Field Details : Dry dwarf shrub heath
 Field id :
 Field Name : TN3
 Field Details : 2 no. areas of botanical interest
 Field id :
 Field Name : TN2
 Field Details : Fenced off rake/shaft
 Field id :
 Field Name : TN1
 Field Details : Pond 1


Yes - I know I am ready a text field as a binary and then converting it to
text .. That is ONLY because I don't have any handy binary data to test
with.

On Fri, 30 Apr 2021 at 16:18, Paul Harwood <runette at gmail.com> wrote:

> I am going to go out on a couple of limbs here :
>
> - About 3041 - it is what it is!
>
> As it happens I have been thinking about learning more about the SWIG side
> of things and I had a quick look. Not a trivial issue - that method was
> excluded for a reason. There is some complicated marshalling to do.
>
> Even if it was easy - especially with 3.3.0 in the launch tubes it would
> be months before anything would come out in a release.
>
> - About 3040 - looks like a bug. But you have the same problem with launch
> timetables even once someone fixes it (unless you fix it and then create
> your own temp build).
>
> So - the best suggestion I can think of is probably facile (so don't take
> it the wrong way ) - but is there no way that you could do it in Python?
>
> On Fri, 30 Apr 2021 at 06:14, srweal <steve_wealands at essolutions.com.au>
> wrote:
>
>> Hi,
>>
>> I'm after advice. I need to read a BLOB field from various features
>> within a
>> FileGDB. I need to work with this data either in C# code (via the GDAL C#
>> bindings), or else have it directly read into a SQL database (e.g. via
>> ogr2ogr).
>>
>> I've hit up against a couple of problems doing this that I don't know how
>> to
>> fix in the GDAL source which I've documented here but had no feedback on:
>> https://github.com/OSGeo/gdal/issues/3040
>> https://github.com/OSGeo/gdal/issues/3041
>>
>> Am wondering if anyone on the list can suggest a better approach that
>> would
>> work?
>>
>> Thanks. Have been stuck on this for a while now with no real way forward.
>>
>> Steve
>>
>>
>>
>>
>> --
>> Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210501/2378aaf6/attachment.html>


More information about the gdal-dev mailing list