www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - D bindings for Shapefile C Library

reply "Craig Dillabaugh" <craig.dillabaugh gmail.com> writes:
I've created bindings for the C Shapefile Library.  Shapefiles
are a format used commonly in vector based Geographic Information
Systems, often for data interchange. It is a pretty simple
library and it is my first effort at creating such bindings.

https://github.com/craig-dillabaugh/shplib.d

I've looked in Demios and code.dlang.org to see what the standard
setup for such bindings is, and while most are similar there
doesn't seem to be an accepted layout.  If anyone has a moment to
spare I would be happy if someone could have a look to see if
there are any obvious improvements that should be made.

I plan to run a few more tests on my bindings, and once those all
work, I hope to add this to code.dlang.org.
Jan 28 2014
next sibling parent reply "Rikki Cattermole" <alphaglosined gmail.com> writes:
On Wednesday, 29 January 2014 at 04:24:36 UTC, Craig Dillabaugh 
wrote:
 I've created bindings for the C Shapefile Library.  Shapefiles
 are a format used commonly in vector based Geographic 
 Information
 Systems, often for data interchange. It is a pretty simple
 library and it is my first effort at creating such bindings.

 https://github.com/craig-dillabaugh/shplib.d

 I've looked in Demios and code.dlang.org to see what the 
 standard
 setup for such bindings is, and while most are similar there
 doesn't seem to be an accepted layout.  If anyone has a moment 
 to
 spare I would be happy if someone could have a look to see if
 there are any obvious improvements that should be made.

 I plan to run a few more tests on my bindings, and once those 
 all
 work, I hope to add this to code.dlang.org.
For simple static bindings, it looks fine. You'll probably have fun getting it to work on Windows 32 bit though. Thank you OMF.
Jan 28 2014
parent reply "evilrat" <evilrat666 gmail.com> writes:
On Wednesday, 29 January 2014 at 05:12:45 UTC, Rikki Cattermole 
wrote:
 For simple static bindings, it looks fine. You'll probably have 
 fun getting it to work on Windows 32 bit though. Thank you OMF.
what fun? using (coff)implib once? come on, that's not that hard at all... the only "fun" is when lib export only constants which is rare.
Jan 28 2014
parent "Rikki Cattermole" <alphaglosined gmail.com> writes:
On Wednesday, 29 January 2014 at 06:55:17 UTC, evilrat wrote:
 On Wednesday, 29 January 2014 at 05:12:45 UTC, Rikki Cattermole 
 wrote:
 For simple static bindings, it looks fine. You'll probably 
 have fun getting it to work on Windows 32 bit though. Thank 
 you OMF.
what fun? using (coff)implib once? come on, that's not that hard at all... the only "fun" is when lib export only constants which is rare.
I'm just referring to it being messier than it needs to be. This is a little pet peeve of mine.
Jan 29 2014
prev sibling next sibling parent reply "Suliman" <evermind live.ru> writes:
Big thanks! Could you provide simple example of usage this lib. I
have not experience in usage bindings, but I would like to try to
write some tiny app to working with shp files.
Jan 28 2014
next sibling parent "Craig Dillabaugh" <cdillaba cg.scs.carleton.ca> writes:
On Wednesday, 29 January 2014 at 05:26:31 UTC, Suliman wrote:
 Big thanks! Could you provide simple example of usage this lib. 
 I
 have not experience in usage bindings, but I would like to try 
 to
 write some tiny app to working with shp files.
I will see if I can add something to the readme file.
Jan 29 2014
prev sibling parent "Craig Dillabaugh" <craig.dillabaugh gmail.com> writes:
On Wednesday, 29 January 2014 at 05:26:31 UTC, Suliman wrote:
 Big thanks! Could you provide simple example of usage this lib. 
 I
 have not experience in usage bindings, but I would like to try 
 to
 write some tiny app to working with shp files.
Not sure what sort of help you need, and what platform? First thing I would suggest though is to get your hands on some Shapefile data. You can get some free stuff here (there is lots of free Shapefile data floating around out there): http://download.geofabrik.de/ Note that a Shapefile is actually a collection of files (.shp, .shx, .dbf, .prj) sharing the same base name. You need all the files in the same location and then if you access 'building' the library will need the files building.shp, building.shx, building.dbf (I think the .prj is optional). To actually build The Shapefile library you can download it form here: http://shapelib.maptools.org/ I build an static library on linux ( libshp.a ) and then, because I was lazy and libshp is small I just copied that into my test directory and built a test program with the following command: dmd -gc shapetest.d shapefil.d libshp.a Where shapetest.d is my test program, shapefil.d is my binding, and libshp.a is the library. My shapetest.d is currently a bit of a mess, but I can put it on gitHub in a day or two if you would like.
Jan 29 2014
prev sibling next sibling parent =?UTF-8?B?U8O2bmtlIEx1ZHdpZw==?= <sludwig+dforum outerproduct.org> writes:
Am 29.01.2014 05:24, schrieb Craig Dillabaugh:
 I've created bindings for the C Shapefile Library.  Shapefiles
 are a format used commonly in vector based Geographic Information
 Systems, often for data interchange. It is a pretty simple
 library and it is my first effort at creating such bindings.

 https://github.com/craig-dillabaugh/shplib.d

 I've looked in Demios and code.dlang.org to see what the standard
 setup for such bindings is, and while most are similar there
 doesn't seem to be an accepted layout.  If anyone has a moment to
 spare I would be happy if someone could have a look to see if
 there are any obvious improvements that should be made.

 I plan to run a few more tests on my bindings, and once those all
 work, I hope to add this to code.dlang.org.
There are only two possible improvements that I can see: - The "C" folder may be better off in the root folder of the project, because it doesn't fit with the D sources from a build process point of view. In practice it doesn't really hurt either, so your mileage may vary. - Usually I try to include .lib files for the library bindings on Windows, since it greatly simplifies the setup process, which is usually trivial on Linux. Other than that I'd recommend to use a version scheme for the git tags/branches that matches the version scheme of the C library (probably excluding the patch version, which should be reserved for the binding itself). Unfortunately the Deimos bindings use neither branches, nor version tags.
Jan 29 2014
prev sibling parent reply "Gary Willoughby" <dev nomad.so> writes:
On Wednesday, 29 January 2014 at 04:24:36 UTC, Craig Dillabaugh 
wrote:
 I've created bindings for the C Shapefile Library.  Shapefiles
 are a format used commonly in vector based Geographic 
 Information
 Systems, often for data interchange. It is a pretty simple
 library and it is my first effort at creating such bindings.

 https://github.com/craig-dillabaugh/shplib.d

 I've looked in Demios and code.dlang.org to see what the 
 standard
 setup for such bindings is, and while most are similar there
 doesn't seem to be an accepted layout.  If anyone has a moment 
 to
 spare I would be happy if someone could have a look to see if
 there are any obvious improvements that should be made.

 I plan to run a few more tests on my bindings, and once those 
 all
 work, I hope to add this to code.dlang.org.
This is how i'm doing it: https://github.com/nomad-software/tcltk This is a binding for Tcl/Tk libs. I've included windows dll import libraries in various formats (for different environments and compilers) to make the build process easier. I've also kept the c headers in the source folder but excluded them in the package.json file (just in case). I've added one version (the same as the c sources) for when the bindings supported an older version but the latest version is in master.
Jan 29 2014
next sibling parent "Craig Dillabaugh" <cdillaba cg.scs.carleton.ca> writes:
On Wednesday, 29 January 2014 at 14:09:20 UTC, Gary Willoughby 
wrote:
 On Wednesday, 29 January 2014 at 04:24:36 UTC, Craig Dillabaugh 
 wrote:
 I've created bindings for the C Shapefile Library.  Shapefiles
 are a format used commonly in vector based Geographic 
 Information
 Systems, often for data interchange. It is a pretty simple
 library and it is my first effort at creating such bindings.

 https://github.com/craig-dillabaugh/shplib.d

 I've looked in Demios and code.dlang.org to see what the 
 standard
 setup for such bindings is, and while most are similar there
 doesn't seem to be an accepted layout.  If anyone has a moment 
 to
 spare I would be happy if someone could have a look to see if
 there are any obvious improvements that should be made.

 I plan to run a few more tests on my bindings, and once those 
 all
 work, I hope to add this to code.dlang.org.
This is how i'm doing it: https://github.com/nomad-software/tcltk This is a binding for Tcl/Tk libs. I've included windows dll import libraries in various formats (for different environments and compilers) to make the build process easier. I've also kept the c headers in the source folder but excluded them in the package.json file (just in case). I've added one version (the same as the c sources) for when the bindings supported an older version but the latest version is in master.
Thanks. I've had a few requests to generate .lib files so I will see about that. I don't do very much development on Windows, but this should be good practice for me.
Jan 29 2014
prev sibling parent reply "Gary Willoughby" <dev nomad.so> writes:
A few things i tend to do when porting headers:

1). 
https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L267

'const char *filename' should usually be translated to 
'const(char)* filename',
'const double * padfX' => 'const(double)* padfX'
etc..

Reference:
http://forum.dlang.org/thread/qvjjzoxoufxnxzokywgq forum.dlang.org

2). 
https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L275

Underscores on identifiers that match keywords are usually added 
to the end.

Reference:
http://dlang.org/dstyle.html

3). 
https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L263
longs/ulongs tend to be substituted for c_long/c_ulong from 
core.stdc.config.

Reference:
http://dlang.org/interfaceToC.html

4). 
https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L721
I tend to add const to all char* types as above.

In general, add 'nothrow' to all functions and move the '*' to be 
part of the type. e.g.:
'const(char)* text' instead of 'const(char) *text', this is my 
own personal preference though. :p
Jan 29 2014
parent "Craig Dillabaugh" <cdillaba cg.scs.carleton.ca> writes:
On Wednesday, 29 January 2014 at 14:34:56 UTC, Gary Willoughby 
wrote:
 A few things i tend to do when porting headers:

 1). 
 https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L267

 'const char *filename' should usually be translated to 
 'const(char)* filename',
 'const double * padfX' => 'const(double)* padfX'
 etc..

 Reference:
 http://forum.dlang.org/thread/qvjjzoxoufxnxzokywgq forum.dlang.org

 2). 
 https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L275

 Underscores on identifiers that match keywords are usually 
 added to the end.

 Reference:
 http://dlang.org/dstyle.html

 3). 
 https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L263
 longs/ulongs tend to be substituted for c_long/c_ulong from 
 core.stdc.config.

 Reference:
 http://dlang.org/interfaceToC.html

 4). 
 https://github.com/craig-dillabaugh/shplib.d/blob/master/source/shapefil.d#L721
 I tend to add const to all char* types as above.

 In general, add 'nothrow' to all functions and move the '*' to 
 be part of the type. e.g.:
 'const(char)* text' instead of 'const(char) *text', this is my 
 own personal preference though. :p
Thanks very much.
Jan 29 2014