Repository navigation
IRI.Maptor.Sta.ShapefileFormat Usage Guide
Hossein Narimani Rad edited this page Sep 28, 2025
·
3 revisions
The IRI.Maptor.Sta.ShapefileFormat library provides comprehensive support for reading, writing, and manipulating ESRI Shapefile formats.
using IRI.Maptor.Sta.ShapefileFormat;
// Read all shapes from a shapefile
var shapes = await Shapefile.ReadShapesAsync("path/to/your/file.shp");
foreach (var shape in shapes)
{
Console.WriteLine($"Shape ID: {shape.RecordNumber}");
Console.WriteLine($"Geometry: {shape.AsSqlServerWkt()}");
}// Read shapes with attribute data
var shapesWithAttributes = await Shapefile.ReadShapesWithAttributesAsync("path/to/your/file.shp");
foreach (var shape in shapesWithAttributes)
{
Console.WriteLine($"Shape ID: {shape.RecordNumber}");
Console.WriteLine($"Geometry: {shape.AsSqlServerWkt()}");
// Access attribute data
foreach (var attribute in shape.Attributes)
{
Console.WriteLine($"{attribute.Key}: {attribute.Value}");
}
}// Create a new shapefile
var shapes = new List<ShapefileShape>();
// Add your shapes here...
// Write to file
await Shapefile.WriteShapesAsync(shapes, "output/path.shp");// Create a point
var point = new PointShape(recordNumber: 1, x: 10.0, y: 20.0);
// Add to shapefile
shapes.Add(point);// Create a polyline
var points = new[] {
new Point(0, 0),
new Point(10, 0),
new Point(10, 10)
};
var polyline = new PolylineShape(recordNumber: 1, points);
shapes.Add(polyline);// Read shapefile with coordinate system information
var shapes = await Shapefile.ReadShapesAsync("file.shp", "file.prj");
// Access coordinate system
var coordinateSystem = shapes.CoordinateSystem;
Console.WriteLine($"Projection: {coordinateSystem.Name}");// For large files, use streaming approach
await foreach (var shape in Shapefile.ReadShapesStreamAsync("large_file.shp"))
{
// Process each shape individually
ProcessShape(shape);
}// Dispose resources properly
using var shapefile = new ShapefileReader("file.shp");
var shapes = await shapefile.ReadAllAsync();
// Resources are automatically disposedtry
{
var shapes = await Shapefile.ReadShapesAsync("file.shp");
}
catch (ShapefileException ex)
{
Console.WriteLine($"Shapefile error: {ex.Message}");
}
catch (FileNotFoundException ex)
{
Console.WriteLine($"File not found: {ex.FileName}");
}For more examples, see the Examples page
π Home
π IRI.Maptor.Sta.ShapefileFormat
Coming Soon
Coming Soon
Maptor Spatial Library Ecosystem