Skip to content

IRI.Maptor.Sta.ShapefileFormat Coordinate Systems

Hossein Narimani Rad edited this page Sep 28, 2025 · 3 revisions

Coordinate Systems

Overview

The IRI.Maptor.Sta.ShapefileFormat library provides comprehensive support for coordinate systems and projections through the PRJ file format and built-in coordinate system definitions.

Working with PRJ Files

Reading Coordinate System Information

// Read shapefile with coordinate system
var shapes = await Shapefile.ReadShapesAsync("file.shp", "file.prj");

// Access coordinate system information
var coordinateSystem = shapes.CoordinateSystem;
Console.WriteLine($"Projection: {coordinateSystem.Name}");
Console.WriteLine($"WKT: {coordinateSystem.Wkt}");

Creating Coordinate Systems

// From PRJ file
var coordSys = CoordinateSystem.FromPrjFile("projection.prj");

// From EPSG code
var wgs84 = CoordinateSystem.FromEpsgCode(4326);
var webMercator = CoordinateSystem.FromEpsgCode(3857);

Common Coordinate Systems

Geographic Coordinate Systems

// WGS84 (EPSG:4326)
var wgs84 = CoordinateSystem.FromEpsgCode(4326);

// NAD83 (EPSG:4269)
var nad83 = CoordinateSystem.FromEpsgCode(4269);

Projected Coordinate Systems

// Web Mercator (EPSG:3857)
var webMercator = CoordinateSystem.FromEpsgCode(3857);

// UTM Zone 10N (EPSG:32610)
var utm10N = CoordinateSystem.FromEpsgCode(32610);

Coordinate Transformations

Transforming Geometries

// Read shapefile in one coordinate system
var shapes = await Shapefile.ReadShapesAsync("input.shp", "input.prj");

// Transform to Web Mercator
var targetCoordSys = CoordinateSystem.FromEpsgCode(3857);
var transformedShapes = shapes.TransformTo(targetCoordSys);

// Write transformed shapes
await Shapefile.WriteShapesAsync(transformedShapes, "output.shp");

Working with Different Projections

// Transform from UTM to Geographic
var utmShapes = await Shapefile.ReadShapesAsync("utm_data.shp");
var geographicShapes = utmShapes.TransformTo(CoordinateSystem.FromEpsgCode(4326));

// Transform from Geographic to Web Mercator
var webMercatorShapes = geographicShapes.TransformTo(CoordinateSystem.FromEpsgCode(3857));

Supported Projections

Geographic Projections

  • WGS84 (EPSG:4326)
  • NAD83 (EPSG:4269)
  • NAD27 (EPSG:4267)

UTM Projections

  • UTM Zone 1N-60N (EPSG:32601-32660)
  • UTM Zone 1S-60S (EPSG:32701-32760)

Web Projections

  • Web Mercator (EPSG:3857)
  • Pseudo-Mercator (EPSG:3857)

State Plane Projections

  • Various State Plane Coordinate Systems
  • Lambert Conformal Conic
  • Transverse Mercator

Creating PRJ Files

From Coordinate System

var coordSys = CoordinateSystem.FromEpsgCode(4326);
await coordSys.WritePrjFileAsync("output.prj");

Custom WKT

var customWkt = @"GEOGCS[""WGS 84"",DATUM[""WGS_1984"",SPHEROID[""WGS 84"",6378137,298.257223563]],PRIMEM[""Greenwich"",0],UNIT[""degree"",0.0174532925199433]]";
var coordSys = new CoordinateSystem("WGS 84", customWkt);

Validation

Coordinate System Validation

try
{
    var coordSys = CoordinateSystem.FromPrjFile("file.prj");
    Console.WriteLine($"Valid coordinate system: {coordSys.Name}");
}
catch (InvalidCoordinateSystemException ex)
{
    Console.WriteLine($"Invalid coordinate system: {ex.Message}");
}

Bounding Box Validation

var shapes = await Shapefile.ReadShapesAsync("file.shp");
var boundingBox = shapes.GetBoundingBox();

// Check if coordinates are within expected range
if (boundingBox.MinX < -180 || boundingBox.MaxX > 180)
{
    Console.WriteLine("Warning: X coordinates outside valid longitude range");
}

Performance Considerations

Coordinate System Caching

// Coordinate systems are automatically cached
var coordSys1 = CoordinateSystem.FromEpsgCode(4326);
var coordSys2 = CoordinateSystem.FromEpsgCode(4326);
// coordSys1 and coordSys2 reference the same cached instance

Batch Transformations

// For multiple transformations, use batch processing
var sourceCoordSys = CoordinateSystem.FromEpsgCode(4326);
var targetCoordSys = CoordinateSystem.FromEpsgCode(3857);

var transformedShapes = shapes
    .AsParallel()
    .Select(shape => shape.TransformTo(targetCoordSys))
    .ToList();

For more examples, see the Examples page

Maptor Wiki

🏠 Home

πŸ“š Library Groups

πŸ“¦ IRI.Maptor.Sta

πŸ“ IRI.Maptor.Sta.ShapefileFormat

πŸ”§ IRI.Maptor.Ket

Coming Soon

πŸ–₯️ IRI.Maptor.Jab

Coming Soon

πŸš€ Getting Started

πŸ”— External Resources


Maptor Spatial Library Ecosystem

Clone this wiki locally