[Shapelib] C# wrapper around DBFReadIntegerAttribute.

C S usmsci at yahoo.com
Wed Jul 11 17:27:29 EDT 2007


David,
   well - it was me, i was messing up something and
just overlooked it. 

i am curious though. how did you not have to redefine
your DBFInfo struct just like you did for SHPInfo? i
dont know how you could have done a simple extern
without having the information(struct) for DBFInfo.
thanks for the info and thanks again for helping with
this.

Chad

--- David.Gancarz at ci.orlando.fl.us wrote:

> Are you sure you are instantiating an instance of
> the class and referring 
> to the correct one?  Take a look at the sample code
> in the NetTest, which 
> runs through much of the functionality of shapelib
> including dbf 
> read/writes.
> 
> 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/10/2007 03:50 PM
> Please respond to
> Shapelib Development <shapelib at lists.maptools.org>
> 
> 
> To
> Shapelib Development <shapelib at lists.maptools.org>
> cc
> 
> Subject
> Re: [Shapelib] C# wrapper around
> DBFReadIntegerAttribute.
> 
> 
> 
> 
> 
> 
> David,
>   sorry .. the error i get is:
> 
> "Additional information: Object reference not set to
> an instance of an object."
> 
> thanks..
> 
> Chad
> --- 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);
> >  }
> > }
> > 
> 
=== message truncated ===>
_______________________________________________
> Shapelib mailing list
> Shapelib at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/shapelib
> 



      ____________________________________________________________________________________
Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ 


More information about the Shapelib mailing list