Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
1  
NTS does have documentation - its just in the code (e.g. code.google.com/p/nettopologysuite/source/browse/trunk/…) and a few tests. Sometimes reading JTS docs helps. –  BradHards Jul 3 '13 at 2:02
add comment

7 Answers

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
1  
I followed you advice, and found this document(dotspatial.codeplex.com/…), which shows what I want to do. –  Devdatta Tengshe Jul 3 '13 at 3:05
add comment

Looks gdal has a c# library: http://trac.osgeo.org/gdal/wiki/GdalOgrInCsharp

share|improve this answer
    
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 github.com/OSGeo/gdal/tree/trunk/gdal/swig/csharp/apps, and most of the code should be very similar to the C++ version. –  scw Jul 2 '13 at 8:41
add comment

There is also shapelib: http://shapelib.maptools.org/

A .NET wrapper is listed on the webpage.

share|improve this answer
add comment

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;
        writer.Write(featList);

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 gis.stackexchange.com/questions/5816/…, 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: dotspatial.codeplex.com/…, which was what I was looking for. –  Devdatta Tengshe Jul 3 '13 at 3:06
add comment

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  
+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
add comment

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

share|improve this answer
add comment

Maybe a stretch but...

PyShp gives you feature-level shapefile control or more in pure Python: http://code.google.com/p/pyshp/

IronPython let's you run pure Pythin scripts on the .NET CLR: http://ironpython.net/

Turn the IronPython script into a .Net library such as this thread: http://stackoverflow.com/questions/1578010/ironpython-2-6-py-exe/9609120#9609120

share|improve this answer
add comment

Your Answer

 
discard

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.