Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#36: Added tileCover to GeoJSON #39

Merged
merged 2 commits into from
Dec 4, 2023
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
41 changes: 22 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -824,16 +824,17 @@ Hint: Most algorithms are optimized for EPSG:4326. Using other projections will
| rhumb-destination | `let destination = coordinate.rhumbDestination(distance: 1000.0, bearing: 0.0)` | | [Source][106] / [Tests][107] |
| rhumb-distance | `let distance = coordinate1.rhumbDistance(from: coordinate2)` | | [Source][108] / [Tests][109] |
| simplify | `let simplified = lineString. simplified(tolerance: 5.0, highQuality: false)` | | [Source][110] / [Tests][111] |
| transform-coordinates | `let transformed = anyGeometry.transformCoordinates({ $0 })` | | [Source][112] / [Tests][113] |
| transform-rotate | `let transformed = anyGeometry. transformedRotate(angle: 25.0, pivot: Coordinate3D(…))` | | [Source][114] / [Tests][115] |
| transform-scale | `let transformed = anyGeometry. transformedScale(factor: 2.5, anchor: .center)` | | [Source][116] / [Tests][117] |
| transform-translate | `let transformed = anyGeometry. transformedTranslate(distance: 1000.0, direction: 25.0)` | | [Source][118] / [Tests][119] |
| truncate | `let truncated = lineString.truncated(precision: 2, removeAltitude: true)` | | [Source][120] / [Tests][121] |
| union | TODO | | [Source][122] |
| tile-cover | `let tileCover = anyGeometry.tileCover(atZoom: 14)` | | [Source][112] / [Tests][113] |
| transform-coordinates | `let transformed = anyGeometry.transformCoordinates({ $0 })` | | [Source][114] / [Tests][115] |
| transform-rotate | `let transformed = anyGeometry. transformedRotate(angle: 25.0, pivot: Coordinate3D(…))` | | [Source][116] / [Tests][117] |
| transform-scale | `let transformed = anyGeometry. transformedScale(factor: 2.5, anchor: .center)` | | [Source][118] / [Tests][119] |
| transform-translate | `let transformed = anyGeometry. transformedTranslate(distance: 1000.0, direction: 25.0)` | | [Source][120] / [Tests][121] |
| truncate | `let truncated = lineString.truncated(precision: 2, removeAltitude: true)` | | [Source][122] / [Tests][123] |
| union | TODO | | [Source][124] |

# Related packages
Currently only one:
- [mvt-tools][123]: Vector tiles reader/writer for Swift
- [mvt-tools][125]: Vector tiles reader/writer for Swift

# Contributing
Please create an issue or open a pull request with a fix or enhancement.
Expand Down Expand Up @@ -955,18 +956,20 @@ Thomas Rasch, Outdooractive
[109]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Turf/RhumbDistanceTests.swift "RhumbDistanceTests"
[110]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Turf/Simplify.swift "Simplify"
[111]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Turf/SimplifyTests.swift "SimplifyTests"
[112]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Turf/TransformCoordinates.swift "TransformCoordinates"
[113]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Turf/TransformCoordinatesTests.swift "TransformCoordinatesTests"
[114]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Turf/TransformRotate.swift "TransformRotate"
[115]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Turf/TransformRotateTests.swift "TransformRotateTests"
[116]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Turf/TransformScale.swift "TransformScale"
[117]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Turf/TransformScaleTests.swift "TransformScaleTests"
[118]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Turf/TransformTranslate.swift "TransformTranslate"
[119]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Turf/TransformTranslateTests.swift "TransformTranslateTests"
[120]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Turf/Truncate.swift "Truncate"
[121]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Turf/TruncateTests.swift "TruncateTests"
[122]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Turf/Union.swift "Union"
[123]: https://github.com/Outdooractive/mvt-tools
[112]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Turf/TileCover.swift "TileCover"
[113]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Turf/TileCoverTests.swift "TileCoverTests"
[114]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Turf/TransformCoordinates.swift "TransformCoordinates"
[115]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Turf/TransformCoordinatesTests.swift "TransformCoordinatesTests"
[116]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Turf/TransformRotate.swift "TransformRotate"
[117]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Turf/TransformRotateTests.swift "TransformRotateTests"
[118]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Turf/TransformScale.swift "TransformScale"
[119]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Turf/TransformScaleTests.swift "TransformScaleTests"
[120]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Turf/TransformTranslate.swift "TransformTranslate"
[121]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Turf/TransformTranslateTests.swift "TransformTranslateTests"
[122]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Turf/Truncate.swift "Truncate"
[123]: https://github.com/Outdooractive/gis-tools/blob/main/Tests/GISToolsTests/Turf/TruncateTests.swift "TruncateTests"
[124]: https://github.com/Outdooractive/gis-tools/blob/main/Sources/GISTools/Turf/Union.swift "Union"
[125]: https://github.com/Outdooractive/mvt-tools

[image-1]: https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FOutdooractive%2Fgis-tools%2Fbadge%3Ftype%3Dswift-versions
[image-2]: https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FOutdooractive%2Fgis-tools%2Fbadge%3Ftype%3Dplatforms
18 changes: 18 additions & 0 deletions Sources/GISTools/Algorithms/TileCover.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#if !os(Linux)
import CoreLocation
#endif
import Foundation

extension GeoJson {

public func tileCover(atZoom zoom: Int) -> [MapTile] {
var tiles: Set<MapTile> = []

allCoordinates.forEach { coordinate in
tiles.insert(MapTile(coordinate: coordinate, atZoom: zoom))
}

return Array(tiles)
}

}
2 changes: 1 addition & 1 deletion Sources/GISTools/Other/MapTile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public struct MapTile: CustomStringConvertible {
public let z: Int

public var description: String {
"MapTile<\(x),\(y))@\(z)>"
"MapTile<(\(x),\(y))@\(z)>"
}

public var parent: MapTile {
Expand Down
28 changes: 28 additions & 0 deletions Tests/GISToolsTests/Algorithms/TileCoverTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@testable import GISTools
import XCTest

final class TileCoverTests: XCTestCase {

func testTileCover1() {
let point = Point(Coordinate3D(latitude: 45.0, longitude: 90.0))
let tileCover = point.tileCover(atZoom: 1)
XCTAssertEqual(tileCover, [MapTile(x: 1, y: 0, z: 1)])
}

func testTileCover2() {
let lineString = LineString([
Coordinate3D(latitude: 10.0, longitude: -10.0),
Coordinate3D(latitude: 10.0, longitude: 10.0),
Coordinate3D(latitude: -10.0, longitude: 10.0),
Coordinate3D(latitude: -10.0, longitude: -10.0),
])!
let tileCover = lineString.tileCover(atZoom: 2)
XCTAssertEqual(Set(tileCover), Set([
MapTile(x: 1, y: 1, z: 2),
MapTile(x: 1, y: 2, z: 2),
MapTile(x: 2, y: 1, z: 2),
MapTile(x: 2, y: 2, z: 2),
]))
}

}