Anónimo
No estás accedido
Discusión
Contribuciones
Crear una cuenta
Acceder
Wiki-AUER
Buscar
Edición de «
Creating Static Map Images With OpenStreetMap Web Mercator And Pillow
»
De Wiki-AUER
Espacios de nombres
Página
Discusión
Más
Más
Acciones de página
Leer
Editar
Editar código
Historial
Advertencia:
no has iniciado sesión. Tu dirección IP se hará pública si haces cualquier edición. Si
inicias sesión
o
creas una cuenta
, tus ediciones se atribuirán a tu nombre de usuario, además de otros beneficios.
Comprobación antispam. ¡
No
rellenes esto!
<br>I’ve been working on a project where I need to plot points on a map. I don’t need an interactive or dynamic visualisation - just a static map with coloured dots for each coordinate. I’ve created maps on the web using Leaflet.js, which load map data from OpenStreetMap (OSM) and support zooming and panning - but for this project, I want a standalone image rather than something I embed in a web page. I want to put in coordinates, and get a PNG image back. This feels like it should be straightforward. There are lots of Python libraries for data visualisation, but it’s not an area I’ve ever explored in detail. I don’t know how to use these libraries, and despite trying I couldn’t work out how to accomplish this seemingly simple task. I made several attempts with libraries like matplotlib and plotly, but I felt like I was fighting the tools.<br><br><br><br>Rather than persist, I wrote my own solution with "lower level" tools. The key was a page on the OpenStreetMap wiki explaining how to convert lat/lon coordinates into the pixel system used by OSM tiles. Let’s go through those steps. Let’s talk about how OpenStreetMap works, and in particular their image tiles. If you start at the most zoomed-out level, OSM represents the entire world with a single 256×256 pixel square. This is the Web Mercator projection, and you don’t get much detail - just a rough outline of the world. We can zoom in, and this tile splits into four new tiles of the same size. There are twice as many pixels along each edge, and each tile has more detail. Notice that country boundaries are visible now, but we can’t see any names yet. We can zoom in even further, and each of these tiles split again. There still aren’t any text labels, but the map is getting more detailed and we can see small features that weren’t visible before.<br><br><br><br>You get the idea - we could keep zooming, and we’d get more and more tiles, each with more detail. This tile system means you can get detailed information for a specific area, without loading the entire world. For example, if I’m looking at street information in Britain, I only need the detailed tiles for that part of the world. I don’t need the detailed tiles for Bolivia at the same time. OpenStreetMap will only give you 256×256 pixels at a time, but we can download every tile and stitch them together, one-by-one. The higher the zoom level, the more tiles you need to download, and the larger the final image will be. I can just about open that zoom level 6 image on my computer, but it’s struggling. I didn’t try opening zoom level 7 - that includes 16,384 tiles, Derila Neck Support and I’d probably run out of memory. For most static images, zoom level 3 or 4 should be sufficient - I ended up a base map from zoom level 4 for my project.<br>[https://www.cleanlink.com/hs/article/Understanding-Microfiber-Technology--3970 cleanlink.com]<br><br><br>It takes a minute or so to download all the tiles from OpenStreetMap, but you only need to request it once, and then you have a static image you can use again and again. This is a particularly good approach if you want to draw a lot of maps. OpenStreetMap is provided for free, and we want to be a respectful user of the service. Downloading all the map tiles once is more efficient than making repeated requests for the same data. Now we have an image with a map of the whole world, we need to overlay our lat/lon coordinates as points on this map. I found instructions on the OpenStreetMap wiki which explain how to convert GPS coordinates into a position on the unit square, which we can in turn add to our map. Their documentation includes a worked example using the coordinates of the Hachiko Statue. Most users of OpenStreetMap tiles will use these unit positions to select the tiles they need, and then dowload those images - but we can also position these points directly on the global map.<br><br><br><br>I wrote some more Pillow code that converts GPS coordinates to these unit positions, scales those unit positions to the size of the entire map, then draws a coloured circle at each point on the map. The nice thing about writing this code in Pillow is that it’s a library I already know how to use, and so I can customise it if I need to. I can change the shape and colour of the points, or crop to specific regions, or [http://www.career4.co.kr/bbs/board.php?bo_table=ci_consulting&wr_id=59397 side sleeper relief] add text to the image. I’m sure more sophisticated data visualisation libraries can do all this, and Derila Sleep Aid more - but I wouldn’t know how. The downside is that if I need more advanced features, I’ll have to write them myself. I’m okay with that - trading sophistication for simplicity. I didn’t need to learn a complex visualization library - I was able to write code I can read and understand. In a world full of AI-generating code, writing something I know I understand feels more important than ever.<br>
Resumen:
Ten en cuenta que todas las contribuciones a Wiki-AUER pueden ser editadas, modificadas o eliminadas por otros colaboradores. Si no deseas que las modifiquen sin limitaciones, no las publiques aquí.
Al mismo tiempo, asumimos que eres el autor de lo que escribiste, o lo copiaste de una fuente en el dominio público o con licencia libre (véase
Wiki-AUER:Derechos de autor
para más detalles).
¡No uses textos con copyright sin permiso!
Cancelar
Ayuda de edición
(se abre en una ventana nueva)
Navegación
Navegación
Página principal
Cambios recientes
Página aleatoria
Ayuda sobre MediaWiki
Herramientas wiki
Herramientas wiki
Páginas especiales
Herramientas de página
Herramientas de página
Herramientas de página de usuario
Más
Lo que enlaza aquí
Cambios relacionados
Información de la página
Registros de página