ベクタータイルをデコードするためのprotobufスキーマを取得します

ベクタータイルを取得したら、protobufスキーマを使用してデコードする必要があります。 ベクタータイルにポイント、ライン、およびポリゴンとして格納されている地理情報をデコードすると、アプリケーションはそのデータをマップレンダリングに使用できます。

関連するprotobufスキーマを取得

protobufスキーマを取得します。このスキーマは、ベクタータイルデータをバイナリから人間が読める形式にデコードするためのキーとして機能します。

  1. エンドポイントprotoへのリクエストGET を生成して、使用可能なprotobufスキーマの名前を取得します。 例:

     curl -X "GET" \
     "https://vector.hereapi.com/v2/vectortiles/proto?apiKey=APIKEY_HERE" \
     -H "accept: application/json"
    

    結果: 次の例に示すように、サーバのレスポンスに成功すると、 Protobuf スキーマ 名が含まれます。

     [{"name":"vector_tile.proto", "description":"OMV format"}]
    
  2. 次の例に示すように、エンドポイントproto/{name}へのリクエストGETを生成して、関連する Protobuf スキーマ を取得します。

     curl -X "GET" \
     "https://vector.hereapi.com/v2/vectortiles/proto/vector_tile.proto?apiKey=APIKEY_HERE" \
     -H "accept: text/plain"
    

    ここで、

    • vector_tile.proto は、エンドポイントprotoへのリクエストによって取得したprotobufスキーマパラメータnameです。

結果: 成功したサーバーレスポンスには、次の例に示すように、ベクタータイルのデコードに使用するprotobufスキーマが含まれています。

//package vector_tile;
package com.mapbox.pb;

option optimize_for = LITE_RUNTIME;

message Tile {

    // GeomType is described in section 4.3.4 of the specification
    enum GeomType {
        UNKNOWN = 0;
        POINT = 1;
        LINESTRING = 2;
        POLYGON = 3;
    }

    // Variant type encoding
    // The use of values is described in section 4.1 of the specification
    message Value {
        // Exactly one of these values must be present in a valid message
        optional string string_value = 1;
        optional float float_value = 2;
        optional double double_value = 3;
        optional int64 int_value = 4;
        optional uint64 uint_value = 5;
        optional sint64 sint_value = 6;
        optional bool bool_value = 7;

        extensions 8 to max;
    }

    // Features are described in section 4.2 of the specification
    message Feature {
        optional uint64 id = 1 [ default = 0 ];

        // Tags of this feature are encoded as repeated pairs of
        // integers.
        // A detailed description of tags is located in sections
        // 4.2 and 4.4 of the specification
        repeated uint32 tags = 2 [ packed = true ];

        // The type of geometry stored in this feature.
        optional GeomType type = 3 [ default = UNKNOWN ];

        // Contains a stream of commands and parameters (vertices).
        // A detailed description on geometry encoding is located in
        // section 4.3 of the specification.
        repeated uint32 geometry = 4 [ packed = true ];
    }

    // Layers are described in section 4.1 of the specification
    message Layer {
        // Any compliant implementation must first read the version
        // number encoded in this message and choose the correct
        // implementation for this version number before proceeding to
        // decode other parts of this message.
        required uint32 version = 15 [ default = 1 ];

        required string name = 1;

        // The actual features in this tile.
        repeated Feature features = 2;

        // Dictionary encoding for keys
        repeated string keys = 3;

        // Dictionary encoding for values
        repeated Value values = 4;

        // Although this is an "optional" field it is required by the specification.
        // See https://github.com/mapbox/vector-tile-spec/issues/47
        optional uint32 extent = 5 [ default = 4096 ];

        extensions 16 to max;
    }

    repeated Layer layers = 3;

    extensions 16 to 8191;
}

ベクタータイルをデコード

ベクタータイルを含むバイナリファイルはマップアプリケーションで使用されることを意図しているため、人間がそれらのファイルを読み取ることは想定されていません。 ただし、テストやトラブルシューティングなどの目的で、タイルに含まれるデータを検査することができます。 したがって、取得したprotobufスキーマを使用して、ベクタータイルをバイナリ形式よりも読みやすい形式にデコードできます。

次の例では、protobufでエンコードされたデータをデコードするためのコマンドラインツールであるprotocを使用しています。 インストール手順および使用可能なコマンドの全リストについては 、マニュアルprotocを参照してください。

  1. リクエストproto/{name} へのレスポンスからペイロードを ファイル.protoとして保存します。
  2. コマンドプロンプトウィンドウを開きます。
  3. コマンドプロンプトで、次の項目を含むディレクトリに移動します。
    • .mvt フォーマットのベクタータイルデータ
    • タイルをデコードするためのProtobufスキーマ
  4. コマンドプロンプトで 、次のコマンド
     protoc --decode=com.mapbox.pb.Tile vector_tile.proto < response.mvt >> output.txt
    
    を入力して、ツールprotocを使用してタイルをデコードします。ここで
    • com.mapbox.pb.Tile は、protobufスキーマで定義されているOMVまたはMVT型の完全修飾トップレベルメッセージです
    • vector_tile.proto は、タイルをデコードするためのスキーマを含むファイルの名前です
    • response.mvt は、ベクタータイルデータを含むprotobufエンコードされたバイナリファイルです
    • output.txt は、デコードされたデータを格納するファイルです

結果: デコードされたデータは output.txt 、ファイルで表示できます。

デコードされたファイルは、ベクタータイル境界内のポリゴン、ポイント、およびラインのジオメトリ情報、および関連するメタデータを表す、一連のキーと値のペア(JSON形式に似ています)です。

タイルデータを視覚化

ベクタータイルの表示範囲を調べるには、バイナリ .mvt ファイルを .geojson ファイルに変換し、タイルデータをレイヤとしてマップ上に配置します。

  1. Convert the binary .mvt file that you obtained earlier to the .geojson format by using the converter tool of your choice.

    ヒント

    For example, you can use the vt2geojson tool.

  2. ファイル.geojson にエンコードされたデータをマップ上にレンダリングします。 詳細については、 「GeoJSONデータの表示」を参照してください。

結果: 次の例で .geojson は、ポイント、ポリゴン、およびラインの形式のベクタータイルデータを、ファイルからマップ上にレンダリングして示します。

マップ上のベクタータイルデータ
図1. マップ上のベクタータイルデータ

次のステップ

  • HERE Vector Tile APIのリクエストとレスポンスの詳細については、 APIリファレンスを参照してください。
  • ベクターデータの保存方法とエンコード方法の詳細については 、「ベクタータイルの仕様」を参照してください。
  • HERE Vector Tile APIを使用してマップをレンダリングする方法のチュートリアルについては 、「」を参照してください。
  • このドキュメントに適用される利用規約につきましては、「HERE Documentation License」を参照してください。

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

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