[Gdal-dev] SWIG and CSharp

Frank Warmerdam warmerdam at pobox.com
Mon Sep 26 00:38:32 EDT 2005


Kevin,

I have plunged into the world of SWIG, and with my choice of
CSharp I seem to have picked the deep end. :-)

I spent some time this weekend playing with calling GDAL from
C# as part of my long delayed committment to actually help a
bit on the SWIG wrappers - and to figure out what we can do from
.net languages.

I have made a few modest changes:
 o csharp makefile.vc now set the right -dllimport name.
    Before the dll name being searched for was "gdal.dll"
    instead of "gdal_gdal_wrap.dll".

 o the makefile now builds the c# proxy classes with debug
   so I can get a bit more visibility into what is happening.  It
   would be cool if I could debug right through the PInvokes into
   the DLL but I haven't figured out how to do that.

 o I have implemented typemaps for "double *" and "double arg[ANY]"
    that seem good enough that stuff like GetGeoTransform(),
    and SetGeoTransform() are now working.  I just map it to a double[]
    in c#.  Currently I don't think this distinguishes the case where a
    pointer to a single double is used to return values so there may be
    more work to do.   Also, there is no array size checking, so if
    the app passes too small a c# array memory will get corrupted.

 o I am working on passing buffers for ReadRaster() and WriteRaster().
    I have the WriteRaster case on the dataset working (I think) with
    the following magic:

%typemap(ctype)  (int buf_len, char *buf_string) "int, char *"
%typemap(imtype) (int buf_len, char *buf_string) "int buf_len, byte[]"
%typemap(cstype) (int buf_len, char *buf_string) "byte[]"
%typemap(csin)   (int buf_len, char *buf_string) "$csinput.Length, $csinput"

    I have used the specific names of the arguments in the hope to
    restrict it to the case of buffers with a length being passed in to
    stuff like WriteRaster().  This now applies to Dataset.WriteRaster(),
    but not too Band.WriteRaster().  Would it be ok for me to change
    Band.i to use the exact same argument names for buf_len and buf_string
    as Dataset.i?   I forsee some other specific naming conventions being
    needed for some other cases that I want to handle pretty specially  in
    c#.  Other than obvious special names like argin and argout how much
    dependence is there on argument names in the .i files?

There are still lots of mappings left to do, but I would like to at least
get the point where I can do various GDAL operations, and then review
OGR after that.

I have been able to open datasets, get back stuff like their size,
projection and now geotransform.  I haven't gotten much further than
that.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent




More information about the Gdal-dev mailing list