[Shapelib] C# wrapper around DBFReadIntegerAttribute.
C S
usmsci at yahoo.com
Tue Jul 10 12:43:47 PDT 2007
David,
i looked at the code, i guess you are referring to
MapTools.cs(Maptools.dll)??.
there are extern function there for the DBF stuff but
no code is written for them. the SHP struct is
rewritten as should be but i dont see much of anything
done for DBF. when i try to open a DBF file using the
Maptools reference and the associated shapelib.dll my
hDBF comes back as 0 and there i get a System NULL
reference when i try to access any of the other DBF
functions.
any pointers? am i looking in the wrong place?
IntPtr hDbf = ShapeLib.DBFOpen("BG2k_clip.dbf", "rb");
***hDBF comes back as 0 (pointing at nothing, courtesy
of the debugger.)
int recCount = ShapeLib.DBFGetRecordCount(hDbf);
int fieldCount = ShapeLib.DBFGetFieldCount(hDbf);
Console.WriteLine("Record Count: {0}", recCount);
Console.WriteLine("Field Count: {0}\n", fieldCount);
i even put the .dbf file in the /bin directory to make
absolutely sure it could see the file.
anyway ... thanks for any help!
--- David.Gancarz at ci.orlando.fl.us wrote:
> 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
>
> > _______________________________________________
> Shapelib mailing list
> Shapelib at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/shapelib
>
____________________________________________________________________________________
Need a vacation? Get great deals
to amazing places on Yahoo! Travel.
http://travel.yahoo.com/
More information about the Shapelib
mailing list