How should we display GeoPackage on Mapbox GL JS? - mapbox-gl-js

We used wgrib2 to convert weather radar data into NetCDF format. We converted it to GeoPackage format using gdal_translate. We created a Color Map on QGIS 3.10 and the GeoPackage appeared as expected.
We would like to display this on the Internet using these files or processed versions of these files. We have Mapbox GL JS as a candidate for that but it is not required. We have not found a way to display the gpkg files we have generated. How can we get it to display?
https://docs.mapbox.com/mapbox-gl-js/guides/
We generated png images using gdaldem color-relief and we also tried the following method
However, when we zoomed in on the map with this method, the quality of the image was rough and it could not be displayed beautifully.
https://docs.mapbox.com/mapbox-gl-js/example/image-on-a-map/
Since the gpkg we generated displays correctly in QGIS, it would be most desirable to be able to display the gpkg on MapBox. However, if that is not possible, we would like to display that data beautifully, even in another format.
We also tried to generate tiles using gdal2tiles.py. It worked as we expected when we created data up to zoom level 10. However, when we created the data for zoom level 11, it took more than 12 minutes. Since our data is generated every 5 minutes, we cannot spend any more time on tile generation.

Mapbox GL JS specialises in displaying vector tiles, but can also display raster tiles. If you can't generate static raster tiles from your GeoPackage data source (because they're too big and change too fast), you'll need some kind of server that can read GeoPackage and serve up raster tiles on demand.
Running GeoServer would be one way to do that. It supports GeoPackage natively and could serve up the requested tiles without having to generate them all in advance.
There is also a NetCDF extension that might let you skip the GeoPackage conversion step.
(What you tried was generating a single raster image, which was probably insufficiently detailed for your needs).

Related

Mapbox Android SDK - querySourceFeatures at a given coordinate

I use Mapbox Tileset API and generated a custom tileset (it's a huge 400MB of GeoJSON data) uploaded to Mapbox servers, and added to our style in the studio as a custom fill layer.
This way I can show our custom areas (as polygons) of the world with green (visited) and red (remaining) locations with using expressions only.
I would like to tell if a point (GPS coordinate) is within a polygon of the tileset source/layer and which one, even if the app is in the background (GPS tracking is running in the background and I would like to notify the user when they are within a polygon).
Using queryRenderedFeatures would be great, but unfortunately, it doesn't work when the app is in the background or the user's position is outside of the current viewport.
Is there any solution to get the list of the features at a GPS coordinate even if it's outside of the viewport?
Another requirement is that, it should work when the device is offline, so the Tilequery API won't help.
Downloading the offline data of our style with a limited zoom range working perfectly, I can see my custom source-layer (polygons) even if the device is offline.
So I think there should be a way to query the tileset-source when the device is offline too.
Currently, I generate a simplified GeoJSON file and use it with turf#points-within-polygon when the device is offline, but there're gaps, sometimes polygons are covering each other (due to the simplifying) etc... if I make the tolerance level lower the file is going to be too large to download and store it offline, so this is not really a solution just a poor workaround.
Can I make a PIP (point-in-polygon) query for a custom Tileset source even outside of the viewport, when the app is in the background and the device is offline?
Assuming this is your actual question:
Can I make a PIP (point-in-polygon) query for a custom Tileset source even outside of the viewport, when the app is in the background and the device is offline?
If the device is offline, then any solution that requires fetching tiles on demand (like a tileset in Mapbox-GL or TileQuery) is out.
You said storing the whole GeoJSON is out, because it's too big.
I think the remaining solution is to generate a single-zoom-level tileset and store it locally, then query it with something like query-mbtiles.

Is it possible to visualize non-standard dynamic range (for example, astronomical) images on leaflet?

Leaflet supports both image and tile server layers as a mapping layer (along with a few other raster layers). However, both of these seem to only work with "standard" image types, for example jpeg, png, etc. If I have an image in some higher dynamic range format - specifically, astronomical images in FITS format which have more than 8 bits per channel, is there any way to serve these using leaflet, or do they need to be converted into tiles or images in a more standard format?
As of now (early 2019), there are some Leaflet plugins for non-standard image formats, specifically Leaflet.TileLayer.IIP and Leaflet-IIIF. You might be able to transform your images from FITS to one of those formats.
If you're able to slice your image in small tiles, and then generate two (or more) .pngs or .jpgs per each of your FITS image (e.g. one .png per each original channel), then you might want to consider a more exotic solution: WebGL through Leaflet.TileLayer.GL. That Leaflet plugin will allow you to grab pixels from several images at once and combine them with a custom shader function. See Mapbox's Terrain-RGB tiles and the TileLayer.GL documentation&demos for more info.
As a side note: Leaflet supports displaying .webp tiles if your web browser supports .webp.

Mapbox GL / style - data separation

I have played with Mapbox and can quite easily create a Choropleth map in Mapbox studio and interact with it in Javascript.
I would like to create Choropleth map of the states with the ability to change the colours of the states for 100 years of different data points. I'm not allowed to upload the data into Mapbox as its sensitive healthcare data and I can't get sign of for the $499 a month cost.
My idea is I create a mapbox style layer in MapBox Studio then push the data client side for each of the states depending on the year x that the user selects. I have seen quite a few cloropeth tutorials such as this https://www.mapbox.com/help/choropleth-studio-gl-pt-1/ but the data is added in through a layer in Mapbox Studio. My thoughts are to embed the large GeoJson in the style and only push the data to the Polygon ID's, whilst creating transtions between the two.
Does anyone have any ideas if this is possible? and perhaps any useful API requests which may help me achieve this https://www.mapbox.com/api-documentation/.
It's possible. There are two approaches:
Upload the geometry as a Dataset in Studio, or load it directly as a GeoJSON.
Set data attributes directly on the geometry.
Create a style with data-driven styles (eg, map "47" to "rgb(100,0,0)" and "153" to "rgb(250,250,0)" and let Mapbox interpolate.
Or:
Upload the geometry as a Tileset to Studio.
Calculate the color you want to represent each possible value of each state.
Generate a data-driven style property that maps each state's code to the color you want, like ...['FL','rgb(143,15,0)']....
Neither method will cope with large numbers of regions, but should be ok for 50 US states at low resolution.
More discussion here: https://github.com/mapbox/mapbox-gl-js/issues/4261

MapBox MB Tile vs Vector Tile

I am a bit confused about Tiles in MapBox. As I understood, a tile is a little piece of map, as in a jigsaw puzzle.
MBTiles are images, but they are connected to a database to read data & let interactions be possible. So if I move the mouse, I can show details of the layers under the cursor.
Vector Tiles store all the data in vectors, and they are just used for a fast rendering of the image. Interaction with such data is not possible.
Am I wrong?
Now, I see that there is the tool TileMill for MBTiles, and MapBox Studio Classic for Vector Tiles. I guess they are for different purposes; the first for interactive maps, the latter for fast rendering.
So.... why is TileMill not supported anymore, in favor of MBStudio?
Is it possible to make interactive maps with MBStudio as well?
Thank you
This is a great question!
mbtile is a filetype that can contain either raster or vector tiles. Think about it like an Adobe Illustrator .ai file -- it can either contain vector or raster data. Both raster tiles and vector tiles can be in mbtile format.
With TileMill, your vector data (shapefile, CSV, etc.) was combined with your CartoCSS style and passed to Mapnik to generate a bunch of tiled images. You could then store your tiles and feed them to a web map via a tile server. With Mapbox Studio Classic, you are converting your data to vector tiles and creating a CartoCSS style to style the data, but the image tiles aren't created until the map is requested via the browser. Ultimately, the output on the map is the same -- a grid of raster tiles.
The interactivity you created in TileMill with raster tiles is happening via a UTFGrid. This is an invisible raster layer that sits beneath the image tiles and adds interactivity to certain locations. The interactivity is not actually connected to any individual features at all -- it's just at the same location as your features. This is also possible in Mapbox Studio Classic, as the output in the map will also be a grid of raster tiles. You can read more about how to do this in Mapbox Studio Classic in the style quickstart guide.
So to answer your question, the move to Mapbox Studio Classic was to take advantage of vector tiles. They are a lot smaller than raster image tiles, and they can be styled on the fly, so, for example, you don't have to store two separate sets of images to accommodate retina screens. It also means you can have multiple styles applied to the same vector data on the fly, which means you don't have to regenerate a whole set of images for every style or every small change.
If the Metadata table contains a record format=pbf then the mbtiles is a vector tiles and not raster. mbtiles SQLite database can be a container for vector tiles which have in the Tiles table and tile_data blob field PBF -Protocol Buffers - protobuf ( https://github.com/google/protobuf – language neutral platform neutral mechasism for serializing structured data) Developed by Google. Tools like MapBox Studio build vector tiles from GIS Vector Data and databases

How to convert shapefile to tile based file

I am developing a Map based iPhone application where I have to draw a map of any specific region depending upon the current location of that device.
Client is supplying me the .shapefile consisting of all the co-ordinates and data to draw the map.
We can store the shape file on the server and i think to draw the map on device with the data presented on .shapefile I need the tiles with different zoom level. So on the server side I have to convert the .shapefile into tile based file.
But I don't know how to do that conversion.
Can anyone please guide me?
Thanks in advance.
Ritz
Its a lot of work.
First, shapefiles only define the geometry - you need to decide what the features are going to look like. Are they points, lines, or polygons? Do you want them all in the same colour, or depending on their attributes?
Then get mapnik or TileMill and learn how to use that. Do you just want to present the shapefile, or do you want that on a base map? In which case you'll have to generate a transparent tile set and do raster image overlays in your application.
Is it the whole world? And to the same resolution as Google Maps zooms? Get a big bank of disk storage.
http://mapbox.com/tilemill/
http://mapnik.org/
Personally I'd look into converting the shapefile into a vector form that you could render on the client - GeoJSON perhaps. Then serve that.