Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ All notable changes to this project are documented in this file.

### Fixed

- Package traits can be enabled together: `EnableMeterConversionExtensions`
and `EnableMeasurementConversionExtensions` no longer abort the build with an
`#error` when both are on. `EnableMeasurementConversionExtensions` now takes
precedence, so `swift build --enable-all-traits` works and the Swift Package
Index documentation builder — which extracts symbol graphs with every trait
enabled — can generate the DocC archive again. Previously every documentation
build failed, so the hosted docs were stale and contained neither the DocC
articles nor the Graph API.

- Documentation build diagnostics: the DocC catalog is now built with all
traits enabled, matching Swift Package Index, and the five broken symbol
links that only appear with the Graph trait (`articulationPoints()`,
`eulerianity()`, `nodeOnEdge(near:tolerance:)`, `expandPath(_:using:)` and
the undocumented `result` parameter) are fixed.

- Line clipping across the antimeridian (#408): `LineString.clipped(to:)` and
`MultiLineString.clipped(to:)` no longer drop one half of a segment that
spans more than 180° of longitude. Such a segment is unwrapped across the
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ let package = Package(
description: "Enables graph construction, routing and network analysis APIs."),
.trait(
name: "EnableMeterConversionExtensions",
description: "Adds conversion properties that return raw Double values in meters."),
description: "Adds conversion properties that return raw Double values in meters. Ignored when EnableMeasurementConversionExtensions is also enabled."),
.trait(
name: "EnableMeasurementConversionExtensions",
description: "Adds conversion properties that return Measurement<UnitLength> values for unit-aware arithmetic."),
description: "Adds conversion properties that return Measurement<UnitLength> values for unit-aware arithmetic. Takes precedence over EnableMeterConversionExtensions."),
],
dependencies: [],
targets: [
Expand Down
69 changes: 43 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


# GISTools
GIS tools for Swift, including a [GeoJSON][3] implementation and many algorithms ported from [https://turfjs.org][4].
GIS tools for Swift, including a [GeoJSON][3] implementation and many spatial algorithms. The algorithms combine ports from [turf.js][4], GEOS, PROJ and Mapbox polylabel with implementations written from scratch for this package.

## Table of Contents

Expand Down Expand Up @@ -62,20 +62,21 @@ GIS tools for Swift, including a [GeoJSON][3] implementation and many algorithms
## Documentation

The [DocC catalog](Sources/GISTools/GISTools.docc/GISTools.md) contains focused
guides for the main workflows:

- [Getting started](Sources/GISTools/GISTools.docc/GettingStarted.md)
- [Projections and antimeridian handling](Sources/GISTools/GISTools.docc/ProjectionsAndAntimeridian.md)
- [GeoJSON and WKB/WKT/TWKB](Sources/GISTools/GISTools.docc/GeoJSONAndCoders.md)
- [Query DSL](Sources/GISTools/GISTools.docc/QueryDSL.md)
- [Graph API](Sources/GISTools/GISTools.docc/GraphAPI.md)
- [Performance and memory notes](Sources/GISTools/GISTools.docc/PerformanceAndMemory.md)
- [CSV](Sources/GISTools/GISTools.docc/CSV.md)
- [FIT](Sources/GISTools/GISTools.docc/FIT.md)
- [GeoPackage](Sources/GISTools/GISTools.docc/GeoPackage.md)
- [GPX](Sources/GISTools/GISTools.docc/GPX.md)
- [Shapefile](Sources/GISTools/GISTools.docc/Shapefile.md)
- [Migrating to GISTools 3.0](Sources/GISTools/GISTools.docc/MigrationGuide.md)
guides for the main workflows, published on Swift Package Index:

- [Getting started][doc-gettingstarted]
- [Projections and antimeridian handling][doc-projections]
- [GeoJSON and WKB/WKT/TWKB][doc-geojsoncoders]
- [Query DSL][doc-querydsl]
- [Graph API][doc-graphapi]
- [Performance and memory notes][doc-performance]
- [CSV][doc-csv]
- [FIT][doc-fit]
- [GeoPackage][doc-geopackage]
- [GPX][doc-gpx]
- [Shapefile][doc-shapefile]
- [mvt-tools (MVT and MLT)][doc-mvttools]
- [Migrating to GISTools 3.0][doc-migration]

The generated API reference is available on
[Swift Package Index](https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools).
Expand All @@ -97,7 +98,7 @@ algorithms.
- [**gis-tools-fit**](https://github.com/Outdooractive/gis-tools-fit) — reads and writes FIT activity files (.fit)
- [**mvt-tools**](https://github.com/Outdooractive/mvt-tools) — reads and writes Mapbox Vector Tiles (MVT) and MapLibre Tiles (MLT); despite its name, its `mvt` command-line tool converts between all supported formats (MVT, MLT, GeoJSON, GPX, FIT, CSV, Shapefile and GeoPackage), and is available via `brew install Outdooractive/homebrew-tap/mvt-tools`
- Spatial search with a R-tree
- Includes many spatial algorithms (ported from turf.js), and more to come
- Includes many spatial algorithms (ported from turf.js, GEOS and PROJ, or written from scratch), and more to come
- Many algorithms accept a `gridSize` parameter to snap coordinates to a uniform grid before computation, reducing noise from floating-point precision
- Handles coordinates across the anti-meridian (±180° longitude) — geometries can wrap around the date line
- Has a helper for working with x/y/z map tiles (center/bounding box/resolution/…)
Expand All @@ -118,7 +119,7 @@ For EPSG:4978 and noSRID, returns the original geometry unchanged (the antimerid

> **Upgrading to 3.0?** The containment API, validity semantics, projected
> coordinates, unlocated features, bounding boxes and graph trait changed. See
> the [3.0 migration guide](Sources/GISTools/GISTools.docc/MigrationGuide.md)
> the [3.0 migration guide][doc-migration]
> and [CHANGELOG.md](CHANGELOG.md) for the complete list.

## Requirements
Expand Down Expand Up @@ -146,10 +147,14 @@ targets: [

This package provides the following optional traits:

**Unit conversion traits** (mutually exclusive):
**Unit conversion traits** (alternatives — enable one):
- `EnableMeasurementConversionExtensions` — conversion properties return `Measurement<UnitLength>` values, enabling unit-aware arithmetic and formatting.
- `EnableMeterConversionExtensions` — conversion properties return raw `Double` meters, providing a lightweight alternative.

If both are enabled, `EnableMeasurementConversionExtensions` takes precedence,
so builds that turn on every trait (such as `swift build --enable-all-traits`)
still compile.

```swift
// With EnableMeasurementConversionExtensions:
let distance: Measurement<UnitLength> = 1000.0.meters
Expand Down Expand Up @@ -690,7 +695,7 @@ Then create your models like this:

This is necessary because SwiftData doesn't work well with the default Codable implementation, so you need to do the serialization for yourself.

A complete model, container and fetch example is in the [GeoJSON and WKB/WKT/TWKB guide](Sources/GISTools/GISTools.docc/GeoJSONAndCoders.md).
A complete model, container and fetch example is in the [GeoJSON and WKB/WKT/TWKB guide][doc-geojsoncoders].

# WKB/WKT/TWKB
The following geometry types are supported: `point`, `linestring`, `linearring`, `polygon`, `multipoint`, `multilinestring`, `multipolygon`, `geometrycollection` and `triangle`. Please open an issue if you need more.
Expand Down Expand Up @@ -1223,17 +1228,17 @@ let fc = graph.toFeatureCollection()

Companion packages built on GISTools:

- [**gis-tools-csv**](https://github.com/Outdooractive/gis-tools-csv) — CSV and PostGIS CSV exports ([guide](Sources/GISTools/GISTools.docc/CSV.md))
- [**gis-tools-fit**](https://github.com/Outdooractive/gis-tools-fit) — Garmin FIT activities ([guide](Sources/GISTools/GISTools.docc/FIT.md))
- [**gis-tools-geopackage**](https://github.com/Outdooractive/gis-tools-geopackage) — OGC GeoPackage files ([guide](Sources/GISTools/GISTools.docc/GeoPackage.md))
- [**gis-tools-gpx**](https://github.com/Outdooractive/gis-tools-gpx) — GPX 1.1 routes and tracks ([guide](Sources/GISTools/GISTools.docc/GPX.md))
- [**gis-tools-shapefile**](https://github.com/Outdooractive/gis-tools-shapefile) — ESRI Shapefiles ([guide](Sources/GISTools/GISTools.docc/Shapefile.md))
- [**gis-tools-csv**](https://github.com/Outdooractive/gis-tools-csv) — CSV and PostGIS CSV exports ([guide][doc-csv])
- [**gis-tools-fit**](https://github.com/Outdooractive/gis-tools-fit) — Garmin FIT activities ([guide][doc-fit])
- [**gis-tools-geopackage**](https://github.com/Outdooractive/gis-tools-geopackage) — OGC GeoPackage files ([guide][doc-geopackage])
- [**gis-tools-gpx**](https://github.com/Outdooractive/gis-tools-gpx) — GPX 1.1 routes and tracks ([guide][doc-gpx])
- [**gis-tools-shapefile**](https://github.com/Outdooractive/gis-tools-shapefile) — ESRI Shapefiles ([guide][doc-shapefile])

Each guide covers installation, formats, supported APIs and limitations.

Additional vector-tile tools:

- [mvt-tools][125]: Vector tiles reader/writer for Swift
- [**mvt-tools**](https://github.com/Outdooractive/mvt-tools) — Mapbox Vector Tiles (MVT) and MapLibre Tiles (MLT), plus the `mvt` CLI ([guide][doc-mvttools])
- [mvt-postgis][130]: Creates vector tiles from Postgis databases

# Development
Expand All @@ -1255,6 +1260,19 @@ Thomas Rasch, Outdooractive
[3]: https://www.rfc-editor.org/rfc/rfc7946
[4]: https://github.com/Turfjs/turf/tree/master/packages
[5]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/GISTool.swift
[doc-gettingstarted]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/gettingstarted
[doc-projections]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/projectionsandantimeridian
[doc-geojsoncoders]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/geojsonandcoders
[doc-querydsl]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/querydsl
[doc-graphapi]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/graphapi
[doc-performance]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/performanceandmemory
[doc-csv]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/csv
[doc-fit]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/fit
[doc-geopackage]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/geopackage
[doc-gpx]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/gpx
[doc-shapefile]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/shapefile
[doc-mvttools]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/mvttools
[doc-migration]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/migrationguide
[6]: https://www.rfc-editor.org/rfc/rfc7946
[8]: https://swiftpackageindex.com/Outdooractive/gis-tools/main/documentation/gistools
[9]: https://github.com/Outdooractive/gis-tools/tree/main/Tests/GISToolsTests/GeoJson
Expand Down Expand Up @@ -1352,7 +1370,6 @@ Thomas Rasch, Outdooractive
[122]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Algorithms/Truncate.swift "Truncate"
[123]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Algorithms/TruncateTests.swift "TruncateTests"
[124]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Algorithms/Union.swift "Union"
[125]: https://github.com/Outdooractive/mvt-tools
[126]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Algorithms/BooleanDisjoint.swift "BooleanDisjoint"
[127]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Algorithms/BooleanDisjointTests.swift "BooleanDisjointTests"
[128]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Algorithms/BooleanIntersects.swift "BooleanIntersects"
Expand Down
4 changes: 1 addition & 3 deletions Sources/GISTools/Extensions/DoubleExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ extension Double {

}

#endif

#if EnableMeterConversionExtensions
#elseif EnableMeterConversionExtensions

extension Double {

Expand Down
11 changes: 5 additions & 6 deletions Sources/GISTools/Extensions/IntExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Foundation

#if EnableMeterConversionExtensions && EnableMeasurementConversionExtensions
#error("EnableMeterConversionExtensions and EnableMeasurementConversionExtensions are mutually exclusive")
#endif
// The two conversion traits are alternatives, not complements:
// `EnableMeasurementConversionExtensions` wins when both are enabled, so that
// builds which turn on every trait (e.g. `swift build --enable-all-traits` or
// the Swift Package Index documentation builder) still compile.

#if EnableMeasurementConversionExtensions

Expand Down Expand Up @@ -80,9 +81,7 @@ extension Int {

}

#endif

#if EnableMeterConversionExtensions
#elseif EnableMeterConversionExtensions

// MARK: Public

Expand Down
8 changes: 7 additions & 1 deletion Sources/GISTools/GISTools.docc/CSV.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,10 @@ by first appearance across all features.

## Related packages

<doc:FIT>, <doc:GeoPackage>, <doc:GPX>, <doc:Shapefile>, <doc:MVTTools>
[FIT][fit], [GeoPackage][geopackage], [GPX][gpx], [Shapefile][shapefile], [mvt-tools][mvttools]

[fit]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/fit
[geopackage]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/geopackage
[gpx]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/gpx
[shapefile]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/shapefile
[mvttools]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/mvttools
8 changes: 7 additions & 1 deletion Sources/GISTools/GISTools.docc/FIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,10 @@ timestamps.

## Related packages

<doc:CSV>, <doc:GeoPackage>, <doc:GPX>, <doc:Shapefile>, <doc:MVTTools>
[CSV][csv], [GeoPackage][geopackage], [GPX][gpx], [Shapefile][shapefile], [mvt-tools][mvttools]

[csv]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/csv
[geopackage]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/geopackage
[gpx]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/gpx
[shapefile]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/shapefile
[mvttools]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/mvttools
40 changes: 24 additions & 16 deletions Sources/GISTools/GISTools.docc/GISTools.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ The package covers:
- Opt-in graph construction, routing and network analysis

Companion packages add CSV, FIT, GeoPackage, GPX and Shapefile support:
<doc:CSV>, <doc:FIT>, <doc:GeoPackage>, <doc:GPX> and <doc:Shapefile>. Tiled
vector formats (MVT and MLT) and the `mvt` CLI live in <doc:MVTTools>.
[CSV][csv], [FIT][fit], [GeoPackage][geopackage], [GPX][gpx] and [Shapefile][shapefile]. Tiled
vector formats (MVT and MLT) and the `mvt` CLI live in [mvt-tools][mvttools].

> Important: GISTools 3.0 contains source-breaking changes to containment,
> validity, projected coordinates, unlocated features, bounding boxes and the
> graph API. Read <doc:MigrationGuide> before upgrading.
> graph API. Read [Migrating to GISTools 3.0][migration] before upgrading.

## Quick example

Expand All @@ -48,28 +48,36 @@ let decoded = Feature(jsonString: json)

### Essentials

- <doc:GettingStarted>
- <doc:ProjectionsAndAntimeridian>
- <doc:GeoJSONAndCoders>
- [Getting started](doc:GettingStarted)
- [Projections and antimeridian handling](doc:ProjectionsAndAntimeridian)
- [GeoJSON and WKB/WKT/TWKB](doc:GeoJSONAndCoders)

### Querying and routing

- <doc:QueryDSL>
- <doc:GraphAPI>
- [Query DSL](doc:QueryDSL)
- [Graph API](doc:GraphAPI)

### Related packages

- <doc:CSV>
- <doc:FIT>
- <doc:GeoPackage>
- <doc:GPX>
- <doc:Shapefile>
- <doc:MVTTools>
- [CSV](doc:CSV)
- [FIT](doc:FIT)
- [GeoPackage](doc:GeoPackage)
- [GPX](doc:GPX)
- [Shapefile](doc:Shapefile)
- [mvt-tools](doc:MVTTools)

### Performance

- <doc:PerformanceAndMemory>
- [Performance and memory notes](doc:PerformanceAndMemory)

### Migration

- <doc:MigrationGuide>
- [Migrating to GISTools 3.0](doc:MigrationGuide)

[csv]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/csv
[fit]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/fit
[geopackage]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/geopackage
[gpx]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/gpx
[shapefile]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/shapefile
[mvttools]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/mvttools
[migration]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/migrationguide
8 changes: 7 additions & 1 deletion Sources/GISTools/GISTools.docc/GPX.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,10 @@ namespaces are preserved. GPX 1.0 input is read-only; writing always emits GPX

## Related packages

<doc:CSV>, <doc:FIT>, <doc:GeoPackage>, <doc:Shapefile>, <doc:MVTTools>
[CSV][csv], [FIT][fit], [GeoPackage][geopackage], [Shapefile][shapefile], [mvt-tools][mvttools]

[csv]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/csv
[fit]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/fit
[geopackage]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/geopackage
[shapefile]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/shapefile
[mvttools]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/mvttools
10 changes: 7 additions & 3 deletions Sources/GISTools/GISTools.docc/GeoJSONAndCoders.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ encoded to WKB or WKT; encoding returns `nil`.

## Next steps

- <doc:QueryDSL> for filtering features by properties and location.
- <doc:PerformanceAndMemory> for loading and encoding performance.
- <doc:MigrationGuide> for the 3.0 unlocated-feature and parsing changes.
- [Query DSL][query-dsl] for filtering features by properties and location.
- [Performance and memory notes][performance] for loading and encoding performance.
- [Migrating to GISTools 3.0][migration] for the 3.0 unlocated-feature and parsing changes.

[query-dsl]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/querydsl
[performance]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/performanceandmemory
[migration]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/migrationguide
8 changes: 7 additions & 1 deletion Sources/GISTools/GISTools.docc/GeoPackage.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,10 @@ Attribute columns other than `fid`, `id` and geometry are mapped as:

## Related packages

<doc:CSV>, <doc:FIT>, <doc:GPX>, <doc:Shapefile>, <doc:MVTTools>
[CSV][csv], [FIT][fit], [GPX][gpx], [Shapefile][shapefile], [mvt-tools][mvttools]

[csv]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/csv
[fit]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/fit
[gpx]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/gpx
[shapefile]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/shapefile
[mvttools]: https://swiftpackageindex.com/Outdooractive/gis-tools/documentation/gistools/mvttools
Loading
Loading