パーティションタイル ID を計算します
目的: 特定の地理座標エリアのクエリおよびレベルのパーティションタイル ID を計算します
複雑さ: 初心者向け
所要時間: 30 分
ソースコード: ダウンロード
このチュートリアルの目的は 、ロケーション ライブラリの HereTileResolver Java および HereTileResolver Scala クラスを使用して、特定の場所の特定の領域をカバーするタイルを検索する方法を学習することです。
このチュートリアルでは、次のトピックについて説明します。
- HERE Tile Partitioning
- タイルに関する情報を取得します
- 4 分割ツリーの横断
- ポイント検索
- バウンディング ボックス検索
- RADIUS 検索
- 地理座標アダプターを使用した他のライブラリーとのインターフェース
HERE Tile Partitioning
タイリングは、マップ データをパーティションに分割するプロセスです。 HERE タイリングスキームは、四角形をベースにしています。 quadtree は、各内部ノードに 4 つの子があるツリーデータ構造です。
Quadtree は、 2 次元空間を 4 つのタイルに再帰的に分割して分割します。 子タイルに 0-3
は、固定された反転 S
パターンで番号が付けられます。
マップ内の各タイルには、 HERE Tile ID と呼ばれる識別子があります。HERE Tile ID は、タイルの quadkey から計算された 64 ビットの符号なし整数です。 quadkey は、0-3
レベル 1 からターゲットタイルレベルまでの親子タイルの階層をキャプチャする数値の文字列です。
たとえば 5
、マップにサンフランシスコを含むレベルのタイルの場合、 quadkey 02123
は親のタイルがで、 0212
サンフランシスコを含む子のタイルがであるためです 3
。 タイル ID が発生 1179
しました。
ただし、タイル ID を自分で計算する必要はありません。 HereTileResolver
クラスを詳細に調べて、さまざまなエリアクエリーのタイル ID を計算できます。 このクラスはロケーション ライブラリの一部です。 以降の章では、タイル ID を使用してタイル情報を取得し、 HERE Tile Partitioning スキームに従ってタイル ID を計算するアプリケーションを作成します。
HERE Tile Partitioning の詳細について は、「パーティション」を参照してください。
Maven プロジェクトを設定します
チュートリアルの最初にソースコードをダウンロードして任意のフォルダーに配置するか、プロジェクトのフォルダー構造を最初から作成します。
here-tile-resolver
└── src
└── main
├── java
└── resources
└── scala
この操作は、次の bash
1 つのコマンドで実行できます。
mkdir -p tile-resolver/src/main/{java,resources,scala}
Maven POM ファイルは 、 Maven 設定の確認 の例のファイルと似ていますが、単純化された親 POM と依存関係セクションを使用します。
親 POM :
<parent>
<groupId>com.here.platform</groupId>
<artifactId>sdk-standalone-bom_2.12</artifactId>
<version>2.54.3</version>
<relativePath/>
</parent>
依存関係 :
<dependencies>
<dependency>
<groupId>com.here.platform.location</groupId>
<artifactId>location-integration-here-commons_2.12</artifactId>
</dependency>
</dependencies>
タイルについての情報を取得します
ロケーション ライブラリは、特定のタイル ID に関する情報を取得するための基本的な方法を提供します。
次のチュートリアルで HereTileLevel
は、および HereTileResolver
クラスを使用して取得する方法を示します。
- 指定されたタイル ID のズーム レベル
- 指定したタイル ID の境界ボックス
サンフランシスコのタイル ID を使用 19319030
しています。
このチュートリアルで使用する用語について、次の一覧で説明します。
-
Zoom Level
地図に表示される世界の量を指定します。 ロケーション ライブラリでは、0
ズーム レベルが最小(完全にズームアウト)で 、最大(完全にズームイン)の31
ズームレベルで、最大の31
ズームレベルをサポートしています。 ズームレベルが低いと、地図のタイルのセットが小さいほど、地理的に大きな領域をカバーします。 ズームレベルが高いほど、タイルの数が多いほど、地理的に狭い領域をカバーできます。
次の図 は、1
、11
、および14
ズームレベルのタイルを示しています。
-
BoundingBox
(通常は bbox に短縮)は、 2 つの経度と 2 つの緯度で定義された領域です。- 緯度は
-90.0
からまでの 10 進数90.0
です。 - 経度は
-180.0
からまでの 10 進数180.0
です。
- 緯度は
次の図は、 bbox と { north : 37.79287, south : 37.68127, east : -122.34480, west : -122.54244 }
地図上の座標を示しています。
ロケーション ライブラリは、特定のタイル ID の情報を取得するための次のメソッドを提供します。
-
apply()
HereTileLevel
クラスから取得します -
boundingBoxOf(HereTile tileId)
HereTileResolver
クラスから取得します
次のコード スニペットを使用すると 19319030
、前述のサンフランシスコタイル ID に関するすべての情報を取得できます。
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.here.platform.location.core.geospatial.BoundingBox
import com.here.platform.location.inmemory.geospatial.TileId
import com.here.platform.location.integration.herecommons.geospatial.{
HereTileLevel,
HereTileResolver
}
object HereTileInformationTutorialScala {
def main(args: Array[String]): Unit = {
val sanFranciscoTileId = TileId(19319030)
val zoomLevel = HereTileLevel.apply(sanFranciscoTileId)
println(s"Zoom Level for Tile ${sanFranciscoTileId.value} is ${zoomLevel.value}")
val boundingBox: BoundingBox = HereTileResolver.boundingBoxOf(sanFranciscoTileId)
printf(s"Bounding box for Tile ${sanFranciscoTileId.value} is $boundingBox")
}
}
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.here.platform.location.core.geospatial.BoundingBox;
import com.here.platform.location.integration.herecommons.geospatial.HereTileLevel;
import com.here.platform.location.integration.herecommons.geospatial.javadsl.HereTileResolver;
public class HereTileInformationTutorial {
public static void main(String[] args) {
long sanFranciscoTileId = 19319030L;
int zoomLevel = HereTileLevel.apply(sanFranciscoTileId).value();
System.out.printf("Zoom Level for Tile %s is %s%n", sanFranciscoTileId, zoomLevel);
BoundingBox boundingBox = HereTileResolver.boundingBoxOf(sanFranciscoTileId);
System.out.printf("Bounding box for Tile %s is %s", sanFranciscoTileId, boundingBox);
}
}
アプリケーションを実行するには、次のコマンドを実行します。
mvn package exec:java -D"exec.mainClass"="HereTileInformationTutorialScala"
mvn package exec:java -D"exec.mainClass"="HereTileInformationTutorial"
次のアプリケーションの結果が得られます。
Zoom Level for Tile 19319030 is 12
Bounding box for Tile 19319030 is BoundingBox(37.79296875,37.705078125,-122.431640625,-122.51953125)
4 つのツリーによる横断
各タイルには、 1 つの祖先タイルと 1 つ以上の子孫があります。
-
Ancestor Tile
下位のズーム レベルにあるタイルで、上位のズーム レベルを持つマップの同じ領域に子のタイルがあります。 -
Descendant Tiles
上位ズーム レベルのタイルで、上位タイルのマップ上の領域に含まれています。 子孫のタイルの数は、ズーム レベルによって異なります。 たとえば、ズーム レベルn
のタイル に は、ズーム レベルn+1
の4
子タイルと16
ズーム レベルn+2
の子タイルがあり ます。
次の図は、青い 12
境界 16
線と子のタイルが 14
赤の境界線と同じ高さになっている上位タイルを示しています。
HereTileResolver
このクラスには、祖先タイルおよび子孫タイルを取得するための次のメソッドがあります。
-
fromDescendantTile(descendantTileId)
Java API | Scala API ] をクリックして、指定した子孫のタイル ID の祖先タイルを取得します。タイルが最上位レベルにあり、親がない場合、現在のタイルの ID が返されます。 -
fromAncestorTile(ancestorTileId)
[ Java API | Scala API ] をクリックして、指定した祖先タイル ID の子孫タイルを取得します。
次のコード スニペットを使用 すると、12
ズーム レベルでサンフランシスコのタイル ID19319030
を使用して14
ズーム レベルで子孫のタイルを取得できます。また、結果のいずれかの子孫のタイルでは、ズーム レベル12
で祖先のタイルを取得できます。 結果の祖先タイルは、 19319030
降下タイルを取得するために渡されたサンフランシスコのタイル ID です。
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.here.platform.location.inmemory.geospatial.TileId
import com.here.platform.location.integration.herecommons.geospatial.{
HereTileLevel,
HereTileResolver
}
object QuadTreeTraversalTutorialScala {
val ZOOM_LEVEL_TWELVE = 12
val ZOOM_LEVEL_FOURTEEN = 14
def main(args: Array[String]): Unit = {
val sanFranciscoTileId = 19319030
val resolverTwelve: HereTileResolver = new HereTileResolver(HereTileLevel(ZOOM_LEVEL_TWELVE))
val resolverFourteen: HereTileResolver = new HereTileResolver(
HereTileLevel(ZOOM_LEVEL_FOURTEEN))
val descendantTiles: Set[TileId] =
resolverFourteen.fromAncestorTile(TileId(sanFranciscoTileId))
println(
s"The Tile $sanFranciscoTileId (level $ZOOM_LEVEL_TWELVE) has the following descendant Tiles on level $ZOOM_LEVEL_FOURTEEN: ${descendantTiles.map(_.value).mkString(", ")}")
val sanFranciscoDescendantTile = descendantTiles.head
val ancestorTile: TileId =
resolverTwelve.fromDescendantTile(sanFranciscoDescendantTile)
println(
s"The tile ${sanFranciscoDescendantTile.value} (level $ZOOM_LEVEL_FOURTEEN) has the following ancestor Tile on level $ZOOM_LEVEL_TWELVE: ${ancestorTile.value}")
}
}
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.here.platform.location.integration.herecommons.geospatial.HereTileLevel;
import com.here.platform.location.integration.herecommons.geospatial.javadsl.HereTileResolver;
import java.util.Set;
public class QuadTreeTraversalTutorial {
public static final int ZOOM_LEVEL_TWELVE = 12;
public static final int ZOOM_LEVEL_FOURTEEN = 14;
public static void main(String[] args) {
int sanFranciscoTileId = 19319030;
HereTileResolver resolverTwelve = new HereTileResolver(new HereTileLevel(ZOOM_LEVEL_TWELVE));
HereTileResolver resolverFourteen =
new HereTileResolver(new HereTileLevel(ZOOM_LEVEL_FOURTEEN));
Set<Long> descendantTiles = resolverFourteen.fromAncestorTile(sanFranciscoTileId);
System.out.printf(
"The Tile %s (level %s) has the following descendant Tiles on level %s: %s%n",
sanFranciscoTileId, ZOOM_LEVEL_TWELVE, ZOOM_LEVEL_FOURTEEN, descendantTiles);
long sanFranciscoDescendantTile = descendantTiles.stream().findFirst().get();
long ancestor = resolverTwelve.fromDescendantTile(sanFranciscoDescendantTile);
System.out.printf(
"The Tile %s (level %s) has the following ancestor Tile on level %s: %s",
sanFranciscoDescendantTile, ZOOM_LEVEL_FOURTEEN, ZOOM_LEVEL_TWELVE, ancestor);
}
}
アプリケーションを実行するには、次のコマンドを実行します。
mvn package exec:java -D"exec.mainClass"="QuadTreeTraversalTutorialScala"
mvn package exec:java -D"exec.mainClass"="QuadTreeTraversalTutorial"
次のアプリケーションの結果が得られます。
The Tile 19319030 (level 12) has the following descendant Tiles on level 14: [309104494, 309104484, 309104489, 309104485, 309104481, 309104493, 309104486, 309104482, 309104492, 309104491, 309104483, 309104487, 309104480, 309104490, 309104495, 309104488]
The Tile 309104494 (level 14) has the following ancestor Tile on level 12: 19319030
ポイント検索
特定の地理座標 を含むタイル を取得する必要がある場合は、ロケーション ライブラリ HereTileResolver
[ Java API | Scala API ] クラスの fromCoordinate(geoCoordinate)
メソッドを使用します。
次のコード スニペットを使用 12
すると、サンフランシスコのゴールデンゲートブリッジをカバーするズーム レベルのタイル ID を取得できます。
地理座標 インスタンスは Golden Gate Bridge
、緯度 37.82171
および Golden Gate Bridge
経度を使用して作成 -122.47881
されます。
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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
}
object HereTileWithPointTutorialScala {
val ZOOM_LEVEL_TWELVE = 12
def main(args: Array[String]): Unit = {
val goldenGateBrgLatitude = 37.82171
val goldenGateBrgLongitude = -122.47881
val hereTileResolver = new HereTileResolver(HereTileLevel(ZOOM_LEVEL_TWELVE))
val geoCoordinateSanFrancisco = GeoCoordinate(goldenGateBrgLatitude, goldenGateBrgLongitude)
val tileId = hereTileResolver.fromCoordinate(geoCoordinateSanFrancisco)
println(
s"Tile ${tileId.value} on level $ZOOM_LEVEL_TWELVE containing the point $geoCoordinateSanFrancisco")
}
}
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.here.platform.location.core.geospatial.GeoCoordinate;
import com.here.platform.location.integration.herecommons.geospatial.HereTileLevel;
import com.here.platform.location.integration.herecommons.geospatial.javadsl.HereTileResolver;
public class HereTileWithPointTutorial {
public static final int ZOOM_LEVEL_TWELVE = 12;
public static void main(String[] args) {
double goldenGateBrgLatitude = 37.82171;
double goldenGateBrgLongitude = -122.47881;
HereTileResolver hereTileResolver = new HereTileResolver(new HereTileLevel(ZOOM_LEVEL_TWELVE));
GeoCoordinate geoCoordinateSanFrancisco =
new GeoCoordinate(goldenGateBrgLatitude, goldenGateBrgLongitude);
Long tileId = hereTileResolver.fromCoordinate(geoCoordinateSanFrancisco);
System.out.printf(
"Tile %s on level %s contains the point %s",
tileId, ZOOM_LEVEL_TWELVE, geoCoordinateSanFrancisco);
}
}
アプリケーションを実行するには、次のコマンドを実行します。
mvn package exec:java -D"exec.mainClass"="HereTileWithPointTutorialScala"
mvn package exec:java -D"exec.mainClass"="HereTileWithPointTutorial"
次のアプリケーションの結果が得られます。
Tile 19319036 on level 12 contains the point GeoCoordinate(37.82171,-122.47881)
バウンディング ボックス検索
前のチュートリアルでは、地図上の特定の座標のタイルを検索する方法を学習しました。 このチュートリアルでは、地図上の特定の領域をカバーするタイルを検索する方法について説明します。 地図の特定の四角形の部分にタイルを表示するには、バウンディング ボックスを使用する必要があります。
fromBoundingBox(boundingBox)
Java API | Scala API クラスのメソッドを使用すると、特定のバウンディング ボックスをカバーするタイルを取得できます。
次のアプリケーションは Golden Gate Park
、経度と緯度を使用します。
- 西行き経度 = -122.511241
- eastbound 経度 = -122.452919
- サウスバウンド緯度 = 37.763901
- 北行き緯度 = 37.774723
Golden Gate Park
のズーム レベルをカバーするタイル ID のセットを返します 15
。
次の図は、赤い境界線が付いたバウンディング ボックスと、この bbox を青い境界線でカバーするタイルを示しています。
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.here.platform.location.core.geospatial.BoundingBox
import com.here.platform.location.inmemory.geospatial.TileId
import com.here.platform.location.integration.herecommons.geospatial.{
HereTileLevel,
HereTileResolver
}
object HereBoundingBoxTutorialScala {
val ZOOM_LEVEL_FIFTEEN = 15
def main(args: Array[String]): Unit = {
val westBoundLongitude = -122.511241
val eastBoundLongitude = -122.452919
val southBoundLatitude = 37.763901
val northBoundLatitude = 37.774723
val hereTileResolver = new HereTileResolver(HereTileLevel(ZOOM_LEVEL_FIFTEEN))
val bbox = new BoundingBox(northBoundLatitude,
southBoundLatitude,
eastBoundLongitude,
westBoundLongitude)
val tilesCoveringBbox: Set[TileId] = hereTileResolver.fromBoundingBox(bbox)
println(
s"Tiles covering $bbox on level $ZOOM_LEVEL_FIFTEEN are [${tilesCoveringBbox.map(_.value).mkString(", ")}]")
}
}
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.here.platform.location.core.geospatial.BoundingBox;
import com.here.platform.location.integration.herecommons.geospatial.HereTileLevel;
import com.here.platform.location.integration.herecommons.geospatial.javadsl.HereTileResolver;
import java.util.Set;
public class HereBoundingBoxTutorial {
public static final int ZOOM_LEVEL_FIFTEEN = 15;
public static void main(String[] args) {
double westBoundLongitude = -122.511241;
double eastBoundLongitude = -122.452919;
double southBoundLatitude = 37.763901;
double northBoundLatitude = 37.774723;
HereTileResolver hereTileResolver = new HereTileResolver(new HereTileLevel(ZOOM_LEVEL_FIFTEEN));
BoundingBox bbox =
new BoundingBox(
northBoundLatitude, southBoundLatitude, eastBoundLongitude, westBoundLongitude);
Set<Long> tilesCoveringBbox = hereTileResolver.fromBoundingBox(bbox);
System.out.printf(
"Tiles covering %s on level %s are %s", bbox, ZOOM_LEVEL_FIFTEEN, tilesCoveringBbox);
}
}
アプリケーションを実行するには、次のコマンドを実行します。
mvn package exec:java -D"exec.mainClass"="HereBoundingBoxTutorialScala"
mvn package exec:java -D"exec.mainClass"="HereBoundingBoxTutorial"
次のアプリケーションの結果が得られます。
Tiles covering BoundingBox(37.774723,37.763901,-122.452919,-122.511241) on level 15 are [1236417959, 1236417970, 1236417977, 1236417971, 1236417974, 1236417954, 1236417955, 1236417976, 1236417958, 1236417964, 1236417960, 1236417980, 1236417965, 1236417961]
RADIUS 検索
前のチュートリアルでは、マップの特定の四角形の部分でタイルを取得する方法について説明しました。 ただし 、このHereTileResolver
クラスには 、 指定した中心と半径のある特定の円内のタイルをメートル単位で検索できるようにする [ タイル | タイル( Java API | Scala API ) ] fromCenterAndRadius(centerPoint, radius)
メソッドが用意されています。 この方法は、バウンディング ボックスを作成するための正確な座標がなく、マップ上に特定のポイントがある場合に便利です。 この場合、この円をカバーするすべてのタイルを取得するには、この点と半径をメートル単位で指定します。
Java と Scala の両方で次のアプリケーションを実行すると、 Holly Park
サンフランシスコのジオコード化された円と 150
ズーム レベルを使用した半径メーターをカバーするタイルが返さ 18
れます。 地理座標 インスタンスは Holly Park
、緯度 37.74638
および Holy Park
経度を使用して作成 -122.43584
されます。
次の図は、半径 150
がメートルの円を示し Holy Park
ています。この円は、カバーと、この円をカバーする 4 つのタイルで構成されています。
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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
}
object HereTileRadiusSearchScala {
val ZOOM_LEVEL_EIGHTEEN = 18
def main(args: Array[String]): Unit = {
val sanFranciscoLatitude = 37.73721
val sanFranciscoLongitude = -122.41994
val radiusInMeters = 100
val hereTileResolver = new HereTileResolver(HereTileLevel(ZOOM_LEVEL_EIGHTEEN))
val sanFranciscoGeoCoordinates = new GeoCoordinate(sanFranciscoLatitude, sanFranciscoLongitude)
val tilesCoveringCircle: Set[TileId] =
hereTileResolver.fromCenterAndRadius(sanFranciscoGeoCoordinates, radiusInMeters)
println(
s"A circle with a center at $sanFranciscoGeoCoordinates and radius of $radiusInMeters meters covers the following tiles on level $ZOOM_LEVEL_EIGHTEEN: ${tilesCoveringCircle
.map(_.value)
.mkString(", ")}")
}
}
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.here.platform.location.core.geospatial.GeoCoordinate;
import com.here.platform.location.integration.herecommons.geospatial.HereTileLevel;
import com.here.platform.location.integration.herecommons.geospatial.javadsl.HereTileResolver;
import java.util.Set;
public class HereTileRadiusSearchTutorial {
public static final int ZOOM_LEVEL_EIGHTEEN = 18;
public static void main(String[] args) {
double sanFranciscoLatitude = 37.73721;
double sanFranciscoLongitude = -122.41994;
double radiusInMeters = 100;
HereTileResolver hereTileResolver =
new HereTileResolver(new HereTileLevel(ZOOM_LEVEL_EIGHTEEN));
GeoCoordinate geoCoordinateSanFrancisco =
new GeoCoordinate(sanFranciscoLatitude, sanFranciscoLongitude);
Set<Long> tilesCoveringCircle =
hereTileResolver.fromCenterAndRadius(geoCoordinateSanFrancisco, radiusInMeters);
System.out.printf(
"A circle with a center at %s and radius of %s meters covers the following tiles on level %s: %s",
geoCoordinateSanFrancisco, radiusInMeters, ZOOM_LEVEL_EIGHTEEN, tilesCoveringCircle);
}
}
アプリケーションを実行するには、次のコマンドを実行します。
mvn package exec:java -D"exec.mainClass"="HereTileRadiusSearchScala"
mvn package exec:java -D"exec.mainClass"="HereTileRadiusSearchTutorial"
次のアプリケーションの結果が得られます。
A circle with a center at 37.73721,-122.41994 and radius of 100.0 meters covers the following tiles on level 18: [79130751637, 79130751551, 79130751592, 79130751680, 79130751594, 79130751681, 79130751549, 79130751595, 79130751593]
地理座標アダプターを使用した他のライブラリーとのインターフェース
HereTileResolver
このクラスで作業する場合、 GeoCoordinate
上記のコードセクションで何度も行ってきたように、マップ上で座標を転送するインスタンスを作成する必要があります。 ロケーション ライブラリは GeoCoordinate
、 GeoCoordinateHolder インターフェイスを実装するクラスを提供します。 ロケーション ライブラリのGeoCoordinate
クラスを使用することを強くお勧め しますが、使用しない場合は、このクラスのインスタンスを使用してロケーション ライブラリを操作する場合に、クラスが GeoCoordinateHolder インターフェイスを実装するかどうかを考慮する必要があります。 この チュートリアルのように、クラスが GeoCoordinateHolder インターフェイスを実装していない場合は 、 GeoCoordinateAdapter アダプタを提供する必要があります。
このチュートリアルでは 、 GeoCoordinateHolder インターフェイスを実装していない 2 つのカスタムGeoCoordinateJava
クラスとGeoCoordinateScala
クラスを使用します。
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
case class GeoCoordinateScala(latitude: Double, longitude: Double) {
def getLatitude: Double = latitude
def getLongitude: Double = longitude
}
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class GeoCoordinateJava {
private double latitude;
private double longitude;
public GeoCoordinateJava(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
@Override
public String toString() {
return String.format("(%s,%s)", latitude, longitude);
}
}
およびロケーション ライブラリから GeoCoordinateAdapter アダプタを実装する 2 つのカスタムGeoCoordinateAdapterJava
アダプタとアダプタGeoCoordinateAdapterScala
。
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.here.platform.location.core.geospatial.javadsl.GeoCoordinateAdapter
class GeoCoordinateAdapterScala private extends GeoCoordinateAdapter[GeoCoordinateScala] {
override def getLatitude(instance: GeoCoordinateScala): Double = instance.latitude
override def getLongitude(instance: GeoCoordinateScala): Double = instance.longitude
}
object GeoCoordinateAdapterScala {
lazy val getInstance = new GeoCoordinateAdapterScala()
}
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.here.platform.location.core.geospatial.javadsl.GeoCoordinateAdapter;
public class GeoCoordinateAdapterJava implements GeoCoordinateAdapter<GeoCoordinateJava> {
private GeoCoordinateAdapterJava() {}
@Override
public double getLatitude(GeoCoordinateJava instance) {
return instance.getLatitude();
}
@Override
public double getLongitude(GeoCoordinateJava instance) {
return instance.getLongitude();
}
public static GeoCoordinateAdapterJava getInstance() {
return new GeoCoordinateAdapterJava();
}
}
次のチュートリアルでは、前と同じことを示し ますが、 GeoCoordinateHolder インターフェイスを実装していないカスタムGeoCoordinatesJava
クラスとGeoCoordinatesScala
クラス、および GeoCoordinateAdapter インターフェイスを実装するカスタムGeoCoordinateAdapterJava
アダプタとGeoCoordinateAdapterScala
アダプタを使用しています。
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.here.platform.location.core.geospatial.javadsl.GeoCoordinateAdapter
import com.here.platform.location.integration.herecommons.geospatial.HereTileLevel
import com.here.platform.location.integration.herecommons.geospatial.javadsl.HereTileResolver
import java.{lang, util};
object HereTileRadiusSearchWithGcAdapterTutorialScala {
val ZOOM_LEVEL_EIGHTEEN = 18
def main(args: Array[String]): Unit = {
val sanFranciscoLatitude = 37.73721
val sanFranciscoLongitude = -122.41994
val radiusInMeters = 100
val hereTileResolver = new HereTileResolver(new HereTileLevel(ZOOM_LEVEL_EIGHTEEN))
val gca: GeoCoordinateAdapter[GeoCoordinateScala] = GeoCoordinateAdapterScala.getInstance
val geoCoordinateSanFrancisco: GeoCoordinateScala =
GeoCoordinateScala(sanFranciscoLatitude, sanFranciscoLongitude)
val tilesCoveringCircle: util.Set[lang.Long] =
hereTileResolver.fromCenterAndRadius(geoCoordinateSanFrancisco, radiusInMeters)(gca)
println(
s"A circle with a center at $geoCoordinateSanFrancisco and radius of $radiusInMeters meters covers the following tiles on level $ZOOM_LEVEL_EIGHTEEN: $tilesCoveringCircle")
}
}
/*
* Copyright (c) 2018-2023 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.here.platform.location.core.geospatial.javadsl.GeoCoordinateAdapter;
import com.here.platform.location.integration.herecommons.geospatial.HereTileLevel;
import com.here.platform.location.integration.herecommons.geospatial.javadsl.HereTileResolver;
import java.util.Set;
public class HereTileRadiusSearchWithGcAdapterTutorial {
public static final int ZOOM_LEVEL_EIGHTEEN = 18;
public static void main(String[] args) {
double sanFranciscoLatitude = 37.73721;
double sanFranciscoLongitude = -122.41994;
double radiusInMeters = 100;
HereTileResolver hereTileResolver =
new HereTileResolver(new HereTileLevel(ZOOM_LEVEL_EIGHTEEN));
GeoCoordinateAdapter<GeoCoordinateJava> gca = GeoCoordinateAdapterJava.getInstance();
GeoCoordinateJava geoCoordinateSanFrancisco =
new GeoCoordinateJava(sanFranciscoLatitude, sanFranciscoLongitude);
Set<Long> tilesCoveringCircle =
hereTileResolver.fromCenterAndRadius(geoCoordinateSanFrancisco, radiusInMeters, gca);
System.out.printf(
"A circle with a center at %s and radius of %s meters covers the following tiles on level %s: %s",
geoCoordinateSanFrancisco, radiusInMeters, ZOOM_LEVEL_EIGHTEEN, tilesCoveringCircle);
}
}
アプリケーションを実行するには、次のコマンドを実行します。
mvn package exec:java -D"exec.mainClass"="HereTileRadiusSearchWithGcAdapterTutorialScala"
mvn package exec:java -D"exec.mainClass"="HereTileRadiusSearchWithGcAdapterTutorial"
次のアプリケーションの結果が得られます。
A circle with a center at 37.73721,-122.41994 and radius of 100.0 meters covers the following tiles on level 18: [79130751637, 79130751551, 79130751592, 79130751680, 79130751594, 79130751681, 79130751549, 79130751595, 79130751593]
詳細情報
このチュートリアルで扱うトピックの詳細については、次のソースを参照してください。
- Java のタイルリゾルバ API の詳細について は、 API のマニュアルを参照してください。
- Scala のタイルリゾルバ Scala の詳細について は、 API のマニュアルを参照してください。
- ロケーション ライブラリの詳細について は、ロケーション ライブラリのマニュアルを参照してください。
- CLI を使用してタイル ID を使用してデータにアクセスする方法の詳細について は、 OLP CLI のドキュメントを参照してください。
- Scala および Java API を使用してデータにアクセスする方法の詳細について は、『データ クライアント ライブラリ開発者ガイド』を参照してください。
- さまざまなレイヤータイプおよびレイヤー設定の詳細について は、データサービスのドキュメントを参照してください。
- このチュートリアルで図を作成するために使用したデータ インスペクターを使用してマップ上のタイルを表示する方法の詳細については 、『データ可視化ガイド』を参照してください