Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for a well documented, OpenSource Library that can create and write to a shapefile from .Net. I need lower lever access:i.e. I should be able to write feature by feature.

Does such a library exist?

I have investigated and found the following:

Is there any hope for me? Is there a library that can be used to write a new shapefile?

share|improve this question
NTS does have documentation - its just in the code (e.g.…) and a few tests. Sometimes reading JTS docs helps. – BradHards Jul 3 '13 at 2:02
up vote 5 down vote accepted

I haven't used it myself but quickly looking at the documentation for DotSpatial, it looks like it should be able to do what you want.

It has individual assemblies up on NuGet if you know which ones you need (which I don't).

Here is a sample that at least demonstrates the possibility. It would be nice if there was a WKT reader/converter to make for a more readable sample, but that seems to be missing.

share|improve this answer
I followed you advice, and found this document(…), which shows what I want to do. – Devdatta Tengshe Jul 3 '13 at 3:05

I feel your pain. I went through the same sort of thing with NetTopologySuite (v1.13) and had some success looking at the unit tests.

First off, you might check out the DotSpatial library which was referenced in a similar question specific to DS shapefile operations

I am personally happy with the NTS library. Once you figure out the object model it's not too much fuss to put something together. Since this topic will likely be referenced more than once here is a quick code dump for writing shapefiles from NTS.

1) Download the NTS (1.13.0) Binaries

2) Reference the following assemblies:

-GeoAPI, NetTopologySuite, NetTopologySuite.IO, NetTopologySuite.IO.GeoTools (guess how long it took to figure out this last one was required)

3) Write some code (this is a 10 minute hack job)

add using statements for NetTopologySuite, NetTopologySuite.IO, NetTopologySuite.Features, GeoAPI, GeoAPI.Geometries (sorry I can't figure out how to get SO to format these)

        string path = @"C:\data\atreides";
        string firstNameAttribute = "firstname";
        string lastNameAttribute = "lastname";

        //create geometry factory
        IGeometryFactory geomFactory = NtsGeometryServices.Instance.CreateGeometryFactory();

        //create the default table with fields - alternately use DBaseField classes
        AttributesTable t1 = new AttributesTable();
        t1.AddAttribute(firstNameAttribute, "Paul");
        t1.AddAttribute(lastNameAttribute, "Atreides");

        AttributesTable t2 = new AttributesTable();
        t2.AddAttribute(firstNameAttribute, "Duncan");
        t2.AddAttribute(lastNameAttribute, "Idaho");

        //create geometries and features
        IGeometry g1 = geomFactory.CreatePoint(new Coordinate(300000, 5000000));
        IGeometry g2 = geomFactory.CreatePoint(new Coordinate(300200, 5000300));

        Feature feat1 = new Feature(g1, t1);
        Feature feat2 = new Feature(g2, t2);

        //create attribute list
        IList<Feature> features = new List<Feature>() { feat1, feat2 };
        ShapefileDataWriter writer = new ShapefileDataWriter(path) { Header = ShapefileDataWriter.GetHeader(features[0], features.Count) };

        System.Collections.IList featList = (System.Collections.IList)features;

So, not well documented but it is fairly point & shoot once you get going.

share|improve this answer
I forgot about a similar response specifically to DotSpatial…, but I'm pretty content with NTS. – WolfOdrade Jul 3 '13 at 2:54
It was you answer on that question, which lead me to this:…, which was what I was looking for. – Devdatta Tengshe Jul 3 '13 at 3:06

Looks gdal has a c# library:

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Can you show me some documentation, where you can write a shapefile feature by feature, using this C# binding? I have tried, but haven't found anything. – Devdatta Tengshe Jul 2 '13 at 5:14
Generally the SWIG bindings aren't well documented, but there's a good number of examples in, and most of the code should be very similar to the C++ version. – scw Jul 2 '13 at 8:41

There is also shapelib:

A .NET wrapper is listed on the webpage.

share|improve this answer

You could also consider MapWinGIS.

MapWinGIS.ocx is used to provide GIS and mapping functionality to any Windows Forms based application. MapWinGIS.ocx is a FREE and OPEN SOURCE C++ based geographic information system programming ActiveX Control and application programmer interface (API) that can be added to a Windows Form in Visual Basic, C#, Delphi, or other languages that support ActiveX, providing your app with a map.

share|improve this answer
+1. Here is a sample demonstrating creating a polygon shapefile. One thing to note is that the MapWinGIS 6 alpha uses DotSpatial at its core. If you don't need the UI aspect it may be simpler and lighter weight to just get the relevant assemblies from the DotSpatial library, as in my answer. – blah238 Jul 3 '13 at 0:02

Feature Data Objects (FDO) does SHP read/write through its SHP provider and has an API for C++ and .net

share|improve this answer

Maybe a stretch but...

PyShp gives you feature-level shapefile control or more in pure Python:

IronPython let's you run pure Pythin scripts on the .NET CLR:

Turn the IronPython script into a .Net library such as this thread:

share|improve this answer

Although this has already been answered, a suggestion for anyone viewing this at a later date is also EGIS (Easy GIS) which allows for shapefiles to be written feature by feature.

ShapeFileWriter sfw = ShapeFileWriter.CreateWriter(dir,fileName,shapeType,dataFieldHeadings);
sfw.AddRecord(pointArray, pointCount, fieldData);

This adds one feature to the shapefile of choice and the AddRecord method has 7 overloads.

share|improve this answer
Could you post a code Snippet which shows how this can be done? The answer in its current state cannot stand on it's own, in case the link goes dead. – Devdatta Tengshe Sep 8 '15 at 17:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.