最適化された地図統合モジュール
HERE Map Content 形式は、主にマップのコンパイル用に設計されています。 そのため、 HERE Map Content への直接アクセスは、ロケーション ライブラリ、ルーティング、およびパスマッチングの主な使用例では効率的ではありません。
アクセスを最適化するために、 HERE は Optimized Map for Location Library を提供 します。この HERE Map Content は、これらの主な用途に合わせて からコンパイルされたマップ形式です。
libraryDependencies ++= Seq(
"com.here.platform.location" %% "location-integration-optimized-map-dcl2" % "0.21.788"
)
<dependencies>
<dependency>
<groupId>com.here.platform.location</groupId>
<artifactId>location-integration-optimized-map-dcl2_${scala.compat.version}</artifactId>
<version>0.21.788</version>
</dependency>
</dependencies>
dependencies {
compile group: 'com.here.platform.location', name: 'location-integration-optimized-map-dcl2_2.12', version:'0.21.788'
}
OptimizedMapVersionedLayers オブジェクトを作成します
このセクションで は、アプリでカタログ Optimized Map for Location Library および HERE Map Content にアクセスする方法について説明します。
まず、 BaseClient インターフェイスのインスタンスを作成する必要があります。
private val baseClient = BaseClient()
カタログの操作が完了したら、 次のように BaseClient を終了します。
Await.result(baseClient.shutdown(), Duration.Inf)
カタログの操作が完了したら、オプションで BaseClient を終了できます。
OptimizedMapVersionedLayers オブジェクト th は OptimizedMapLayers をインプリメントしてVersionedLayers
います。このオブジェクトを使用すると、 Optimized Map for Location Library カタログで使用可能なデータをから読み取ることができます。
Optimized Map for Location Library の OptimizedMapVersionedLayers オブジェクトを作成するには、この BaseClient と 適切なカタログ HERE リソースネーム およびバージョンを使用します。
val optimizedMap: OptimizedMapVersionedLayers =
OptimizedMapCatalog
.from(optimizedMapHRN)
.usingBaseClient(baseClient)
.newInstance
.version(optimizedMapVersion)
HERE リソースネーム の定義および Optimized Map for Location Library のバージョンの詳細について は、「カタログ」の「 HNS およびバージョン」を参照してください。
レイヤーオブジェクトを作成します
OptimizedMapLayers オブジェクトのデータは、カタログレイヤーのピース ( タイル ) に保存されます。 特定のレイヤーからデータを読み込むには、次のメソッドを呼び出してレイヤーオブジェクトを作成します。
val lengthLayer = optimizedMap.length
各タイルは 、その TileId によって一意に識別されます。 これらの ID は、タイル内のデータが記述している領域に関連 しています。これらの ID は、遺伝的なパーティション分割方式に従います。
レイヤーオブジェクトは 、 TileId によってデータを読み取るためのreader
メソッドを公開します。
指定したポイントに近いタイルを取得します
特定の領域のデータが含まれているタイルを簡単に検出できるように、ロケーション ライブラリで は TileResolversを提供しています。
TileResolver のインスタンスを取得する には 、 HereTileResolver を作成し、 そのズーム レベルを使用して HereTileLevel を提供します。
TileResolver を使用 すると、例えば、 Brandenburger Tor の周りの半径 1000 メートルの円をカバーするタイルを次のように検索できます。
import com.here.platform.location.core.geospatial.GeoCoordinate
import com.here.platform.location.inmemory.geospatial.TileId
import com.here.platform.location.integration.herecommons.geospatial.{
HereTileLevel,
HereTileResolver
}
val lengthZoomLevel = optimizedMap.versionedLayers
.versionedHereTileLayer(OptimizedMapLayers.RoadAccessLayerConfiguration.layerId)
.zoomLevels
.head
val tileResolver = new HereTileResolver(HereTileLevel(lengthZoomLevel))
val brandenburgerTor = GeoCoordinate(52.516268, 13.377700)
val radiusInMeters = 1000.0
val outputTiles =
tileResolver.fromCenterAndRadius(brandenburgerTor, radiusInMeters)
val roadAccessLayer = optimizedMap.roadAccess
val readTiles = outputTiles.map(tile => (tile, roadAccessLayer.reader(tile)))
Brandenburger Tor から 1000 メートル以内にある唯一のタイルには、タイル ID 1476150
が割り当てられています。 このタイルは、道路トポロジおよびジオメトリレイヤー内で検索できます。
Optimized Map for Location Library と HERE Map Content の両方を使用する場合は、 HERE Map Content のバージョンが Optimized Map for Location Library のバージョンと互換性があることを確認してください。 次のスニペットは、正しい HERE Map Content カタログを取得する方法を示しています。
import com.here.platform.data.client.v2.main.scaladsl.DataClient
val dataClient = DataClient()
try {
val optimizedMap = dataClient
.catalogBuilder(optimizedMapHRN)
.build
println(s"The latest OM4LL version is ${optimizedMap.versionInfo.latestVersion}")
val om4llVersion = 3305L
val hmcVersions = optimizedMap.versionInfo.resolveDependencyVersion(
om4llVersion,
hereMapContentHRN
)
println(
s"An OM4LL version is $om4llVersion, the compatible HMC versions are ${hmcVersions.mkString(", ")}")
} finally {
dataClient.shutdown()
}
プロパティ
プロパティは、制限速度、特定の車両タイプによるアクセス性、ジオメトリ(道路形状)など、配線グラフの頂点に添付された値です。 HERE Map Content では 、これらはセグメント属性と呼ばれます。
頂点のプロパティ
頂点全体に適用される値が常に 1 つだけのプロパティは 、 PropertyMaps として表されます。 Optimized Map for Location Library の一部である頂点プロパティ については、以下で詳しく説明します。
指定したトポロジーセグメントの頂点を取得します
「ルーティンググラフ」のセクションで説明したように、頂点を使用すると、トポロジセグメントよりも特定の道路セグメントのプロパティを分析する方が効率的です。 Optimized Map for Location Library のマッピングレイヤー は、ルーティンググラフの頂点と HERE Map Content の道路セグメントの間のマッピングを定義します。 このセクションでは、このレイヤーを使用してトポロジーセグメントを頂点に変換する方法を示します。
- https://platform.here.com/data/hrn:here:data::olp-here:rib-2/topology-geometry/inspect を開きます。
- トポロジセグメントをクリックします。
start_node_ref
オブジェクトを展開し、その識別子を書き留めます。 - セグメントの方向を推測するに
start_node_ref
は、セグメントの端にあるノードをクリックし、それらの ID をセグメントの識別子と比較します。 -
トポロジーセグメントを変換するに TileLoader
は、マッピングレイヤーのを作成し、 TiledReverseHereMapContentReferencePropertyMap を作成します。 TiledReverseHereMapContentReferencePropertyMap
は 、特定のタイル ID についてTileLoader
が生成するパーティションを使用します。 次のコード スニペットは 、パーティション23618402
のトポロジセグメントhere:cm:segment:94480838
に対応する頂点を取得する方法を示し ています。
import com.here.platform.location.integration.heremapcontent.PartitionId
import com.here.platform.location.integration.optimizedmap.geospatial.{
HereMapContentReference,
SegmentId
}
import com.here.platform.location.integration.optimizedmap.graph.{
MappingTile,
TiledReverseHereMapContentReferencePropertyMap
}
val mappingLayer = optimizedMap.mapping
val mappingPartitions: Map[TileId, Option[MappingTile]] =
outputTiles.map(tileId => (tileId, mappingLayer.reader(tileId))).toMap
val optimizedMapMapping = new TiledReverseHereMapContentReferencePropertyMap(
mappingPartitions,
mappingLayer.tileResolver
)
val srcTopologySegment = HereMapContentReference(PartitionId("23618402"),
SegmentId("here:cm:segment:94480838"),
Forward)
val vertex = optimizedMapMapping(srcTopologySegment)
println(s"The topology segment $srcTopologySegment corresponds to the vertex $vertex")
指定した頂点のトポロジーセグメントを取得します
近接検索などの複数のロケーション ライブラリアルゴリズムが、トポロジセグメントではなく頂点を返します。 頂点には 2 つの欠点があります。
そのため、頂点をトポロジーセグメントに変換する必要がある場合があります。 次のコード スニペットでは 、この操作を実行する方法を示します。この操作を行うには、マッピングレイヤーのTileLoader
を作成し、 TiledHereMapContentReferencePropertyMap を作成します。 は TiledHereMapContentReferencePropertyMap
、特定のタイル ID についてTileLoader
が生成するパーティションを使用します。 コード スニペットでは、前のセクションの頂点(コード スニペット)で取得した頂点が使用されます。
import com.here.platform.location.integration.optimizedmap.geospatial.HereMapContentReference
import com.here.platform.location.integration.optimizedmap.graph.{
MappingTile,
TiledHereMapContentReferencePropertyMap
}
val mappingLayer = optimizedMap.mapping
val mappingPartitions: Map[TileId, Option[MappingTile]] =
outputTiles.map(tileId => (tileId, mappingLayer.reader(tileId))).toMap
val hereMapContentMapping = new TiledHereMapContentReferencePropertyMap(mappingPartitions)
val topologySegment = hereMapContentMapping(vertex)
val HereMapContentReference(partitionId, segmentId, direction) = topologySegment
println(s"$vertex corresponds to the segment with identifier $segmentId")
println(s" in HERE Map Content partition $partitionId")
println(s" travelling in $direction direction, relative to the segment")
指定した頂点の形状を取得します
ルーティンググラフで説明したように、頂点は道路セグメントに沿った特定の方向の移動を表します。 Optimized Map for Location Library のジオメトリレイヤー には、道路セグメントの形状が保存されます。 レイヤーのタイルには、次のものが含まれています。
- タイルを横断する各セグメントの道路形状
- 特定の領域内で効率的に検索するための空間インデックス
ジオメトリ レイヤーのパーティションからのプロパティマップの作成は 、 TiledGeometryPropertyMap によって有効になります。 TiledGeometryPropertyMap は 、頂点ごとに指定されたジオメトリを返します。ジオメトリのポイントは、この頂点の移動方向に配置されます。
import com.here.platform.location.core.graph.PropertyMap
import com.here.platform.location.inmemory.geospatial.{GeometryTile, PackedLineString}
val geometryLayer = optimizedMap.geometry
val geometryTiles: Iterable[(TileId, Option[GeometryTile])] =
outputTiles.map(tileId => (tileId, geometryLayer.reader(tileId))).toMap
val geometry: PropertyMap[Vertex, PackedLineString] =
new TiledGeometryPropertyMap(geometryTiles.toMap)
val tileId = outputTiles.head
val segmentIndex = SegmentIndex.fromVertexIndex(VertexIndex(10))
val forwardVertex = Vertex(tileId, segmentIndex.toVertexIndex(Forward))
val backwardVertex = Vertex(tileId, segmentIndex.toVertexIndex(Backward))
assert(geometry(forwardVertex).toIndexedSeq.reverse == geometry(backwardVertex).toIndexedSeq)
長さレイヤー
長 さレイヤーは、メートル単位の頂点の長さを提供します。 頂点の長さにアクセスするに は、まず、長さデータを含む TiledUndirectedPropertyMap を作成する必要があります。 次に、この TiledUndirectedPropertyMap を使用し て、指定した頂点の長さにアクセスします。
val lengthLayer = optimizedMap.length
val lengthPartitions: Iterable[(TileId, Option[UndirectedPropertyTile[Double]])] =
outputTiles.map(tileId => (tileId, lengthLayer.reader(tileId))).toMap
val lengthProperty: PropertyMap[Vertex, Double] =
new TiledUndirectedPropertyMap(lengthPartitions.toMap)
val lengthVertex = Vertex(outputTiles.head, VertexIndex(10))
val length = lengthProperty(lengthVertex)
println(s"The $lengthVertex is $length meters long.")
範囲ベースの頂点のプロパティ
Optimized Map for Location Library から
Optimized Map for Location Library には、 HERE Map Content からコンパイルされた範囲ベースのプロパティレイヤーが含まれています。
1 つの例 として、道路アクセス層があります。この層には、特定の頂点にアクセスできるトラフィックのタイプに関する情報が含まれています。
val roadAccessType: RangeBasedPropertyMap[Vertex, RoadAccessType] =
PropertyMaps(optimizedMap).roadAccess
val vertexHasCarAccessType: Boolean =
roadAccessType(v, vertexFraction).get.value.intersects(RoadAccess.Automobile)
val isCarOrBusAccessible =
PropertyMaps(optimizedMap)
.roadAccess(RoadAccess.Automobile union RoadAccess.Bus)
val vertexIsCarOrBusAccessible: Boolean = isCarOrBusAccessible(v, vertexFraction).get.value
println(s"If $v has the car access type ($vertexHasCarAccessType) it is accessible")
println(s"for cars or buses ($vertexIsCarOrBusAccessible)")
もう 1 つの例として、 freeflowspeed レイヤーがあります。 witch には、通常の交通状況下で、車が頂点ジオメトリのさまざまな部分を通過する速度が含まれています。この速度は km/時 で表されます。
val freeFlowSpeed = PropertyMaps(optimizedMap).freeFlowSpeed
println(s"The free-flow speeds of $v are ${freeFlowSpeed(v)}")