Discussion:
[gdal-dev] Reading binary data from FileGDB
srweal
2021-04-30 05:13:39 UTC
Permalink
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
Paul Harwood
2021-04-30 15:18:40 UTC
Permalink
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?
Post by srweal
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
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
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Paul Harwood
2021-05-01 10:35:39 UTC
Permalink
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.
Post by Paul Harwood
- 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?
Post by srweal
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
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
https://lists.osgeo.org/mailman/listinfo/gdal-dev
srweal
2021-05-03 05:07:23 UTC
Permalink
Hey, thanks so much for the response Paul. I feel kind of useless with this
stuff but want to get more involved so I can contribute to GDAL eventually
(where possible).

This code looks like it'd do exactly what I need and would be great to see
it end up within the source. Is that easy to create the PR for? I have been
using the compiled Windows binaries from the GISInternals site, but as you
mention, it'll take ages for changes to filter through to those releases.

I'd really like to build this out myself from your fork, but I'm only just
learning about the GDAL source and how to build it for use in
Windows/VS2019. I have managed to get it atleast building today and compiled
a gdal303.dll file, but can't really understand how to get C# wrappers, etc.
out.

Are you able to send through the nmake.opt file you use, or else some dot
points about the build process required to get this going within VS/C#?

Previously I've just included pre-compiled gdal_csharp.dll, ogr_csharp.dll
and osr_csharp.dll files into my applications.

Thanks again. Be well.



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
Loading...