开发者

Creating contour lines using GDAL and Delphi

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: dou开发者_开发技巧ble; 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]


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜