Skip to content

Commit

Permalink
Add Playground to swiftlint config
Browse files Browse the repository at this point in the history
  • Loading branch information
macdrevx authored and Andrew Hershberger committed Aug 7, 2018
1 parent 36e36b5 commit 7ef562c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
included: # paths to include during linting. `--path` is ignored if present.
- GEOSwift
- GEOSwiftTests
- GEOSwift.playground
disabled_rules:
- force_cast
- identifier_name
Expand Down
43 changes: 26 additions & 17 deletions GEOSwift.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import GEOSwift
import MapKit

Waypoint(WKT: "POINT(10 45)")
//: > _Note:_ Build the GEOSwift framework scheme targeting an iOS Simulator prior to use this Playground. You may have to close and reopen the project after building it.
//: > _Note:_ Build the GEOSwift framework scheme targeting an iOS Simulator prior to use this Playground.
//: You may have to close and reopen the project after building it.
//: # GEOSwift
//: _The Swift Geographic Engine._
//:
//: Easily handle geographical objects (points, linestrings, polygons etc.) and the main related topographical operations (intersections, overlapping etc.).
//: GEOSwift is basically a MIT-licensed Swift interface to the OSGeo's GEOS library routines*, plus some convenience features for iOS developers as:
//: Easily handle geographical objects (points, linestrings, polygons etc.) and the main related topographical
//: operations (intersections, overlapping etc.).
//: GEOSwift is basically a MIT-licensed Swift interface to the OSGeo's GEOS library routines*, plus some convenience
//: features for iOS developers as:
//:
//: * A pure-Swift, type-safe, optional-aware programming interface
//: * Automatically-typed geometry deserialization from WKT and WKB representations
Expand All @@ -29,12 +32,16 @@ Waypoint(WKT: "POINT(10 45)")
//: * MultiPolygon
//: * GeometryCollection
//:
//: Geometries can be deserialized from and serialized back to their Well Known Text (WKT) or Well Known Binary (WKB) representations, as they are defined in the _[Simple features for SQL](http://www.opengeospatial.org/standards/sfa)_ specification.
//: The default spatial reference system for geometry fields is WGS84 (meaning the SRID is 4326) – in other words, the geometry coordinates are in longitude, latitude pairs in units of degrees.
//: Geometries can be deserialized from and serialized back to their Well Known Text (WKT) or Well Known Binary (WKB)
//: representations, as they are defined in the _[Simple features for SQL](http://www.opengeospatial.org/standards/sfa)_
//: specification.
//: The default spatial reference system for geometry fields is WGS84 (meaning the SRID is 4326) – in other words, the
//: geometry coordinates are in longitude, latitude pairs in units of degrees.
// Create a POINT from its WKT representation.
let point = Waypoint(WKT: "POINT(10 45)")

// A geometry can be created even using the constructor `Geometry.create(WKT)` and casting the returned value to the desired subclass.
// A geometry can be created even using the constructor `Geometry.create(WKT)` and casting the returned value to the
// desired subclass.
let geometry1 = Geometry.create("POLYGON((35 10, 45 45.5, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))")

// The same geometry can be represented in binary form as a Well Known Binary.
Expand All @@ -54,31 +61,30 @@ if geometry1 == geometry2 && geometry1 != point {
// MULTILINESTRING((3 4,10 50,20 25),(-5 -8,-10 -8,-15 -4))
// MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2, 3 2, 3 3, 2 3,2 2)),((3 3,6 2,6 4,3 3)))
// GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10))

//: ### Mapkit integration
//:
//: Convert the geometries to a MKShape subclass, ready to be added as annotations to a MKMapView
//:
let shape1 = point!.mapShape()!
let shape2 = geometry1?.mapShape()!
let annotations = [shape1, shape2]

//: ### Quicklook integration
//:
//: GEOSwift geometries are integrated with Quicklook!
//: This means that while debugging you can inspect complex geometries and see what they represent: just stop on the variable with the mouse cursor or select the Geometry instance and press backspace in the Debug Area to see a preview.
//: This means that while debugging you can inspect complex geometries and see what they represent: just stop on the
//: variable with the mouse cursor or select the Geometry instance and press backspace in the Debug Area to see a
//: preview.
//: In Playgrounds you can display them just as any other object, like this:
geometry2

//: ### GEOJSON parsing
//:
//: Your geometries can be loaded from a GEOJSON file.
//:
if let geoJSONURL = Bundle.main.url(forResource: "multipolygon", withExtension: "geojson"),
let features = try! Features.fromGeoJSON(geoJSONURL),
let italy = features.first?.geometries?.first as? MultiPolygon {
italy
let features = try? Features.fromGeoJSON(geoJSONURL),
let italy = features?.first?.geometries?.first as? MultiPolygon {

italy
//: ### Topological operations:
//:
italy.buffer(width: 1)
Expand All @@ -91,7 +97,6 @@ if let geoJSONURL = Bundle.main.url(forResource: "multipolygon", withExtension:
italy.intersection(geometry2!)
italy.difference(geometry2!)
italy.union(geometry2!)

//: ### Predicates:
//:
italy.disjoint(geometry2!)
Expand All @@ -103,8 +108,12 @@ if let geoJSONURL = Bundle.main.url(forResource: "multipolygon", withExtension:
italy.overlaps(geometry2!)
italy.equals(geometry2!)
italy.relate(geometry2!, pattern: "T*****FF*")

}
//: [GEOS](http://trac.osgeo.org/geos/) stands for Geometry Engine - Open Source, and is a C++ library, ported from the [Java Topology Suite](http://sourceforge.net/projects/jts-topo-suite/). GEOS implements the OpenGIS [Simple Features for SQL](http://www.opengeospatial.org/standards/sfs) spatial predicate functions and spatial operators. GEOS, now an OSGeo project, was initially developed and maintained by [Refractions Research](http://www.refractions.net/) of Victoria, Canada.
//: [GEOS](http://trac.osgeo.org/geos/) stands for Geometry Engine - Open Source, and is a C++ library, ported from the
//: [Java Topology Suite](http://sourceforge.net/projects/jts-topo-suite/). GEOS implements the OpenGIS [Simple Features
//: for SQL](http://www.opengeospatial.org/standards/sfs) spatial predicate functions and spatial operators. GEOS, now
//: an OSGeo project, was initially developed and maintained by [Refractions Research](http://www.refractions.net/) of
//: Victoria, Canada.
//:
//: GEOSwift was released by Andrea Cremaschi ([@andreacremaschi](https://twitter.com/andreacremaschi)) under a MIT license. See LICENSE for more information.
//: GEOSwift was released by Andrea Cremaschi ([@andreacremaschi](https://twitter.com/andreacremaschi)) under a MIT
//: license. See LICENSE for more information.
14 changes: 7 additions & 7 deletions GEOSwift.playground/Sources/SupportCode.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//
// This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to GEOSwiftPlayground.playground.
// This file (and all other Swift source files in the Sources directory of this playground)
// will be precompiled into a framework which is automatically made available to GEOSwiftPlayground.playground.
//

import Foundation
Expand All @@ -8,22 +9,21 @@ extension NSData {
public class func fromHexString (string: String) -> NSData {
// Based on: http://stackoverflow.com/a/2505561/313633
let data = NSMutableData()

var temp = ""

for char in string.characters {
temp+=String(char)
if(temp.characters.count == 2) {
for char in string {
temp += String(char)
if temp.count == 2 {
let scanner = Scanner(string: temp)
var value: CUnsignedInt = 0
scanner.scanHexInt32(&value)
data.append(&value, length: 1)
temp = ""
}
}
return data as NSData
return data
}
}

// swiftlint:disable:next line_length
let geometryWKBHexString = "010300000002000000050000000000000000804140000000000000244000000000008046400000000000C046400000000000002E40000000000000444000000000000024400000000000003440000000000080414000000000000024400400000000000000000034400000000000003E40000000000080414000000000008041400000000000003E40000000000000344000000000000034400000000000003E40"
public func geometryWKB() -> NSData { return NSData.fromHexString(string: geometryWKBHexString) }

0 comments on commit 7ef562c

Please sign in to comment.