geojson2vt icon indicating copy to clipboard operation
geojson2vt copied to clipboard

What format is returned by get_tile ?

Open eLvErDe opened this issue 5 years ago • 6 comments

Hello,

I used you library to implement a VectorTile server from GeoJSON however I've been unable to display the resulting tile with OpenLayers. I get a dict with keys likes minX, maxY... and I have no idea what format this is. I tried MVP, GeoJSON and TopoJSON in OpenLayers, none managed to load these tiles.

Thanks

eLvErDe avatar Jun 22 '20 10:06 eLvErDe

It should comply with the vector-tile-spec that can be found here: https://github.com/mapbox/vector-tile-spec/blob/master/README.md. I'm not sure about the viewers that support this format, though, and someone more qualified might be able to help. The JavaScript package reference https://github.com/mapbox/mapbox-gl-js as an example, maybe that helps.

hixi avatar Jun 22 '20 15:06 hixi

Hello,

I'm not sure about that, MVT file are supposed to be protobuf, or maybe I should then encode the dict payload to protobuf ?

Thanks

eLvErDe avatar Jun 23 '20 07:06 eLvErDe

Seems I misunderstood the spec. This is a python port of the javascript equivalent geojson-vt which states:

Resulting tiles conform to the JSON equivalent of the vector tile specification.

I'm not sure, but in theory it should be possible to encode in protobuf to be conformant with the spec.

hixi avatar Jun 29 '20 07:06 hixi

@Murthy10 I have the same question... I'm not quite sure how to get from the not-quite-GeoJSON but also not-quite-vt-protobuf output to something I can load as a real honest vector tile.... this code illustrates I believe the same "what now?" question that has us scratching our heads

# This is a large half-gigabyte FeatureCollection, load once at startup
geojson_path = 'big-featurecollection.geojson'
geojson_data = get_json(geojson_path)
mvt = geojson2vt(geojson_data, {'maxZoom': 20})

@app.route(f"{URL_BASE}/vector_tiles/<int:z>/<int:x>/<int:y>")
def vector_tiles(z=None, x=None, y=None, geojson_key=None):
    tile_dict = mvt.get_tile(z, x, y)

    # So.... Now what????
    #
    # OK, I don't think /this/ is right.... this JSON is now a LOT
    # more like the spec in vector_tile.proto but I'm missing some
    # step to convert this to an actual binary ProtoBuf, but tile_dict
    # is still not suitable to call google.protobuf.json_format.ParseDict
    # according to the vector_tile.proto spec.... so how do we get
    # from point A to something mapboxGL will see as a binary protobuf MVT???
    
    return jsonify(tile_dict)

Any hints? :-)

snickell avatar Jul 29 '21 03:07 snickell

@Murthy10 I have the same question... I'm not quite sure how to get from the not-quite-GeoJSON but also not-quite-vt-protobuf output to something I can load as a real honest vector tile.... this code illustrates I believe the same "what now?" question that has us scratching our heads

# This is a large half-gigabyte FeatureCollection, load once at startup
geojson_path = 'big-featurecollection.geojson'
geojson_data = get_json(geojson_path)
mvt = geojson2vt(geojson_data, {'maxZoom': 20})

@app.route(f"{URL_BASE}/vector_tiles/<int:z>/<int:x>/<int:y>")
def vector_tiles(z=None, x=None, y=None, geojson_key=None):
    tile_dict = mvt.get_tile(z, x, y)

    # So.... Now what????
    #
    # OK, I don't think /this/ is right.... this JSON is now a LOT
    # more like the spec in vector_tile.proto but I'm missing some
    # step to convert this to an actual binary ProtoBuf, but tile_dict
    # is still not suitable to call google.protobuf.json_format.ParseDict
    # according to the vector_tile.proto spec.... so how do we get
    # from point A to something mapboxGL will see as a binary protobuf MVT???
    
    return jsonify(tile_dict)

Any hints? :-)

did you managed to figuring it out? I am stuck here.

SulimanLab avatar May 11 '22 08:05 SulimanLab

old issue but still relevant: here for reference you need to encode as bpf with something like this: https://github.com/DenysMoskalenko/vt2pbf

pumelo avatar Jan 03 '23 12:01 pumelo