A lightweight, zero-dependency C++ tool designed to parse binary ESRI Shapefiles and project them using the Universal Transverse Mercator (UTM) projection system.
This project explores the complexities of localized map projections. Unlike the global Mercator projection, UTM is a grid-based system that divides the Earth into 60 zones to minimize distortion. Built from scratch without GIS libraries like GDAL or PROJ, this tool focuses on:
- Binary Data Parsing: Directly reading
.shpfiles, handling Big/Little Endian conversions, and navigating record headers. - Ellipsoidal Mathematics: Implementing the Krüger series for the Transverse Mercator projection, transforming Lat/Long into metric Easting and Northing coordinates based on the WGS84 ellipsoid.
- Dynamic Vector Rendering: Generating SVGs with an automated
viewBoxand fixed-point precision to handle large-scale metric coordinates (meters).
- Dependency-Free: Pure C++17 using only standard headers (
<cmath>,<vector>,<fstream>). - WGS84 Compliant: Uses standard ellipsoidal constants for high-accuracy local mapping.
- Automatic Zone Detection: Determines the optimal UTM zone based on the first geometry's longitude.
- Robust Parser: Manually handles the ESRI Shapefile technical specification (Type 5: Polygon).
- Smart Filtering: Automatically handles points far from the central meridian to prevent mathematical instability.
- A C++17 compatible compiler (GCC, Clang, or MSVC).
- CMake (version 3.10 or higher).
mkdir build && cd build
cmake ..
make
# Auto-detect zone
./utm_parser region.shp map.svg
# Force a specific zone (e.g., Zone 32 for Europe)
./utm_parser region.shp map.svg 32
The UTM system uses a Transverse Mercator projection. Unlike the standard Mercator, the "cylinder" is transverse to the Earth's axis.
- Units: The output coordinates are in meters.
- False Easting: A constant of 500,000m is added to X coordinates to ensure all values within a zone remain positive.
- ViewBox: The SVG generator calculates the min/max X and Y of the projected data to create a tight, high-resolution viewport.
Note: For best results, use regional shapefiles. UTM is designed for high accuracy within 6-degree longitudinal strips.