ESRI Shapefile (.shp/.dbf/.shx/.prj) read and write support for Swift, built on top of gis-tools.
- Reads and writes Point, PolyLine, Polygon, MultiPoint, and MultiPatch geometry types, including Z and M variants
- Reads
.prjfiles to determine the source projection (EPSG:4326 assumed if absent) - Writes
.prjfiles matching the output projection - Attributes are mapped to and from
Feature.propertiesvia the companion.dbffile - Writes
.shxindex files for compatibility with tools that require them - Multipatch geometries are decomposed into
GeometryCollectionwithPolygonparts
Swift 6.1 or higher. Compiles on iOS (≥ iOS 15), macOS (≥ macOS 15), tvOS (≥ tvOS 15), watchOS (≥ watchOS 7), Linux, Android and Wasm.
dependencies: [
.package(url: "https://github.com/Outdooractive/gis-tools-shapefile", from: "1.0.1"),
.package(url: "https://github.com/Outdooractive/gis-tools", from: "2.0.0"),
],
targets: [
.target(name: "MyTarget", dependencies: [
.product(name: "GISToolsShapefile", package: "gis-tools-shapefile"),
.product(name: "GISTools", package: "gis-tools"),
]),
]import GISTools
import GISToolsShapefile
let url = URL(fileURLWithPath: "/path/to/file.shp")
let fc = try FeatureCollection(shapefile: url)
// Or via ShapefileCoder directly:
let fc = try ShapefileCoder.read(from: url)import GISTools
import GISToolsShapefile
let url = URL(fileURLWithPath: "/path/to/new_file.shp")
try fc.writeShapefile(to: url)
// Or via ShapefileCoder directly:
try ShapefileCoder.write(fc, to: url)The shapefile path is constructed from the base URL by replacing the extension:
.shp— geometry data.dbf— attribute data.shx— spatial index.prj— projection string
- GeoJSON
idvalues are mapped to anidcolumn in the.dbffile - Maximum field count: 1024 per dBase specification
- Maximum record size: 65531 bytes per dBase specification
- Field name length: maximum 10 characters per dBase specification
- Multipatch geometry is read-only (converted to
GeometryCollection) - AutoCAD Civil 3D and ArcGIS variants are not supported
Please create an issue or open a pull request with a fix or enhancement.
MIT
Thomas Rasch, Outdooractive
Built on top of gis-tools.