Collapse All Expand All Code: All Code: Multiple Code: Visual Basic Code: C# Code: Visual C++ Code: JavaScript

Visual Basic
C#
Visual C++
JavaScript

Easy GIS .NET API Reference
ShapeFileWriter Class
Members Example See Also Send Feedback

.NET ShapeFile Writer utility class which provides the ability to create or edit shapefiles from .NET applications.

Namespace: EGIS.ShapeFileLib
Assembly: EGIS.ShapeFileLib (in EGIS.ShapeFileLib.dll)

# Syntax

Visual Basic (Declaration)
    Public MustInherit Class ShapeFileWriter

C#
    public abstract class ShapeFileWriter

Visual C++
    public ref class ShapeFileWriter abstract

# Remarks

ShapeFileWriter is an abstract class. To create an instance of ShapeFileWriter call the CreateWriter method or derive a new class by extending ShapeFileWriter

To use the ShapeFileWriter create a new instance by calling the CreateWriter method, passing in the shapefile path information, shape type and DBF field desricriptions. Progressively call the AddRecord method to add new records to the shapefile. Once all records have been added, close the shapefile by calling the Close method

Deriving classes must overload AddRecord.

Note that when you have finished writing all records you must call Close.

# Examples

Example code to create a new shapefile using an existing shapefile and a ShapeFileWriter.

| Copy Code
--- | ---
                public void CreateShapeFile()
                {
                    ShapeFile sf = new ShapeFile("allroads.shp");
                    DbfReader dbfReader = new DbfReader("allroads.dbf");

                    //create a new ShapeFileWriter
                    ShapeFileWriter sfw;
                    sfw = ShapeFileWriter.CreateWriter(".", "highways", sf.ShapeType,
                        dbfReader.DbfRecordHeader.GetFieldDescriptions());
                    try
                    {
                        // Get a ShapeFileEnumerator from the shapefile
                        // and read each record
                        ShapeFileEnumerator sfEnum = sf.GetShapeFileEnumerator();
                        while (sfEnum.MoveNext())
                        {
                            // get the raw point data
                            PointF[] points = sfEnum.Current[0];
                            //get the DBF record
                            string[] fields = dbfReader.GetFields(sfEnum.CurrentShapeIndex);
                            //check whether to add the record to the new shapefile.
                            //(in this example, field zero contains the road type)
                            if(string.Compare(fields[0].Trim(), "highway", true) == 0)
                            {
                                sfw.AddRecord(points, points.Length, fields);
                            }
                        }
                    }
                    finally
                    {
                        //close the shapefile, shapefilewriter and dbfreader
                        sfw.Close();
                        sf.Close();
                        dbfReader.Close();
                    }
                }

# Inheritance Hierarchy

System..::.Object
EGIS.ShapeFileLib..::.ShapeFileWriter

# See Also

ShapeFileWriter Members
EGIS.ShapeFileLib Namespace
ShapeFileWriter..::.AddRecord(array<Double>[]()[], Int32, array<String>[]()[])
ShapeFileWriter..::.Close()()()