weixin_39769406
weixin_39769406
2020-12-27 02:23

Unable to open the vector tile end points

I am trying to parse the vector tile end points but the results I get

http://localhost:3001/services/postgis/pois/geom/vector-tiles/{z}/{x}/{y}.json

are not readable. I can't open or read the endpoints in any format. How can I parse/read the vector tile endpoints?

该提问来源于开源项目:spatialdev/PGRestAPI

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

6条回答

  • weixin_39972019 weixin_39972019 4月前

    According to https://github.com/spatialdev/PGRestAPI/blob/master/docs/VectorTiles.md the file extension is pbf not json.

    The vector tiles can be tested using one of the solutions provided here: https://github.com/mapbox/awesome-vector-tiles

    If you do not use a Javascript client (e.g. Mapbox GL JS, which needs the URL template for the vector tiles (e.g. http://localhost:3001/services/postigs/pois/geom/vector-tiles/{z}/{x}/{y}.pbf) you can test the endpoints by: 1. Get the raw tile via cURL (note the actual Zoom/X/Y coordinates are 0/0/0) curl http://localhost:3001/services/postigs/pois/geom/vector-tiles/0/0/0.pbf 2. Parse the tile (0.pbf) with one of the parsers E.g. for the vector-tile Javascript parser open node after having installed vector-tile and pbf via npm install

    
    VectorTile = require('vector-tile').VectorTile;
    Protobuffer = require('pbf'); 
    fs = require('fs');
    zlib = require('zlib');                                                                           
    pbfData = fs.readFileSync('0.pbf');// generated by PGRestAPI
    vt = new VectorTile(new Protobuffer(pbfData)));
    

    Furthermore, please note that the endpoints are generated only once at the start of the PGRestAPI application. If you add tables afterwards, you will get 404 while requesting them. A workaround is to restart the application.

    点赞 评论 复制链接分享
  • weixin_39769406 weixin_39769406 4月前

    I am able to render the tiles using the Leaflet.MapboxVectorTile plugin. I tried it with different formats, using json instead of pbf in the URL template ( http://localhost:3001/services/postigs/pois/geom/vector-tiles/{z}/{x}/{y}.pbf works exactly like http://localhost:3001/services/postigs/pois/geom/vector-tiles/{z}/{x}/{y}.json )

    What I wanted to try and do was to look at what the individual tiles contain, how they return the data?, what exactly is returned at what zoom levels?, for that purpose I tried getting the json tiles instead of pbf because it is easier to parse/understand.

    I will look into the parsers you have listed, thank you for taking the time to explain and clarify a lot of things.

    Furthermore, please note that the endpoints are generated only once at the start of the PGRestAPI application. If you add tables afterwards, you will get 404 while requesting them. A workaround is to restart the application.

    I have not added any extra table since I made the initial connected to PostGres but I still get the 404 error at some tiles, any idea what could cause this? ( I already looked to make sure that these tiles were not out of bounds of the data )

    点赞 评论 复制链接分享
  • weixin_39972019 weixin_39972019 4月前

    JSON considerations

    On a more general note, JSON is used to fetch all the data at once. It is like getting the entire content of the Postgres spatial table in a JSON format (more specifically GeoJSON).

    PGRestAPI does have an endpoint for that:

    
    curl 'http://localhost:3001/services/tables/pois/query?format=geojson&returnGeometry=yes&returnGeometryEnvelops=no'
    

    I have extracted the above URL from playing with the query string in the web interface available at:

    
    http://localhost:3001/services/tables/pois/query
    

    I have not seen tiled GeoJSON that often. When used the following happens: 1. less features because of the bounding box of the tile 2. simplified geometries because of zoom level

    Regarding the extension json or pbf, after some testing, I see this is ignored. E.g. you could have xfrgsg and you would get the same binary data.

    So you are not getting JSON from:

    
    http://localhost:3001/services/postgis/pois/geom/0/0/0.json
    

    Tiles not found

    I have seen this behavior when zooming in and out really fast. A minority of tile requests end up in 404. I do not know why, but the user experience is not affected because the ones that are not found are at a previous zoom level.

    点赞 评论 复制链接分享
  • weixin_39769406 weixin_39769406 4月前

    Using the Vector Tile Javascript Parser I was able to view the contents of individual tiles, was a bit stuck at this point for a while so really appreciate the help.

    The JSON considerations do make sense, not getting json from: http://localhost:3001/services/postgis/pois/geom/0/0/0.json does explain a lot.

    Point Layer

    I have noticed that while the other geometries are simplified at different zoom levels, this is not the case with points, the http://localhost:3001/services/postgis/pois/geom/vector-tiles/10/719/410.pbf (point layer) is 212kb, and as we go to higher zoom levels it is sliced, is there any way to show the points based on another attribute (priority or something) at lower zoom levels to be able to reduce the size of the tiles.

    点赞 评论 复制链接分享
  • weixin_39972019 weixin_39972019 4月前

    According to VectorTiles.md you can filter the features from the requested layer by adding a where= query string:

    
    curl 'http://localhost:3001/services/postgis/pois/geom/vector-tiles/0/0/0.pbf?where=priority%3C3'
    

    will obtain only the features that have priority<3. This assumes you have a priority column.

    Please note the warning:

    Note - This should be used sparingly, or in conjunction with a cache (like an NGINX reverse proxy cache) as to not overwhelm the database with requests. (Remember, the database executes the same query for every tile requested)

    点赞 评论 复制链接分享
  • weixin_39769406 weixin_39769406 4月前

    That does work on a level, but I am trying to get different different query strings for different zoom levels, so I can filter my results on the fly. Using the where query string in the URL will filter all the results, while I only want to filter the results based on zoom levels.

    I'll open a new thread about this. This one has digressed too much.

    点赞 评论 复制链接分享

相关推荐