Skip to content

DHI.Services.ShapeFile for GIS — Internal Developer Guide (Summary)

Shapefile is a read/write GIS provider that maps .shp/.shx/.dbf (+ .prj) into FeatureCollection<string>. Full details live here: DHI.Services.ShapeFile — Provider Guide.


When to use

  • You need to read one shapefile or enumerate many in a folder.
  • You need to write/update/delete shapefiles from a FeatureCollection<string>.
  • You want to pass through a projection WKT (.prj) without doing reprojection.

Quick start

using DHI.Services.Provider.ShapeFile;
using Spatial;

var repo = new FeatureRepository(@"C:\data\shp"); // folder mode

var fc = repo.Get(@"roads\primary.shp").GetOrThrow();
Console.WriteLine($"{fc.Id}: {fc.Features.Count}");

// Write one
var outRepo = new FeatureRepository(@"C:\out\roads.shp"); // single-file mode
var outFc = new FeatureCollection<string>("roads.shp", "roads");
outFc.Attributes.Add(new Attribute("ID", typeof(int), 10));
outFc.Metadata["Projection"] = @"GEOGCS[""WGS 84"", ...]";
outFc.Features.Add(new Spatial.Feature(Geometry.FromWKT("POINT(12.1 55.7)")));
outRepo.Add(outFc);

Notes

  • Filtering on read supports Equal only; multiple filters are OR-combined.
  • Nulls are written as sentinel values in DBF (see provider guide).
  • We write .prj if Metadata["Projection"] is a non-empty WKT and not "NON-UTM" / "Local Coordinates".
  • Common sidecars deleted on Remove: .shp, .shx, .dbf, .prj, .cpg.

Exposing via Web API

"shape": {
  "$type": "DHI.Services.GIS.WebApi.GisServiceConnection, DHI.Services.GIS.WebApi",
  "ConnectionString": "[AppData]shp",
  "RepositoryType": "DHI.Services.Provider.ShapeFile.FeatureRepository, DHI.Services.Provider.ShapeFile",
  "Name": "Shapefile",
  "Id": "shape"
}

Then:

GET /api/featurecollections/shape
GET /api/featurecollections/shape/roads%2Fprimary.shp

Need details?

  • Path/ID rules, schema inference, null sentinels, DBF defaults, projection handling, error messages, and advanced wiring are in the ShapeFile Provider Guide.