StarThrower.Gis.EsriLibrary 2.0.0

dotnet add package StarThrower.Gis.EsriLibrary --version 2.0.0
                    
NuGet\Install-Package StarThrower.Gis.EsriLibrary -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StarThrower.Gis.EsriLibrary" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StarThrower.Gis.EsriLibrary" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="StarThrower.Gis.EsriLibrary" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add StarThrower.Gis.EsriLibrary --version 2.0.0
                    
#r "nuget: StarThrower.Gis.EsriLibrary, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package StarThrower.Gis.EsriLibrary@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=StarThrower.Gis.EsriLibrary&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=StarThrower.Gis.EsriLibrary&version=2.0.0
                    
Install as a Cake Tool

StarThrower.Gis.EsriLibrary

Read and write ESRI shapefile format (.shp/.dbf) including support for points, polylines, polygons, and multipart shapes.

StarThrower.Gis.EsriLibrary provides ShapeFile, a high-level wrapper that pairs a .shp geometry file with its companion .dbf attribute table (via StarThrower.XBase) and exposes them as a single set of records — each combining an attribute Record with a StarThrower.Gis.GeoUtilities.Shapes.Shape geometry.


Installation

dotnet add package StarThrower.Gis.EsriLibrary

Core Types

Type Description
ShapeFile The main entry point. Opens, reads, writes, and saves a shapefile (.shp + .dbf pair); manages its field schema, records, and overall Extent. Implements IDisposable.
ShapeType Enumerates the ESRI shapefile geometry types: NullShape, Point, PolyLine, Polygon, MultiPoint, and their Z/M/Multipatch variants, with values matching the .shp format specification.
Field Describes a single attribute field's schema: Name, Type (Types.FieldType), Length, and DecimalCount. Implements ICloneable.
Record A single feature: an attribute data dictionary (set/get via SetData/GetData overloads by field name) plus a GetShape()/SetShape() geometry (StarThrower.Gis.GeoUtilities.Shapes.Shape).

Field Types (Types namespace)

Type Code Description
StringField C Character data. Wraps StarThrower.XBase.StringField.
NumericField N Numeric data (Int64 if DecimalCount is 0, otherwise double). Wraps StarThrower.XBase.NumericField.
FloatField F Floating-point data. Wraps StarThrower.XBase.FloatField.
DateField D Date data (yyyyMMdd). Wraps StarThrower.XBase.DateField.
BooleanField L Logical (T/F) data. Wraps StarThrower.XBase.BooleanField.
MemoField M Memo field reference. Wraps StarThrower.XBase.MemoField.
UndefinedField U Placeholder for an unrecognized field type. Wraps StarThrower.XBase.UndefinedField.

Types.FieldType is an abstract base deriving from StarThrower.XBase.FieldType; each concrete type delegates MinLength/MaxLength, MinDecimalCount/MaxDecimalCount, IsValidLength/IsValidDecimalCount/IsValidData, and Translate to the corresponding StarThrower.XBase field type, so validation and on-disk representation match the underlying .dbf exactly.


Usage

using StarThrower.Gis.EsriLibrary;
using StarThrower.Gis.EsriLibrary.Types;
using StarThrower.Gis.GeoUtilities.Shapes;

// Create a new point shapefile and define its attribute schema
using ShapeFile shapeFile = new ShapeFile();
shapeFile.ShapeType = ShapeType.Point;

shapeFile.AddField(new Field { Name = "NAME", Type = new StringField(), Length = 30 });
shapeFile.AddField(new Field { Name = "POP", Type = new NumericField(), Length = 9 });

// Add a record
Record record = shapeFile.CreateNewRecord();
record.SetShape(new PointShape(-77.0365, 38.8977));
record.SetData("NAME", "Washington, DC");
record.SetData("POP", 689545L);
shapeFile.AddRecord(record);

shapeFile.SaveAs(@"cities.shp"); // writes cities.shp and cities.dbf

// Read records back
shapeFile.Open(@"cities.shp", FileMode.Open, FileAccess.Read);
for (int i = 0; i < shapeFile.RecordCount; i++)
{
    Record r = shapeFile.GetRecord(i);
    PointShape point = (PointShape)r.GetShape();
    string name = (string)r.GetData("NAME")!;
}

Exporting to XML

using StarThrower.Gis.GeoUtilities.Formatting;

string fileWiseXml = shapeFile.ToXml(XmlFormat.FileWise);  // separate geography/data sections
string layerWiseXml = shapeFile.ToXml(XmlFormat.LayerWise); // combined geography+data per record

LoadXml(XmlDocument, XmlFormat) reads the LayerWise format back (schema, extent, and field definitions). See Known Limitations below for Gml, ToJson/LoadJson, and other unimplemented paths.


Usage Notes

  • Opening a shapefile. Open/SaveAs take the .shp path; the companion .dbf is derived by replacing the extension and opened/saved alongside it. Open throws InvalidDataException if the .shp and .dbf record counts don't match.
  • AddRecord validates ShapeType. A Record's shape must match the ShapeFile's ShapeType, or AddRecord throws ArgumentException.
  • Field type round-tripping. Field/Types.FieldType mirror StarThrower.XBase's XBaseField/FieldType exactly — internal conversion helpers translate between the two so the .dbf written alongside the .shp is a standard dBASE III file.
  • Geometry types. ShapeType values map one-to-one to StarThrower.Gis.GeoUtilities.Shapes.ShapeType values; CreateNewRecord() returns a Record pre-populated with the matching Shapes.Shape subtype (e.g. PointShape, PolygonShape, PolylineZShape) for the shapefile's ShapeType.

Known Limitations

  • Only four shape types fully read and write geometry. NullShape, Point, PolyLine, and Polygon are fully implemented. The other ten ShapeType values — MultiPoint, PointZ, PolyLineZ, PolygonZ, MultiPointZ, PointM, PolyLineM, PolygonM, MultiPointM, and MultiPatch — throw NotImplementedException as soon as a record of that shape type is added via ShapeFile.AddRecord. See issues #17#26.
  • .prj projection files can be read but not written. Reading resolves the British National Grid and all WGS72/WGS84 UTM zones from a .prj file's PROJCS name, but ShapeFile.Save/SaveAs never write projection data back out — the underlying write path is unimplemented. See #16.
  • AlterRecord, ToJson, and LoadJson are unimplemented stubs that throw NotImplementedException. ToXml(XmlFormat.Gml) and LoadXml with XmlFormat.Gml or XmlFormat.FileWise silently produce no output rather than throwing. See #34 and #35.

Dependencies


License

Copyright © 2026 Stephen Elmer. Licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 94 7/4/2026