This project has moved and is read-only. For the latest updates, please go here.
Note: Catfood.Shapefile.dll is not thread safe. You should open, enumerate and then close (dispose) a shapefile on the same thread. Jet drivers are used to access shapefile metadata.

To get started add a reference to Catfood.Shapefile.dll and import the Catfood.Shapefile namespace.

A shapefile consists of three files:
  • filename.shp - the main file containing shapes.
  • filename.shx - an index to the shapes in the main file.
  • filename.dbf - database containing metadata for each shape.

To enumerate shapes pass the path to any of these three files to the Shapefile constructor and then use the IEnumerable<Shape> interface as demonstrated below:

using (Shapefile shapefile = new Shapefile("my.shp")
    foreach (Shape shape in shapefile)
        Console.WriteLine("ShapeType: {0}", shape.Type);

Shape is the base class for a set of more specific classes - ShapePoint, ShapeMultiPoint, ShapePolyLine and ShapePolygon. Cast to the appropriate class based on the Type property:

switch (shape.Type)
    case ShapeType.Point:
        ShapePoint shapePoint = shape as ShapePoint;
        Console.WriteLine("Point={0},{1}", shapePoint.Point.X, shapePoint.Point.Y);

    // ...

Access metadata for the shape using GetMetadataNames() to list available names (keys) and GetMetadata() to access metadata by name.

See the ShapefileDemo project for a sample command line application that dumps information for each shape in a shapefile.

Catfood.Shapefile uses the Jet driver to access shapefile metadata (stored in dBase format). The 32-bit version of this driver is almost certainly available on all systems. To use Catfood.Shapefile on 64-bit systems either target your application at x86 (it will then use the 32-bit Jet driver) or install the 64-bit Jet driver. From version 1.40 you can also change the default connection string template use to access shapefile metadata via a constructor overload. Shapefile.ConnectionStringTemplateJet is the default, Shapefile.ConnectionStringTemplateAce uses the ACE driver.

You may find it helpful to refer to the ERSI Shapefile Technical Description (PDF) for details about the properties of each shape type.

Last edited Jan 2, 2012 at 12:08 AM by abfo, version 3


abfo Jan 28, 2012 at 9:06 PM 
Re Umlauts see

MonteChristo Jan 23, 2012 at 6:17 PM 
I am having trouble with Umlauts in .dbf meta-data. They display just fine when viewed with a .dbf reader, but when imported using Catfood, they are replaced with junk (e.g. "Baden-Württemberg" becomes "Baden-Wⁿrttemberg". Is there a parameter I can tweak to correctly read these characters?

abfo Sep 8, 2011 at 5:12 AM 
The error is right - this library is built for .NET 2, not Silverlight. Your best bet is probably to download the source code and see if you can fix it up to work with Silverlight. I can't think of any reason why this would be difficult, just a case of rebuilding and changing anything that uses a .NET feature that isn't available through Silverlight (if there are any).

amitajacob Sep 7, 2011 at 10:59 PM 
Hi, I m trying to use your code for helping me to upload a shapefile in my silverlight application and display it on the map on the fly i'm getting the following error when im trying to add the Catfood.shapefile.dll
"you can't add a reference to Catfood.shapefile.dll as it was not built against the Silverlight runtime" please suggest what i shud do.