Rendering non-simplified Mapbox Vector Tile using mapbox gl js - polygon

I am trying to render a mvt (Mapbox Vector Tile) containing OSM data using Mapbox GL js, but I keep getting some ugly polygons like they were simplified (like in the Simplification section of this documentation!). I don't want those polygons to be simplified. At least I would like the best resolution to be as close as possible from reality.
First, I checked if it could come from OSM data. But OSM data is good.
So I looked into the tile server and more precisely into the mvt encoder (code). The extent value, which controls how detailed the coordinates are encoded in the vector tile, is 4096. 4096 is a very good value. So I don't understand why I don't get proper polygons.
I suppose that this issue comes from Mapbox GL js which might perform an additional simplification.
What extent value could I use in the encoder?
Is there a way to configure a resolution with mapbox gl js ?
I would appreciate some help !
Thanks!

Mapbox GL JS does not do any additional simplification on vector tile sources. If you are seeing simplified geometries, this is most likely done during vector tile generation.

I was finding the same thing. I got better results when, rather than importing the polygons as a geojson as I had been doing, I converted the file to a shape file, zipped it, and imported that into mapbox. There was then no simplification to the shape.

Related

Is there a javascript library to reproject a geojson so that mapbox gl will render it looking like 'Plate-Carrée'?

I'm building a web application using Angular and mapbox-gl-js as map library.
The map tiles are projected using EPSG:4326 Plate-Carrée and the dataset is GeoJson (WGS84).
Since mapbox supports only web mercator projection, the data is not displayed in the correct position on map.
Any suggestions how to reproject the dataset so mapbox is able to display the data in the correct location?
Thanks.
If I understand your question correctly, you have some raster tiles which are "projected" (well, not really) in EPSG:4326, and you would like to display them in Mapbox-GL-JS. You also have another dataset, in GeoJSON, also provided in EPSG:4326, which you would like to overlay.
As you note, Mapbox-GL-JS only supports the EPSG:3857 (Web Mercator) projection. It projects datasets (but not raster tiles) from EPSG:4326 to EPSG:3857 in order to display them.
Your good options are:
Find a different basemap in Web Mercator
Find a web service which can reproject the tiles you have on the fly
Maybe there's some way where you could let Mapbox-GL-JS think it's displaying your tiles in EPSG:3857, then somehow adjust the coordinates of your overlaid dataset so that when they're reprojected from EPSG:4326 to EPSG:3857 they end up in the right positions. But I can't think how to achieve that.
You could try asking at gis.stackexchange.com.

How does a non-tile based map works?

Ok, here is the thing. Recently i decided i wanted to understand how Random map generation works. I found some papers and some arguments. The most interesting one was "Diamond Square algorithm" and "Midpoint Displacement". I still have to try to apply those to a software, but other than that, i ran into this site: http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/
As you can see, the idea is to use polygons. But i have no idea how to apply that a Tile-Based map, not even how to create those polygons using the tools i have (c++ and sdl). I am assuming there is no way to do it ( please correct me if i am wrong.) But if i am not, how does a non-tile map works, and how are these polygons generated?
This answer will not give you directly the answers you're looking for, but hopefully will get you close enough!
The Problem
I think what blocks you is how to represent the data. You're probably used to a 2D grid that simply represent the type of each tile. As you know, this is fine to handle a tile-based map, but doesn't properly allow you to model worlds where tiles are of a different shape.
Graphs
What I suggest to you, is to see the problem a bit differently. A grid is nothing more than a graph (more info) with nodes that have 4 (or 8 if you allow diagonals) implicit neighbor nodes. So first, what I would do if I was you, would be to move from your strict standard 2D grid to a more "loose" graph, where each node has a position, a position, a list of neighbors (in most cases you'll have corners with 2 neighbors, borders with 3 and "middle" tiles with 4) and finally a rendering component which simply draws your tile on screen at the given position. Once this is done, you should be able to have the exact same results on screen that you currently have with your "2D Tile-Based" engine by simply calling the rendering component with each node who's bounding box (didn't touch it in what you should add to your node, but I'll get back to this later) intersects with the camera's frustum (in a 2D world, it would most likely if the position +/- the size intersects the RECT currently being drawn).
Search
The more generic approach will also help you doing stuff like pathfinding with generic algorithms that explore nodes until they find a valid path (see A* or Dijkstra). Even if you decided to stick to a good old 2D Tile Map game, these techniques would still be useful!
Yeah but I want Polygons
I hear you! So, if you want polygons, basically all you need to do, is add to your nodes a list of vertices and the appropriate data that you might need to render your polygons (either vertex color, textures and U/V maps, etc...) and update your rendering component to do the appropriate OpenGL (this for example should help) calls to draw your nodes. Once again, the first step to iteratively upgrade your 2D Tile Engine to a polygon map engine would be to, for each tile in your map, give each of your nodes two triangles, a texture resource (the tile), and U/V mappings (0,0 - 0,1 - 1,0 and 1,1). Once again, when this step is done, you should have a "generic" polygon based tile map engine. The creation of most of this data can be created procedurally by calculating coordinates based on tile position, tile size, etc...
Convex Polygons
If you decide that you ever might need NPCs to navigate on your map or want to allow your player to navigate by clicking the map, I would suggest that you always use convex polygons (the triangle being the simplest for of a convex polygon). This allows your code that assume that two different positions on the same polygon can be navigated to in straight line.
Complex Maps
Based on the link you provided, you want to have rather complex maps. In this case, the author used Voronoi Diagrams to generate the polygons of the map. There are already solutions to do triangulation like that, but you might also want to use other techniques that are easier to work with if you're just switching to 3D like this one for example. Once you have interesting results, you should consider implementing serialization to save/open your map data from the game. If you want to create an editor, be aware that it might be a lot of work but can be worth it if you want people to help you creating maps or to add elements to the maps (like geometry that's not part of the terrain).
I went all over the place with this answer, but hopefully it helps!
Just iterate over all the tiles, and do a hit-test from the centre of the tile to the polys. Turn the type of the tile into the type of the polygon. Did you need more than that?
EDIT: Sorry, I realize that probably isn't helpful. Playing with procedural algorithms can be fun and profitable. Start with a loop that iterates over all tiles and chooses randomly whether or not the tile is occupied. Then, iterate over them again and choose whether it is occupied or its neighbour is.
Also, check out the source code for this: http://dustinfreeman.org/toys/wall7-dustin.html

QGis: How to import svg or raster images into Quantum GIS?

these vector or raster files being classic files without geocoordinates. They are lat/long projection, I want to import them into QGIS, scale them up/down, place them to their right place, and they become reusable shp or raster geocoordinated layers.
Edit: I'am from the wikipedia Graphic Lab>Map workshop, we want to work more using GIS. We litteraly have hundreds maps to migrate to GIS technologies....
File:Chinese_plain_5c._BC-en.svg
File:Vignobles_basse_loire.svg
Partial Solution: load SVG into Inkscape, Save as DXF file, then you can load this into QGIS. This should at least get you most of the linework into QGIS.
However, it won't yet be properly georeferenced or styled, and different layers may be in different places because the SVG has some scaling and translating operators on parts of the map data that QGIS or Inkscape is ignoring. You'll probably need to work with a layer at a time. This probably isn't a problem since maybe you are only interested in the added data on the map, and not the base map (country outlines etc) since you will probably want to overlay your data onto standard map base layer (natural earth, OpenStreetMap tiles).
The only way I see to do the transformation at present is to work out the affine transformation parameters and use the QgsAffine plugin, but that does require you to work out the parameters beforehand by fitting known source coordinates to known target coordinates.
But to do hundreds? You might be better off writing some custom SVG parsing code for each one...
If you only want to display it in the correct place, scale and rotation treat it as an SVG icon.
1. create a point layer and put a single point at the georeferenced centre of the SVG you will load.
2. edit the symbology and load the SVG as an icon
3. set the size units to map units
4. supply the appropriate dimensions
5. rotate as necessary
The redraw is very slow and painful, but if you use Project>import/Export>Export map as image you can make a georeferenced raster.

a planet in openGL: vector data or texture mapping?

I am completely new to 3D and started with Jeff Lamarche's tutorials as an introduction to openGL ES for iPhone, then so far, I am able to draw a spinning sphere, which will the base of my application.
What I want to do is render a planet Earth, thanks to 2D GIS vector data (polygones, lines or points with latitude/longitude or x/y coord).
I want to be able to turn different layers on/off and maybe able to identify an object that wold be touched.
My questions are :
would it be easier to rasterize my vector data to use them as image texture or apply the vector data onto the sphere (keeping in mind that I want to turn on/off the layers, the touch-enabled objects being optional)?
would it be easier to use a software like blender to draw the planet and add the layers rather than starting with the sphere I already have (procedural sphere)?
do the export tool from blender to opengl work well?
This kind of question is difficult to answer in general. Technically your intention sounds a lot like if you would like to write a program like Google Earth or KDE Marble. Since you're referring to GIS data you will require very high resolution. Textures only make sense for limited resolution data.
GIS applications usually work using hybrid approaches where some vector data are rendered directly (roads, waters, borders), while others are rendered to texture and the texture, or more accurately texture tiles, being used as caches, for example for building outlines in dense cities or the like. However data as it comes from say OSM can be directly rendered as vector data, since they are not very dense.

polygon to raster GIS

I have a shapefile of India with states (probably as polygons). I want to convert each polygon into equally divided cells ("raster" way), and populate (actually coloring) each cell by a value that would be calculated from an algorithm which is cell's location specific. This should be done for all the cells in the polygon (programmatically) so that at the end I have the shapefile, looking as a thematic (of what my algorithm calculates), raster image. I am not starting any image because the information is actually calculated value from algorithm and not coming from satellite imagery or anything like that.
In other words, it is not a vegetation or elevation thematic but something like population distribution, where each value (color) of cell represents a mean value of population there, showing wholly as a distribution at large scale.
Can any one please help how to do this using any open source application? (both as application and also programmatically using API like sharpmap) Please help
The GDAL utilities and scripting would be my choice.
http://www.gdal.org/index.html
I don't quite understand how you are going to decide cell values based on position, but have a look at the following utilites:
http://www.gdal.org/gdal_grid.html
http://www.gdal.org/gdal_rasterize.html
If you can't get the required output from the command line, then the GDAL functions can be scripted (C++ or Python have the most examples).
One easy way to do this would be to use Mapnik and its Python binding. See their site for a tutorial on thebasic usage and their XML configuration schema.
I've done this using MapScript (from UMN's Mapserver).
http://mapserver.org/mapscript/index.html#mapscript
It's fairly straight forward and has many bindings (PHP, Ruby, Python, .NET and so forth), but the API is the same across all bindings. Those bindings when I last used it were of varying quality and I'm not up to date on the current quality
I've done this using python and GDAL by following the instructions outlined here:
http://proj.lis.ic.unicamp.br/webmaps/docs/calc_ndvi/
I hope this helps.
ps. The site is in portugese, so if you don't speak the language you may find Google translate very useful. Good luck.
n

Resources