Skip to content

Commit

Permalink
Move geo utils files into a geoengine utiles sub-directory
Browse files Browse the repository at this point in the history
This is a minor move really, but the aim is to have all geo functionality
within the geoengine directory.
  • Loading branch information
davecraig committed Nov 20, 2024
1 parent b50ce74 commit 7e8d053
Show file tree
Hide file tree
Showing 37 changed files with 287 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import org.scottishtecharmy.soundscape.screens.home.HomeScreen
import org.scottishtecharmy.soundscape.screens.home.Navigator
import org.scottishtecharmy.soundscape.services.SoundscapeService
import org.scottishtecharmy.soundscape.ui.theme.SoundscapeTheme
import org.scottishtecharmy.soundscape.utils.TileGrid.Companion.PROTOMAPS_SERVER_PATH
import org.scottishtecharmy.soundscape.utils.TileGrid.Companion.PROTOMAPS_SERVER_BASE
import org.scottishtecharmy.soundscape.geoengine.utils.TileGrid.Companion.PROTOMAPS_SERVER_PATH
import org.scottishtecharmy.soundscape.geoengine.utils.TileGrid.Companion.PROTOMAPS_SERVER_BASE
import org.scottishtecharmy.soundscape.utils.extractAssets
import java.io.File
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlinx.coroutines.flow.asStateFlow
import org.scottishtecharmy.soundscape.geojsonparser.geojson.LngLatAlt
import org.scottishtecharmy.soundscape.services.SoundscapeBinder
import org.scottishtecharmy.soundscape.services.SoundscapeService
import org.scottishtecharmy.soundscape.utils.TileGrid
import org.scottishtecharmy.soundscape.geoengine.utils.TileGrid
import javax.inject.Inject

@ActivityRetainedScoped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import io.realm.kotlin.RealmConfiguration
import org.scottishtecharmy.soundscape.database.local.model.Location
import org.scottishtecharmy.soundscape.database.local.model.RouteData
import org.scottishtecharmy.soundscape.database.local.model.RoutePoint
import org.scottishtecharmy.soundscape.utils.TileGrid.Companion.SOUNDSCAPE_TILE_BACKEND
import org.scottishtecharmy.soundscape.geoengine.utils.TileGrid.Companion.SOUNDSCAPE_TILE_BACKEND

object RealmConfiguration {
private var tileDataRealm: Realm? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.scottishtecharmy.soundscape.dto

import org.scottishtecharmy.soundscape.geojsonparser.geojson.LngLatAlt
import org.scottishtecharmy.soundscape.utils.isBetween

/**
* Bounding box usually follow the standard format of:
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,37 @@ import org.scottishtecharmy.soundscape.network.ITileDAO
import org.scottishtecharmy.soundscape.network.ProtomapsTileClient
import org.scottishtecharmy.soundscape.network.SoundscapeBackendTileClient
import org.scottishtecharmy.soundscape.network.TileClient
import org.scottishtecharmy.soundscape.utils.InterpolatedPointsJoiner
import org.scottishtecharmy.soundscape.utils.RelativeDirections
import org.scottishtecharmy.soundscape.utils.TileGrid
import org.scottishtecharmy.soundscape.utils.TileGrid.Companion.SOUNDSCAPE_TILE_BACKEND
import org.scottishtecharmy.soundscape.utils.TileGrid.Companion.ZOOM_LEVEL
import org.scottishtecharmy.soundscape.utils.TileGrid.Companion.getTileGrid
import org.scottishtecharmy.soundscape.utils.checkIntersection
import org.scottishtecharmy.soundscape.utils.cleanTileGeoJSON
import org.scottishtecharmy.soundscape.utils.deduplicateFeatureCollection
import org.scottishtecharmy.soundscape.utils.distance
import org.scottishtecharmy.soundscape.utils.distanceToPolygon
import org.scottishtecharmy.soundscape.utils.getCompassLabelFacingDirection
import org.scottishtecharmy.soundscape.utils.getCompassLabelFacingDirectionAlong
import org.scottishtecharmy.soundscape.geoengine.mvttranslation.InterpolatedPointsJoiner
import org.scottishtecharmy.soundscape.geoengine.utils.RelativeDirections
import org.scottishtecharmy.soundscape.geoengine.utils.TileGrid
import org.scottishtecharmy.soundscape.geoengine.utils.TileGrid.Companion.SOUNDSCAPE_TILE_BACKEND
import org.scottishtecharmy.soundscape.geoengine.utils.TileGrid.Companion.ZOOM_LEVEL
import org.scottishtecharmy.soundscape.geoengine.utils.TileGrid.Companion.getTileGrid
import org.scottishtecharmy.soundscape.geoengine.utils.checkIntersection
import org.scottishtecharmy.soundscape.geoengine.utils.cleanTileGeoJSON
import org.scottishtecharmy.soundscape.geoengine.utils.deduplicateFeatureCollection
import org.scottishtecharmy.soundscape.geoengine.utils.distance
import org.scottishtecharmy.soundscape.geoengine.utils.distanceToPolygon
import org.scottishtecharmy.soundscape.geoengine.utils.getCompassLabelFacingDirection
import org.scottishtecharmy.soundscape.geoengine.utils.getCompassLabelFacingDirectionAlong
import org.scottishtecharmy.soundscape.utils.getCurrentLocale
import org.scottishtecharmy.soundscape.utils.getFovIntersectionFeatureCollection
import org.scottishtecharmy.soundscape.utils.getFovRoadsFeatureCollection
import org.scottishtecharmy.soundscape.utils.getIntersectionRoadNames
import org.scottishtecharmy.soundscape.utils.getIntersectionRoadNamesRelativeDirections
import org.scottishtecharmy.soundscape.utils.getNearestIntersection
import org.scottishtecharmy.soundscape.utils.getNearestRoad
import org.scottishtecharmy.soundscape.utils.getPoiFeatureCollectionBySuperCategory
import org.scottishtecharmy.soundscape.utils.getRelativeDirectionLabel
import org.scottishtecharmy.soundscape.utils.getRelativeDirectionsPolygons
import org.scottishtecharmy.soundscape.utils.getRoadBearingToIntersection
import org.scottishtecharmy.soundscape.utils.getSuperCategoryElements
import org.scottishtecharmy.soundscape.utils.pointIsWithinBoundingBox
import org.scottishtecharmy.soundscape.utils.processTileFeatureCollection
import org.scottishtecharmy.soundscape.utils.processTileString
import org.scottishtecharmy.soundscape.utils.removeDuplicateOsmIds
import org.scottishtecharmy.soundscape.utils.sortedByDistanceTo
import org.scottishtecharmy.soundscape.utils.vectorTileToGeoJson
import org.scottishtecharmy.soundscape.geoengine.utils.getFovIntersectionFeatureCollection
import org.scottishtecharmy.soundscape.geoengine.utils.getFovRoadsFeatureCollection
import org.scottishtecharmy.soundscape.geoengine.utils.getIntersectionRoadNames
import org.scottishtecharmy.soundscape.geoengine.utils.getIntersectionRoadNamesRelativeDirections
import org.scottishtecharmy.soundscape.geoengine.utils.getNearestIntersection
import org.scottishtecharmy.soundscape.geoengine.utils.getNearestRoad
import org.scottishtecharmy.soundscape.geoengine.utils.getPoiFeatureCollectionBySuperCategory
import org.scottishtecharmy.soundscape.geoengine.utils.getRelativeDirectionLabel
import org.scottishtecharmy.soundscape.geoengine.utils.getRelativeDirectionsPolygons
import org.scottishtecharmy.soundscape.geoengine.utils.getRoadBearingToIntersection
import org.scottishtecharmy.soundscape.geoengine.utils.getSuperCategoryElements
import org.scottishtecharmy.soundscape.geoengine.utils.pointIsWithinBoundingBox
import org.scottishtecharmy.soundscape.geoengine.utils.processTileFeatureCollection
import org.scottishtecharmy.soundscape.geoengine.utils.processTileString
import org.scottishtecharmy.soundscape.geoengine.utils.removeDuplicateOsmIds
import org.scottishtecharmy.soundscape.geoengine.utils.sortedByDistanceTo
import org.scottishtecharmy.soundscape.geoengine.mvttranslation.vectorTileToGeoJson
import retrofit2.awaitResponse
import java.util.Locale
import kotlin.coroutines.cancellation.CancellationException
Expand Down Expand Up @@ -150,7 +150,8 @@ class GeoEngine {
newLocation?.let { location ->
// Check if we're still within the central area of our grid
if (!pointIsWithinBoundingBox(LngLatAlt(location.longitude, location.latitude),
centralBoundingBox)) {
centralBoundingBox)
) {
Log.d(TAG, "Update central grid area")
// The current location has moved from within the central area, so get the
// new grid and the new central area.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.scottishtecharmy.soundscape.utils
package org.scottishtecharmy.soundscape.geoengine.mvttranslation

import org.scottishtecharmy.soundscape.geoengine.utils.distance
import org.scottishtecharmy.soundscape.geojsonparser.geojson.Feature
import org.scottishtecharmy.soundscape.geojsonparser.geojson.FeatureCollection
import org.scottishtecharmy.soundscape.geojsonparser.geojson.GeoJsonObject
Expand All @@ -9,7 +10,8 @@ import org.scottishtecharmy.soundscape.geojsonparser.geojson.LngLatAlt
import org.scottishtecharmy.soundscape.geojsonparser.geojson.MultiPoint
import org.scottishtecharmy.soundscape.geojsonparser.geojson.Point
import org.scottishtecharmy.soundscape.geojsonparser.geojson.Polygon
import org.scottishtecharmy.soundscape.utils.TileGrid.Companion.ZOOM_LEVEL
import org.scottishtecharmy.soundscape.geoengine.utils.TileGrid.Companion.ZOOM_LEVEL
import org.scottishtecharmy.soundscape.geoengine.utils.getLatLonTileWithOffset
import vector_tile.VectorTile

fun pointIsOffTile(x: Int, y: Int) : Boolean {
Expand Down Expand Up @@ -100,11 +102,13 @@ private fun parseGeometry(
private fun convertGeometry(tileX : Int, tileY : Int, tileZoom : Int, geometry: ArrayList<Pair<Int, Int>>) : ArrayList<LngLatAlt> {
val results = arrayListOf<LngLatAlt>()
for(point in geometry) {
results.add(getLatLonTileWithOffset(tileX,
results.add(
getLatLonTileWithOffset(tileX,
tileY,
tileZoom,
point.first.toDouble()/4096.0,
point.second.toDouble()/4096.0))
point.second.toDouble()/4096.0)
)
}
return results
}
Expand Down Expand Up @@ -197,7 +201,8 @@ class IntersectionDetection {
*
*/
fun addLine(line : ArrayList<Pair<Int, Int>>,
details : IntersectionDetails) {
details : IntersectionDetails
) {
for (point in line) {
if((point.first < 0) || (point.first > 4095) ||
(point.second < 0) || (point.second > 4095)) {
Expand Down Expand Up @@ -315,7 +320,8 @@ class EntranceMatching {
*
*/
fun addPolygon(line : ArrayList<Pair<Int, Int>>,
details : EntranceDetails) {
details : EntranceDetails
) {
for (point in line) {
if((point.first < 0) || (point.first > 4095) ||
(point.second < 0) || (point.second > 4095)) {
Expand Down Expand Up @@ -521,11 +527,13 @@ fun convertGeometryAndClipLineToTile(
interpolatedNodes.add(interpolatedLatLon)

// Add the new point
segment.add(getLatLonTileWithOffset(tileX,
segment.add(
getLatLonTileWithOffset(tileX,
tileY,
tileZoom,
point.first.toDouble()/4096.0,
point.second.toDouble()/4096.0))
point.second.toDouble()/4096.0)
)
} else {
// We started on tile and this point is now off tile
// Add interpolated point from lastPoint to this point
Expand All @@ -546,11 +554,13 @@ fun convertGeometryAndClipLineToTile(
offTile = offTile.xor(true)
}
else if(!offTile) {
segment.add(getLatLonTileWithOffset(tileX,
segment.add(
getLatLonTileWithOffset(tileX,
tileY,
tileZoom,
point.first.toDouble()/4096.0,
point.second.toDouble()/4096.0))
point.second.toDouble()/4096.0)
)
} else {
// We're continuing off tile, but we need to check if the line between the two off tile
// points crossed over the tile.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scottishtecharmy.soundscape.utils
package org.scottishtecharmy.soundscape.geoengine.utils

import java.util.NavigableSet
import java.util.PriorityQueue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scottishtecharmy.soundscape.utils
package org.scottishtecharmy.soundscape.geoengine.utils

import java.util.ArrayList

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scottishtecharmy.soundscape.utils
package org.scottishtecharmy.soundscape.geoengine.utils

data class BoPoint(
var x_coord: Double,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scottishtecharmy.soundscape.utils
package org.scottishtecharmy.soundscape.geoengine.utils

class BoSegment(
private val p1: BoPoint,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.scottishtecharmy.soundscape.utils
package org.scottishtecharmy.soundscape.geoengine.utils


import android.content.Context
import android.content.res.Configuration
import org.scottishtecharmy.soundscape.R

fun getCompassLabelFacingDirection(localizedContext: Context, degrees: Int, locale: java.util.Locale): String{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scottishtecharmy.soundscape.utils
package org.scottishtecharmy.soundscape.geoengine.utils

enum class Direction(val value: Int) {
// This is tracking around clockwise from 6 o'clock
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scottishtecharmy.soundscape.utils
package org.scottishtecharmy.soundscape.geoengine.utils

import org.scottishtecharmy.soundscape.dto.BoundingBox
import org.scottishtecharmy.soundscape.dto.BoundingBoxCorners
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scottishtecharmy.soundscape.utils
package org.scottishtecharmy.soundscape.geoengine.utils

class Quadrant(private val heading: Double) {
val left: Double
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scottishtecharmy.soundscape.utils
package org.scottishtecharmy.soundscape.geoengine.utils

enum class RelativeDirections (val value: Int) {
// Ahead, Right, Behind, and Left all get a 150 degree window centered in their respective
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scottishtecharmy.soundscape.utils
package org.scottishtecharmy.soundscape.geoengine.utils

enum class RoadDirectionAtIntersection {
LEADING,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scottishtecharmy.soundscape.utils
package org.scottishtecharmy.soundscape.geoengine.utils

import org.scottishtecharmy.soundscape.dto.BoundingBox
import org.scottishtecharmy.soundscape.dto.Tile
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scottishtecharmy.soundscape.utils
package org.scottishtecharmy.soundscape.geoengine.utils

import org.scottishtecharmy.soundscape.database.local.model.TileData
import org.scottishtecharmy.soundscape.dto.IntersectionRelativeDirections
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.scottishtecharmy.soundscape.network

import org.scottishtecharmy.soundscape.utils.TileGrid.Companion.PROTOMAPS_SERVER_PATH
import org.scottishtecharmy.soundscape.utils.TileGrid.Companion.PROTOMAPS_SUFFIX
import org.scottishtecharmy.soundscape.geoengine.utils.TileGrid.Companion.PROTOMAPS_SERVER_PATH
import org.scottishtecharmy.soundscape.geoengine.utils.TileGrid.Companion.PROTOMAPS_SUFFIX
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.scottishtecharmy.soundscape.network

import android.app.Application
import org.scottishtecharmy.soundscape.utils.TileGrid.Companion.PROTOMAPS_SERVER_BASE
import org.scottishtecharmy.soundscape.geoengine.utils.TileGrid.Companion.PROTOMAPS_SERVER_BASE
import retrofit2.Retrofit
import retrofit2.converter.protobuf.ProtoConverterFactory

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.scottishtecharmy.soundscape.database.local.RealmConfiguration
import org.scottishtecharmy.soundscape.database.local.dao.RoutesDao
import org.scottishtecharmy.soundscape.database.local.model.RouteData
import org.scottishtecharmy.soundscape.database.repository.RoutesRepository
import org.scottishtecharmy.soundscape.utils.distance
import org.scottishtecharmy.soundscape.geoengine.utils.distance

class RoutePlayer(val service: SoundscapeService) {
private var currentRouteData: RouteData? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import org.scottishtecharmy.soundscape.geojsonparser.geojson.FeatureCollection
import org.scottishtecharmy.soundscape.geojsonparser.geojson.GeoMoshi
import org.scottishtecharmy.soundscape.geojsonparser.geojson.LngLatAlt
import org.scottishtecharmy.soundscape.geojsonparser.geojson.Point
import org.scottishtecharmy.soundscape.utils.distance
import org.scottishtecharmy.soundscape.utils.getBusStopsFeatureCollectionFromTileFeatureCollection
import org.scottishtecharmy.soundscape.utils.getFovIntersectionFeatureCollection
import org.scottishtecharmy.soundscape.utils.getNearestIntersection
import org.scottishtecharmy.soundscape.geoengine.utils.distance
import org.scottishtecharmy.soundscape.geoengine.utils.getBusStopsFeatureCollectionFromTileFeatureCollection
import org.scottishtecharmy.soundscape.geoengine.utils.getFovIntersectionFeatureCollection
import org.scottishtecharmy.soundscape.geoengine.utils.getNearestIntersection

class BusStopTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import org.scottishtecharmy.soundscape.geojsonparser.geojson.FeatureCollection
import org.scottishtecharmy.soundscape.geojsonparser.geojson.GeoMoshi
import org.scottishtecharmy.soundscape.geojsonparser.geojson.LngLatAlt
import org.scottishtecharmy.soundscape.geojsonparser.geojson.Point
import org.scottishtecharmy.soundscape.utils.RelativeDirections
import org.scottishtecharmy.soundscape.utils.checkIntersection
import org.scottishtecharmy.soundscape.utils.getFovIntersectionFeatureCollection
import org.scottishtecharmy.soundscape.utils.getFovRoadsFeatureCollection
import org.scottishtecharmy.soundscape.utils.getIntersectionRoadNames
import org.scottishtecharmy.soundscape.utils.getIntersectionRoadNamesRelativeDirections
import org.scottishtecharmy.soundscape.utils.getIntersectionsFeatureCollectionFromTileFeatureCollection
import org.scottishtecharmy.soundscape.utils.getNearestIntersection
import org.scottishtecharmy.soundscape.utils.getNearestRoad
import org.scottishtecharmy.soundscape.utils.getRelativeDirectionsPolygons
import org.scottishtecharmy.soundscape.utils.getRoadBearingToIntersection
import org.scottishtecharmy.soundscape.utils.getRoadsFeatureCollectionFromTileFeatureCollection
import org.scottishtecharmy.soundscape.utils.sortedByDistanceTo
import org.scottishtecharmy.soundscape.geoengine.utils.RelativeDirections
import org.scottishtecharmy.soundscape.geoengine.utils.checkIntersection
import org.scottishtecharmy.soundscape.geoengine.utils.getFovIntersectionFeatureCollection
import org.scottishtecharmy.soundscape.geoengine.utils.getFovRoadsFeatureCollection
import org.scottishtecharmy.soundscape.geoengine.utils.getIntersectionRoadNames
import org.scottishtecharmy.soundscape.geoengine.utils.getIntersectionRoadNamesRelativeDirections
import org.scottishtecharmy.soundscape.geoengine.utils.getIntersectionsFeatureCollectionFromTileFeatureCollection
import org.scottishtecharmy.soundscape.geoengine.utils.getNearestIntersection
import org.scottishtecharmy.soundscape.geoengine.utils.getNearestRoad
import org.scottishtecharmy.soundscape.geoengine.utils.getRelativeDirectionsPolygons
import org.scottishtecharmy.soundscape.geoengine.utils.getRoadBearingToIntersection
import org.scottishtecharmy.soundscape.geoengine.utils.getRoadsFeatureCollectionFromTileFeatureCollection
import org.scottishtecharmy.soundscape.geoengine.utils.sortedByDistanceTo

class ComplexIntersections {

Expand Down
Loading

0 comments on commit 7e8d053

Please sign in to comment.