mirror of
https://github.com/corda/corda.git
synced 2025-05-02 16:53:22 +00:00
Switch to using Antony's list of country coordinates, and load country code of each city.
This commit is contained in:
parent
1a2fe41330
commit
dec2c82693
@ -40,14 +40,16 @@ data class WorldCoordinate(val latitude: Double, val longitude: Double) {
|
|||||||
/**
|
/**
|
||||||
* A labelled [WorldCoordinate], where the label is human meaningful. For example, the name of the nearest city.
|
* A labelled [WorldCoordinate], where the label is human meaningful. For example, the name of the nearest city.
|
||||||
* Labels should not refer to non-landmarks, for example, they should not contain the names of organisations.
|
* Labels should not refer to non-landmarks, for example, they should not contain the names of organisations.
|
||||||
|
* The [countryCode] field is a two letter ISO country code.
|
||||||
*/
|
*/
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
data class PhysicalLocation(val coordinate: WorldCoordinate, val description: String)
|
data class PhysicalLocation(val coordinate: WorldCoordinate, val description: String, val countryCode: String)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple lookup table of city names to their coordinates. Lookups are case insensitive.
|
* A simple lookup table of city names to their coordinates. Lookups are case insensitive.
|
||||||
*/
|
*/
|
||||||
object CityDatabase {
|
object CityDatabase {
|
||||||
|
private val matcher = Regex("^([a-zA-Z- ]*) \\((..)\\)$")
|
||||||
private val caseInsensitiveLookups = HashMap<String, PhysicalLocation>()
|
private val caseInsensitiveLookups = HashMap<String, PhysicalLocation>()
|
||||||
val cityMap = HashMap<String, PhysicalLocation>()
|
val cityMap = HashMap<String, PhysicalLocation>()
|
||||||
|
|
||||||
@ -56,9 +58,11 @@ object CityDatabase {
|
|||||||
for (line in lines) {
|
for (line in lines) {
|
||||||
if (line.startsWith("#")) continue
|
if (line.startsWith("#")) continue
|
||||||
val (name, lng, lat) = line.split('\t')
|
val (name, lng, lat) = line.split('\t')
|
||||||
val location = PhysicalLocation(WorldCoordinate(lat.toDouble(), lng.toDouble()), name)
|
val matchResult = matcher.matchEntire(name) ?: throw Exception("Could not parse line: $line")
|
||||||
caseInsensitiveLookups[name.toLowerCase()] = location
|
val (city, country) = matchResult!!.destructured
|
||||||
cityMap[name] = location
|
val location = PhysicalLocation(WorldCoordinate(lat.toDouble(), lng.toDouble()), city, country)
|
||||||
|
caseInsensitiveLookups[city.toLowerCase()] = location
|
||||||
|
cityMap[city] = location
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -777,7 +777,6 @@ Changwat Tak (TH) 99.12 16.87
|
|||||||
Yangzhou (CN) 119.43 32.38
|
Yangzhou (CN) 119.43 32.38
|
||||||
Novokuznetsk (RU) 87.08 53.75
|
Novokuznetsk (RU) 87.08 53.75
|
||||||
Kisangani (CD) 25.18 0.52
|
Kisangani (CD) 25.18 0.52
|
||||||
Bor Sa`id (EG) 32.28 31.27
|
|
||||||
Warri (NG) 5.75 5.52
|
Warri (NG) 5.75 5.52
|
||||||
Yongkang (CN) 120.02 28.87
|
Yongkang (CN) 120.02 28.87
|
||||||
Tanggu (CN) 117.63 39.02
|
Tanggu (CN) 117.63 39.02
|
||||||
|
14
core/src/test/kotlin/net/corda/core/node/CityDatabaseTest.kt
Normal file
14
core/src/test/kotlin/net/corda/core/node/CityDatabaseTest.kt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package net.corda.core.node
|
||||||
|
|
||||||
|
import org.junit.Assert.*
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class CityDatabaseTest {
|
||||||
|
@Test
|
||||||
|
fun lookups() {
|
||||||
|
val london = CityDatabase["London"]!!
|
||||||
|
assertEquals(WorldCoordinate(51.5, -0.12), london.coordinate)
|
||||||
|
assertEquals("GB", london.countryCode)
|
||||||
|
assertEquals("London", london.description)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user