Package-level declarations

Types

Link copied to clipboard
Link copied to clipboard
class BoEvent(point: BoPoint, segments: ArrayList<BoSegment>, type: Int)
Link copied to clipboard
data class BoPoint(var x_coord: Double, var y_coord: Double)
Link copied to clipboard
class BoSegment(p1: BoPoint, p2: BoPoint)
Link copied to clipboard
Link copied to clipboard
class FeatureTree(featureCollection: FeatureCollection?)

FeatureTree is a class which stores FeatureCollections within an rtree which gives us faster spatial searching. The APIs are purely FeatureCollections - pass one in to create the tree and then call one of generateFeatureCollection, generateNearbyFeatureCollection or generateNearestFeatureCollection to return a FeatureCollection trimmed down by location.

Link copied to clipboard
data class FovLeftRight(val left: LngLatAlt, val right: LngLatAlt)
Link copied to clipboard
class Quadrant(heading: Double) : Segment
Link copied to clipboard
Link copied to clipboard
open class Segment(heading: Double, width: Double)
Link copied to clipboard
class TileGrid(newTiles: MutableList<Tile>, newCentralBoundingBox: BoundingBox)

Properties

Link copied to clipboard
Link copied to clipboard
const val EARTH_RADIUS_METERS: Double = 6378137.0
Link copied to clipboard
const val MAX_LATITUDE: Double = 85.05112878
Link copied to clipboard
const val MAX_LONGITUDE: Double = 180.0002
Link copied to clipboard
const val MIN_LATITUDE: Double
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard

Gives the heading from one point to another point.

Link copied to clipboard
fun calculateCenter(start: LngLatAlt, end: LngLatAlt, arcMidPoint: LngLatAlt): Circle

Calculate the approximate center coordinates of a circle based on the start and end coordinates of a segment and the arc midpoint.

Link copied to clipboard

Calculate the approximate center coordinates of a circle based on a segment.

Link copied to clipboard
fun calculateRadius(chordLength: Double, arcMidPoint: LngLatAlt, chordMidPoint: LngLatAlt): Double

Calculate the radius of a circle based on the chord length, arc midpoint and chord midpoint

Link copied to clipboard
fun checkWhetherIntersectionIsOfInterest(intersectionRoadNames: FeatureCollection, testNearestRoad: Feature?): Boolean
Link copied to clipboard
fun circleToPolygon(segments: Int, centerLat: Double, centerLon: Double, radius: Double): Polygon

Converts a circle to a polygon "circle".

Link copied to clipboard
fun cleanTileGeoJSON(tileX: Int, tileY: Int, zoom: Int, geoJSONTile: String): String

There's a bug in the backend API where the GeoJSON can contain data that isn't part of the tile for example the 16/32277/21812.json contains MultiPolygons for the University of Law, University of Bristol, and Monarchs Way walking route. This strips out Features that someone has wrapped giant polygons around in the original OSM data. Need to see if there is a fix for this on the backend...

Link copied to clipboard
fun clip(value: Double, minimum: Double, maximum: Double): Double

Clips a value to the range max, min.

Link copied to clipboard
fun createTriangleFOV(left: LngLatAlt, location: LngLatAlt, right: LngLatAlt): Polygon

Return a triangle that is used as a "field of view".

Link copied to clipboard
fun deduplicateFeatureCollection(outputFeatureCollection: FeatureCollection, inputFeatureCollection: FeatureCollection?, existingSet: MutableSet<Any>)

processFeatureCollection goes through the feature collection from a tile and adds it to the feature collection for the grid, deduplicating by OSM is as it goes.

Link copied to clipboard
fun dijkstraWithLoops(graph: Map<Int, List<Pair<Int, Int>>>, start: Int): Pair<Map<Int, Int>, Map<Int, Int>>
Link copied to clipboard
fun distance(lat1: Double, long1: Double, lat2: Double, long2: Double): Double

Compute the Haversine distance between the two coordinates.

fun distance(l1: LngLatAlt, l2: LngLatAlt, p: LngLatAlt, nearestPoint: LngLatAlt? = null): Double

Calculate distance of a point p to a line defined by two other points l1 and l2.

fun distance(x1: Double, y1: Double, x2: Double, y2: Double, x: Double, y: Double, nearestPoint: LngLatAlt? = null): Double

Calculate distance of a point (pLat,pLon) to a line defined by two other points (lat1,lon1) and (lat2,lon2)

Link copied to clipboard
fun distanceToLineString(pointCoordinates: LngLatAlt, lineStringCoordinates: LineString, nearestPoint: LngLatAlt? = null): Double

Distance to a LineString from current location.

Link copied to clipboard
fun distanceToPolygon(pointCoordinates: LngLatAlt, polygon: Polygon): Double

Distance to a Polygon from current location.

Link copied to clipboard

Given a Feature Collection that contains a LineString it will return a Feature Collection that contains the "exploded" LineString which are the individual segments of the LineString.

Link copied to clipboard

Given a Feature Collection that contains a Polygon it will return a Feature Collection that contains the "exploded" Polygon which are the individual segments of the Polygon as LineStrings.

Link copied to clipboard
fun findCircleCenter(arcMidPoint: LngLatAlt, chordBearing: Double, radius: Double): LngLatAlt

Calculate the center coordinates of a circle based on the arc midpoint, chord bearing and radius.

Link copied to clipboard
fun findClosestDirection(reference: Double, option1: Double, option2: Double): Double
Link copied to clipboard
Link copied to clipboard
fun fromRadians(degrees: Double): Double
Link copied to clipboard
Link copied to clipboard

This represent the original iOS AHEAD_BEHIND direction type which they described like this:

Link copied to clipboard

Given a BoundingBox returns the coordinates for the corners.

Link copied to clipboard

Given a LineString object returns the bounding box for it.

Link copied to clipboard

Given a MultiLineString object returns the bounding box for it.

Link copied to clipboard

Given a MultiPoint object return the bounding box for it.

Link copied to clipboard

Given a MultiPolygon object returns the bounding box for it.

Link copied to clipboard

Given a Point object returns the bounding box for it.

Link copied to clipboard

Given a Polygon object returns the bounding box.

Link copied to clipboard

Gives the coordinates for the center of a bounding box.

Link copied to clipboard

This represent the original iOS COMBINED direction type which they described like this:

Link copied to clipboard
fun getCompassLabelFacingDirection(localizedContext: Context, degrees: Int, inMotion: Boolean, inVehicle: Boolean): String
Link copied to clipboard
fun getCompassLabelFacingDirectionAlong(localizedContext: Context, degrees: Int, placeholder: String, inMotion: Boolean, inVehicle: Boolean): String
Link copied to clipboard
fun getDestinationCoordinate(start: LngLatAlt, bearing: Double, distance: Double): LngLatAlt

Return a destination coordinate based on a starting point, bearing and distance.

Link copied to clipboard

Returns a road direction type in relation to the intersection: The road is leading up to an intersection - LEADING → --------------⦿ The road starts from an intersection - TRAILING → ⦿-------------- The road is leading up to and continues on from an intersection - LEADING_AND_TRAILING → → -------⦿------- The road is not part of the intersection - NONE ⦿

Link copied to clipboard
fun getDistanceToFeature(currentLocation: LngLatAlt, feature: Feature?): Double

Given a Feature and a location this will calculate the nearest distance to it

Link copied to clipboard

Given a Feature Collection and location this will calculate the nearest distance to each Feature, and return a Feature Collection that contains the distance_to data for each Feature.

Link copied to clipboard
fun getFeatureNearestPoint(currentLocation: LngLatAlt, feature: Feature): LngLatAlt?
Link copied to clipboard
fun getFeaturesWithRoadDirection(road: Feature, intersectionRelativeDirections: FeatureCollection): FeatureCollection

Given a road Feature and a set of intersectionRelativeDirections this will return a feature collection with an entry for the road each time it appears in the intersection. Normally this would be a single Feature (one road leaving the intersection) but if the road loops around and back into the roundabout then there can be two entries - see intersectionsLoopBackTest for an example e.g. https://geojson.io/#map=18/37.339112/-122.038756

Link copied to clipboard

Return a Feature Collection that contains the Features within the "field of view" triangle.

Link copied to clipboard
Link copied to clipboard

This represent the original iOS INDIVIDUAL direction type which they described like this:

Link copied to clipboard
fun getIntersectionRoadNames(intersectionFeature: Feature?, roadsFeatureCollection: FeatureCollection): FeatureCollection

Get the road names/ref/road type that make up the intersection. Intersection objects only contain "osm_ids" so we need to hook the osm_ids up with the information from the roads feature collection

fun getIntersectionRoadNamesRelativeDirections(intersectionRoadNames: FeatureCollection, nearestIntersection: Feature?, intersectionRelativeDirections: FeatureCollection): FeatureCollection

Given an intersection Road names FeatureCollection, a nearest Intersection FeatureCollection and an intersectionRelativeDirections FeatureCollection. This will return a feature collection of the roads that make up the intersection tagged with their relative directions. 0 = Behind, 1 = Behind Left, 2 = Left, 3 = Ahead Left, 4 = Ahead, 5 = Ahead Right, 6 = Right, 7 = Behind Right

Link copied to clipboard
fun getLatLonTileWithOffset(xTile: Int, yTile: Int, zoom: Int, xOffset: Double, yOffset: Double): LngLatAlt
Link copied to clipboard

This represent the original iOS LEFT_RIGHT direction type which they described like this:

Link copied to clipboard
Link copied to clipboard
fun getNearestRoad(currentLocation: LngLatAlt, searchTree: FeatureTree): Feature?

Get nearest road from roads Feature Collection. WARNING: It doesn't care which direction the road is. Roads can contain crossings which are Points not LineStrings.

Link copied to clipboard
fun getNode(coordinate: LngLatAlt, nodeMap: MutableMap<LngLatAlt, Int>, nodeIdCounter: Int): Int
Link copied to clipboard

Gets map coordinates from X and Y GPS coordinates. This is the same calculation as above but returns normalised x and y values scaled between 0 and 1.0. These are what are required by the mapcompose library to set markers/positions.

Link copied to clipboard
fun getPathCoordinates(endNode: Int, startNode: Int, previousNodes: Map<Int, Int>, nodeMap: Map<LngLatAlt, Int>): List<LngLatAlt>
Link copied to clipboard
fun getPixelXY(latitude: Double, longitude: Double, zoom: Int): Pair<Double, Double>

Calculates the pixel coordinate of the provided latitude and longitude location at the given zoom level.

Link copied to clipboard

Parses out the super category Features contained in the Points of Interest (POI) Feature Collection.

Link copied to clipboard

Given a BoundingBox returns a closed Polygon.

Link copied to clipboard
fun getQuadKey(tileX: Int, tileY: Int, zoomLevel: Int): String

Generates a quad key string from the tile X, Y coordinates and zoom level provided. Here's the Microsoft info: https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system

Link copied to clipboard

Calculates the bounds of the quadrants that should be used for filtering POIs These quadrants are rotated from the standard cardinal direction quadrants (north: [315.0, 45.0), east: [45.0, 135.0), etc.) such that the provided heading becomes the center of the standard cardinal direction quadrant that it belongs to. This ensures that callouts filtered into quadrants will always be centered around the user's current heading if possible (if quadrants were fixed to the standard cardinal direction, and the user were facing 315.0, then all callouts for north would be to the user's right). Here are several examples to illustrate how this works:

Link copied to clipboard
fun getReferenceCoordinate(path: LineString, targetDistance: Double, reverseLineString: Boolean): LngLatAlt

Calculates a coordinate on a LineString at a target distance from the first coordinate of the LineString.

Link copied to clipboard
fun getRelativeDirectionLabel(localizedContext: Context, relativeDirection: Int): String
Link copied to clipboard

A wrapper around: getCombinedDirectionPolygons, getIndividualDirectionPolygons, getAheadBehindDirectionPolygons, getLeftRightDirectionPolygons

Link copied to clipboard
fun getRoadBearingToIntersection(intersection: Feature?, road: Feature?, deviceHeading: Double): Double

Given an intersection Feature and a road Feature will return the bearing of the road to the intersection

Link copied to clipboard
fun getShortestRoute(startLocation: LngLatAlt, endLocation: LngLatAlt, roads: FeatureCollection): FeatureCollection

Given a start and end location and a FeatureCollection that contains connected roads it will return a FeatureCollection with a LineString that represents the shortest route between the start and end locations. The shortest route is calculated using Dijkstra's algorithm.

Link copied to clipboard

Given a super category string returns a mutable list of things in the super category. Categories taken from original Soundscape.

Link copied to clipboard
fun getTilesForRegion(currentLatitude: Double = 0.0, currentLongitude: Double = 0.0, radius: Double = 250.0, zoom: Int = 16): MutableList<Tile>

Given a radius and location it calculates the set of tiles (VectorTiles) that cover a circular region around the specified location.

Link copied to clipboard
fun getTileXY(pixelX: Int, pixelY: Int): Pair<Int, Int>

Calculates the coordinates of the Tile containing the provided pixel coordinates.

Link copied to clipboard
fun getXYTile(location: LngLatAlt, zoom: Int = 16): Pair<Int, Int>

Gets Slippy Map Tile Name from GPS coordinates and Zoom (fixed at 16 for Soundscape).

Link copied to clipboard
fun groundResolution(latitude: Double, zoom: Int): Double

Determines the ground resolution (in meters per pixel) at a specified latitude and level of detail.

Link copied to clipboard
fun interpolate(point1: LngLatAlt, point2: LngLatAlt, fraction: Double): LngLatAlt
Link copied to clipboard
fun isBetween(x1: Double, x2: Double, value: Double): Boolean
Link copied to clipboard
fun isDuplicateByOsmId(existingSet: MutableSet<Any>, feature: Feature): Boolean

isDuplicateByOsmId returns true if the OSM id for the feature has already been entered into the existingSet. It returns false if it's the first time, or there's no OSM id.

Link copied to clipboard
fun isLineHorizontal(lineStart: LngLatAlt, lineEnd: LngLatAlt, tolerance: Double = 1.0E-6): Boolean
Link copied to clipboard
fun isLineVertical(lineStart: LngLatAlt, lineEnd: LngLatAlt, tolerance: Double = 1.0E-6): Boolean
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun lineStringsIntersect(lineString1: LineString, lineString2: LineString): Boolean

Check if two LineStrings intersect.

Link copied to clipboard

Given an array of Segments and some user geometry with the location and Field of View distance it which represent the FoV triangles it will generate a FeatureCollection of triangles.

Link copied to clipboard
fun mapSize(zoom: Int): Int

The size of the map in pixels for the given zoom level assuming the base is 256 pixels.

Link copied to clipboard
fun mergePolygons(polygon1: Feature, polygon2: Feature): Feature
Link copied to clipboard
Link copied to clipboard
fun nearestNodeToCoordinate(nodeMap: Map<LngLatAlt, Int>, coordinate: LngLatAlt): Int
Link copied to clipboard
fun onSegment(x: Double, y: Double, x1: Double, y1: Double, x2: Double, y2: Double): Boolean
Link copied to clipboard
fun pixelXYToLatLon(pixelX: Double, pixelY: Double, zoom: Int): Pair<Double, Double>

Calculates the lat and lon coordinates given a pixelX, pixelY and zoom.

Link copied to clipboard
Link copied to clipboard
fun pointOnRightSide(start: LngLatAlt, pointToCheck: LngLatAlt, end: LngLatAlt): Boolean

Checks if a point is on the right side of a line segment or not.

Link copied to clipboard

Determine if a coordinate is contained within a polygon.

Link copied to clipboard

Given a FeatureCollection checks for duplicate OSM IDs and removes them.

Link copied to clipboard
fun removeDuplicates(intersectionToCheck: Feature?): Feature?
Link copied to clipboard
fun Double.round(digitLength: Int): Double
Link copied to clipboard
Link copied to clipboard
fun sortedByDistanceTo(currentLocation: LngLatAlt, featureCollection: FeatureCollection): FeatureCollection

Given a Feature Collection and location this will calculate the nearest distance to each Feature, and return a sorted Feature Collection by the distance_to foreign member for each Feature.

Link copied to clipboard
Link copied to clipboard

Given an intersection Feature and a road Feature will split the road into two based on the coordinate of the intersection.

Link copied to clipboard
fun straightLinesIntersect(line1Start: LngLatAlt, line1End: LngLatAlt, line2Start: LngLatAlt, line2End: LngLatAlt): Boolean

Check if straight lines defined by line1Start, line1End, line2Start, line2End intersect.

Link copied to clipboard
fun straightLinesIntersectLngLatAlt(line1Start: LngLatAlt, line1End: LngLatAlt, line2Start: LngLatAlt, line2End: LngLatAlt): LngLatAlt?

Check if straight lines defined by line1Start, line1End, line2Start, line2End intersect and if they do return the intersection coordinates

Link copied to clipboard

Calculates the Bounding Box coordinates for a Slippy Tile with a given zoom level.

Link copied to clipboard
fun tileToLat(x: Int, zoom: Int): Double

Converts the X of a Slippy Tile with a given zoom level into a latitude.

Link copied to clipboard
fun tileToLon(y: Int, zoom: Int): Double

Converts the Y of a Slippy Tile with a given zoom level into a longitude.

Link copied to clipboard
fun toRadians(degrees: Double): Double
Link copied to clipboard
fun traceLineString(featureCollection: FeatureCollection, distanceBetweenPoints: Double): FeatureCollection

Given a Feature Collection that contains a LineString it will return a Feature Collection of Points that trace along the LineString at given distance intervals. This is useful for faking the locations of a user walking down a road but isn't super accurate if you enter big distance intervals and the LineString has lots of curves or bends.