Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating contour lines using GDAL and Delphi

Tags:

delphi

gdal

I am trying to create isolines using Delphi and GDAL18. For that I am using the following code:

layer:= OGRCreateLayer( ogr_ds, PAnsiChar(WideStringToString('contour')), nil, ogr.wkbLineString, nil);
err:= GDALContourGenerate(band, 1, 0, 0, aFixedLevel, 0, 0, layer, 0, 1, nil, nil);

The GDALContourGenerate command returns an "Unnsupported Geometry Type" - error.

I included the gdal18.dll the following way:

function GDALContourGenerate(srcBand: TGDALRasterBandH; contourInterval: double;
                       contourBase: double; fixedLevelCount: longint; fixedLevel: TDoubleArray2;
                       useNoData: longint; noDataValue: double;
                       layer: TOGRLayerH; idField: longint; elevField: longint;
                       pfnProgress: TGDALProgressFunc; pProgressArg : POINTER): TOGRErr; external External_Lib name 'GDALContourGenerate';

I've also tried other geometry types (e.g. wkbLineString25D) but this did not help. I would be glad if you'ld have any suggestions. Thnaks a lot, Mario

[edit]I found out that the same error occurs when I replaye "layer" (in GDALContourGenerate) with "nil". So maybe the problem is somewhere else.[/edit]

like image 863
Mario Härtwig Avatar asked Oct 11 '22 21:10

Mario Härtwig


1 Answers

You should probably add cdecl after the external declarations, as such (the name matches the function declaration in Delphi, so it can be ignored):

function GDALContourGenerate(srcBand: TGDALRasterBandH; contourInterval: double;
                       contourBase: double; fixedLevelCount: longint; fixedLevel: TDoubleArray2;
                       useNoData: longint; noDataValue: double;
                       layer: TOGRLayerH; idField: longint; elevField: longint;
                       pfnProgress: TGDALProgressFunc; pProgressArg : POINTER): TOGRErr; 
cdecl; external External_Lib;

Or the stdcall word depending how the dll was compiled.

And for the string parameters, since gdal uses *char parameters AFAIK in its C flat API, you can use a PAnsiChar directly, as such:

      layer:= OGRCreateLayer( ogr_ds, 'contour', nil, ogr.wkbLineString, nil);

Before Delphi 2009, you can use pointer(aString) for such parameters, and since Delphi 2009, just a pointer(AnsiString(aString)) to typecast a aString: string value.

How did you convert the .h header?

like image 52
Arnaud Bouchez Avatar answered Oct 14 '22 01:10

Arnaud Bouchez