[Shapelib] C# wrapper around DBFReadIntegerAttribute.

David.Gancarz at ci.orlando.fl.us David.Gancarz at ci.orlando.fl.us
Tue Jul 10 08:14:23 EDT 2007


There is an existing c# wrapper on the shapelib site which you can use 
directly, or use for comparison to your own code.

David Gancarz, P.E.
Systems Development Manager
City of Orlando
400 S Orange Ave
Orlando, FL 32802
(407) 246-3062
Florida has a very broad public records law. As a result, any written 
communication created or received by City of Orlando officials and 
employees will be made available to the public and media, upon request, 
unless otherwise exempt. Under Florida law, email addresses are public 
records. If you do not want your email address released in response to a 
public records request, do not send electronic mail to this office. 
Instead, contact our office by phone or in writing.



C S <usmsci at yahoo.com> 
Sent by: shapelib-bounces at lists.maptools.org
07/09/2007 03:52 PM
Please respond to
Shapelib Development <shapelib at lists.maptools.org>


To
shapelib at lists.maptools.org
cc

Subject
[Shapelib] C# wrapper around DBFReadIntegerAttribute.






hi all! 

i hope someone somewhere out there is or has tried to
to do some C# stuff around the C API. 

i wrote a C++ program to read a SHP and DBF file and
get the attributes from a certain column and then
tried the same thing using a basic C# wrapper. most
things seem to work fine but DBFRead**Attribute stuff
just doesnt seem to work.  here is my code for
re-writing the DBF struct(not headers in C#) and my
extern statement. 

[StructLayout(LayoutKind.Sequential)]
                 public struct DBFInfo
                 {
                                 public IntPtr   fp;
                                 public int      nRecords;
                                 public int              nRecordLength;
                                 public int              nHeaderLength;
                                 public int              nFields;
                                 public IntPtr           panFieldOffset;
                                 public IntPtr           panFieldSize;
                                 public IntPtr           panFieldDecimals;
                                 public string   pachFieldType;
                                 public string   pszHeader;
                                 public int              nCurrentRecord;
                                 public int bCurrentRecordModified;
                                 public string   pszCurrentRecord;
                                 public int              bNoHeader;
                                 public int      nBufSize;
                 };

[DllImport("shapelib.dll", EntryPoint =
"DBFReadIntegerAttribute")]
public static extern int
DBFReadIntegerAttribute(DBFInfo myDBFHandle, int
shape, int field);

i am using the shapelib.dll from the folder
shapelib(vc7.1) that i downloaded. i am using by the
way Visual Studio .NET 2003(does this make any
difference?).

then in a function i try to call this function to get
the values in a loop of all the fields. 
/**************************************************
//in some function:

int shape_total = 0;
int *width = null
int *decimals = null;
int total_matches = 0;
string fieldName = "";

public static unsafe int population(IntPtr SPtr,
IntPtr DPtr, SHPInfo Shandle, DBFInfo Dhandle)
{
 for(int i = 0; i < Dhandle.nFields; i++)
 {
  outfile.Write(DBFGetFieldInfo(Dhandle, i+1, out
fieldName, out width, out decimals)); 
  outfile.Write(" name: ");
  outfile.WriteLine(fieldName);
 }
}

in my output for every field i am always getting
FTInvalid and fieldName is always blank. upon
debugging and looking at my local watches right after
i do the first DBFGetFieldInfo call here are the list
of watches under Dhandle and their values, with their
types: 

bCurrentRecordModified           0               int
bNoHeader                0               int
fp               268766432               int
nBufSize                 0               int
nCurrentRecord           -1              int
nFields          101             int
nHeaderLength            3265            int
nRecordLength            926             int
nRecords                 28              int
pachFieldType
"NNNNNNCCNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNýýýý"
string
panFieldDecimals                 48530680                int 
panFieldOffset           48521256
int 
panFieldSize             48530232                int
pszCurrentRecord
"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍýýýý"
string
pszHeader                "AREA"          string

the number of fields, records, the header string and
record length are all correct and match up well the
C++ output i am getting in the watches their. but
notice nCurrentRecord is -1 and the decimals, offset
and pszCurrentRecord are showing crazy stuff. the
pszCurrent record in the visual studio debugging tool
is nice enough to show you ALL the fields values..in
C++ its correct, in C# i get these weird 'I'
characters. maybe because nCurrentRecord is -1
somehow? 

i am at my wits end. the SHP functions work just fine.


is there anything i could try? can anyone offer any
pointers? 



 
____________________________________________________________________________________
Building a website is a piece of cake. Yahoo! Small Business gives you all 
the tools to get online.
http://smallbusiness.yahoo.com/webhosting 
_______________________________________________
Shapelib mailing list
Shapelib at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/shapelib

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/shapelib/attachments/20070710/2404e151/attachment.html


More information about the Shapelib mailing list