コアモジュール

このセクションで core は、ロケーション ライブラリのモジュールを使用して特定の目的を達成するのに役立つ追加情報を提供します。

core このモジュールには、位置データ全般および特に道路ネットワークを操作するための主要なインターフェイスおよびアルゴリズムが含まれています。

  • 地理空間 の操作とクエリ
    • 地理座標および投影座標、線文字列、および境界ボックスを操作する操作
    • 指定 したポイントに近いエレメントを検索する近接検索
  • 車両によって記録された一連の位置(通常は GPS 位置)を取得し、車両が通過する経路の再構築を試みるパスマッチング
  • 各頂点またはエッジの関連する属性へのアクセスを提供するプロパティマップ。

SBT
Maven
グレードル
libraryDependencies ++= Seq(
  "com.here.platform.location" %% "location-core" % "0.21.788"
)
<dependencies>
    <dependency>
        <groupId>com.here.platform.location</groupId>
        <artifactId>location-core_${scala.compat.version}</artifactId>
        <version>0.21.788</version>
    </dependency>
</dependencies>
dependencies {
    compile group: 'com.here.platform.location', name: 'location-core_2.12', version:'0.21.788'
}

データモデル抽象化

geospatial サブパッケージは、アルゴリズムで使用されるジオメトリタイプの抽象化を定義します( Scala 固有)。

次の操作は、ユーザータイプからロケーション ライブラリを抽象化します。

これにより、ロケーション ライブラリで独自のタイプを使用できます。

ジオコード化、座標、またはバウンディングボックスに独自の種類がない場合、ロケーション ライブラリでは最小限の実装しか提供されません。

単純な行文字列を表す場合 、 GeoCoordinates のシーケンスを使用できます。

ロケーション ライブラリへの入力としてタイプを使用する場合は、次のように定義できます。

Scala
Java
case class MyPosition(eventId: String, latitude: Double, longitude: Double)
class MyPosition {
  MyPosition(final String eventId, final double latitude, final double longitude) {
    this.eventId = eventId;
    this.latitude = latitude;
    this.longitude = longitude;
  }

  final String eventId;
  final double latitude;
  final double longitude;
}

カスタム入力タイプをロケーション ライブラリによって提供されているタイプに変換する代わりに、次のようにしてタイプのアクセサを定義できます。

Scala
Java
import com.here.platform.location.core.geospatial._

implicit object MyPositionOperations extends GeoCoordinateOperations[MyPosition] {
  override def latitude(c: MyPosition): Double = c.latitude

  override def longitude(c: MyPosition): Double = c.longitude
}
import com.here.platform.location.core.geospatial.ElementProjection;
import com.here.platform.location.core.geospatial.GeoProjections;
import com.here.platform.location.core.geospatial.javadsl.GeoCoordinateAdapter;
import com.here.platform.location.core.geospatial.javadsl.GeoCoordinates;
import com.here.platform.location.core.geospatial.javadsl.LineStringAdapter;
import com.here.platform.location.core.geospatial.javadsl.LineStrings;

import java.util.Arrays;
import java.util.List;

class MyPositionAdapter implements GeoCoordinateAdapter<MyPosition> {
  @Override
  public double getLongitude(final MyPosition instance) {
    return instance.longitude;
  }

  @Override
  public double getLatitude(final MyPosition instance) {
    return instance.latitude;
  }
}

同様に、バウンディング ボックスまたは行文字列タイプに必要な操作を定義できます。

Scala
Java
case class MyTrip(tripId: String, events: Seq[MyPosition])

implicit object MyTripOperations extends LineStringOperations[MyTrip] {
  override type Point = MyPosition
  override val PointGeoCoordinateOperations: GeoCoordinateOperations[Point] =
    MyPositionOperations

  override def points(lineString: MyTrip): Seq[MyPosition] = lineString.events
}
class MyTrip {
  String tripId;
  List<MyPosition> events;
}

class MyTripAdapter implements LineStringAdapter<MyTrip, MyPosition> {
  @Override
  public List<MyPosition> getPoints(final MyTrip lineString) {
    return lineString.events;
  }
}

次の段落と例では、これらの抽象化の使用方法を示します。

地理空間の操作

前の段落で定義した抽象化を実装した後、位置情報を使用して、既存のデータ型にさまざまな関数を適用できます。

たとえば、 2 つの WGS-84 座標の間でコンパスの方向を計算する場合、カスタムタイプを使用できます。

Scala
Java
val start = MyPosition("Start", 52.53062, 13.38531)
val end = MyPosition("End", 52.53088, 13.38515)

println(f"Your heading is: ${GeoCoordinates.heading(start, end)}%1.1f°")
final MyPosition start = new MyPosition("Start", 52.53062, 13.38531);
final MyPosition end = new MyPosition("End", 52.53088, 13.38515);

final double heading = GeoCoordinates.getInstance(new MyPositionAdapter()).heading(start, end);

System.out.format("Your heading is: %1.1f°%n", heading);
Your heading is: 339.5°

同様に、セグメント形状があり、その形状への点の投影を距離とともに計算する場合は、次のコードを使用します。

Scala
Java
// Optimized Map for Location Library types
import com.here.schema.geometry.v2.geometry.{LineString, Point}

// Optimized Map types implicits
import com.here.platform.location.integration.heremapcontent.geospatial.Implicits._

// Create the geometry of a pedestrian path following the Spree river, using HERE Types
val geometry: LineString = LineString(
  Seq(Point(52.51464, 13.40091),
      Point(52.51546, 13.40027),
      Point(52.51573, 13.40009),
      Point(52.51591, 13.40001)))

// A position of the user type
val position = MyPosition("Current", 52.51537, 13.40114)

// Project your point on the HERE geometry
val projection = LineStrings.pointProjection[MyPosition, LineString](
  position,
  geometry,
  SinusoidalProjection
)

println(
  "The nearest point is: " +
    f"${projection.nearest.latitude}%1.5f, ${projection.nearest.longitude}%1.5f")
// Create the geometry of a pedestrian path following the Spree river, using custom types
final MyTrip geometry = new MyTrip();
geometry.events =
    Arrays.asList(
        new MyPosition("1", 52.51464, 13.40091),
        new MyPosition("2", 52.51546, 13.40027),
        new MyPosition("3", 52.51573, 13.40009),
        new MyPosition("4", 52.51591, 13.40001));

// A position of the user type
final MyPosition position = new MyPosition("Current", 52.51537, 13.40114);

// Project your point on the geometry
final ElementProjection<MyTrip> projection =
    LineStrings.getInstance(new MyTripAdapter(), new MyPositionAdapter())
        .pointProjection(position, geometry, GeoProjections.sinusoidal());

System.out.format(
    "The nearest point is: %1.5f, %1.5f%n",
    projection.getNearest().getLatitude(), projection.getNearest().getLongitude());

投影には、線文字列上の投影点の位置を表す分数も含まれています。 このフラクションには、次のようにアクセスできます。

Scala
Java
val fraction = projection.fraction
println(f"The nearest point is ${fraction * 100}%1.0f%% of the way along the segment")
final double fraction = projection.getFraction();
System.out.format(
    "The nearest point is %1.0f%% of the way along the segment%n", fraction * 100);

」に一致する結果は 件です

    」に一致する結果はありません