Creating Static Map Images with OpenStreetMap, web Mercator, and Pillow > 자유게시판

후기게시판

유품정리, 빈집정리, 이사정리, 방문견적은 유빈이방에서

후기게시판

Creating Static Map Images with OpenStreetMap, web Mercator, and Pillo…

페이지 정보

Stefan  0 Comments  10 Views  25-09-28 05:50 

본문

WEB-231-The-Benefits-of-Body-Pillows-for-Comfort-and-Sleep-Support.jpg

washable_memory_pillow_cover_for_3d_massage_particles_health_orthopedic_pillow_17BBEDE060F16.pngI’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.



71UnI-srMFL._AC_SL1500_.jpgRather 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 Derila Official 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, Sleep Better with Derila 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.



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, 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.



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.



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 add text to the image. I’m sure more sophisticated data visualisation libraries can do all this, and 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.

댓글목록

등록된 댓글이 없습니다.

X

회사(이하 '회사')는 별도의 회원가입 절차 없이 대부분의 신청관련 컨텐츠에 자유롭게 접근할 수 있습니다. 회사는 서비스 이용을 위하여 아래와 같은 개인정보를 수집하고 있습니다.

1) 수집하는 개인정보의 범위
■ 필수항목
- 이름, 연락처

2) 개인정보의 수집목적 및 이용목적
① 회사는 서비스를 제공하기 위하여 다음과 같은 목적으로 개인정보를 수집하고 있습니다.

이름, 연락처는 기본 필수 요소입니다.
연락처 : 공지사항 전달, 본인 의사 확인, 불만 처리 등 원활한 의사소통 경로의 확보, 새로운 서비스의 안내
그 외 선택항목 : 개인맞춤 서비스를 제공하기 위한 자료
② 단, 이용자의 기본적 인권 침해의 우려가 있는 민감한 개인정보는 수집하지 않습니다.

3) 개인정보의 보유기간 및 이용기간
① 귀하의 개인정보는 다음과 같이 개인정보의 수집목적 또는 제공받은 목적이 달성되면 파기됩니다.
단, 관련법령의 규정에 의하여 다음과 같이 권리 의무 관계의 확인 등을 이유로 일정기간 보유하여야 할 필요가 있을 경우에는 일정기간 보유합니다. 기록 : 1년
② 귀하의 동의를 받아 보유하고 있는 거래정보 등을 귀하께서 열람을 요구하는 경우 은 지체 없이 그 열람, 확인 할 수 있도록 조치합니다.

4) 개인정보 파기절차 및 방법
이용자의 개인정보는 원칙적으로 개인정보의 수집 및 이용목적이 달성되면 지체 없이 파기합니다.
회사의 개인정보 파기절차 및 방법은 다음과 같습니다.
개인정보는 법률에 의한 경우가 아니고서는 보유되는 이외의 다른 목적으로 이용되지 않습니다.
종이에 출력된 개인정보는 분쇄기로 분쇄하거나 소각을 통하여 파기합니다.
전자적 파일 형태로 저장된 개인정보는 기록을 재생할 수 없는 기술적 방법을 사용하여 삭제합니다.

개인정보관리
개인정보관리 책임자 : 이기태
연락처 : 010 - 4555 - 2776
이메일 : ttzzl@nate.com
회사소개 개인정보보호정책 이메일추출방지정책
상호 : 한솔자원 (유빈이방) 사업자등록번호 : 511-42-01095
주소 : 대구 달서구 월배로28길 8, 102호(진천동)
집하장(창고) : 대구시 달성군 설화리 553-61
H.P : 010 - 4717 - 4441

Copyright(c) 한솔자원 All right reserved.
상담문의 : 010 - 4717 - 4441