August 6th, 2024

Writing a tile server in Python

Marcos Dione developed a custom Python tile server for OpenStreetMap data, optimizing rendering processes, managing client requests, and addressing challenges with existing frameworks to enhance efficiency and responsiveness.

Read original articleLink Icon
Writing a tile server in Python

Marcos Dione discusses his experience in developing a tile server using Python, focusing on optimizations and the challenges faced during the process. He initially created a tileset based on OpenStreetMap data and modified an existing script, "generate_tiles," to enhance its functionality, including the ability to handle multiple rendering processes and optimize rendering time by avoiding unnecessary tile generation for water areas. Dione's approach involves rendering tiles on a powerful personal computer and syncing them to a server. He prefers creating his own tile server over using existing solutions like renderd due to its limitations in tile storage and update efficiency. The server's architecture includes a master thread and rendering threads that manage tile requests and caching optimizations. Dione also explores the integration of a web frontend to handle client requests, emphasizing the need for a responsive system that can manage long rendering times without causing client timeouts. He initially experimented with frameworks like FastAPI and Flask but found them lacking in handling specific requirements, leading him to consider a custom non-blocking loop implementation. Ultimately, he aims to create a robust tile server that efficiently processes requests while managing client connections and rendering tasks.

- Marcos Dione developed a custom tile server in Python for rendering tiles from OpenStreetMap data.

- The server optimizes rendering by avoiding unnecessary tile generation for water areas and reusing cached data.

- Dione prefers individual tile storage for easier updates and offline access compared to existing solutions.

- He faced challenges with existing web frameworks and opted for a custom non-blocking loop to manage client requests.

- The server architecture includes a master thread and rendering threads to efficiently handle tile rendering and client connections.

Related

Optimizing Large-Scale OpenStreetMap Data with SQLite

Optimizing Large-Scale OpenStreetMap Data with SQLite

The article discusses optimizing large-scale OpenStreetMap data with SQLite. Converting OSMPBF to SQLite enhanced search functionalities. Indexing, full-text search, and compression improved query performance, despite some false positives.

Adventures in mapmaking: the search for grayscale tiles

Adventures in mapmaking: the search for grayscale tiles

The author shares their tileset journey, starting with Stamen Toner and transitioning to WMS TopPlusOpen gray due to cost concerns. They later repainted OpenStreetMap tiles into grayscale for desired aesthetics.

Building a World of Warcraft Server in Elixir

Building a World of Warcraft Server in Elixir

A developer documents building a World of Warcraft private server project named Thistle Tea with Elixir. Challenges included cryptography, packet handling, and optimization. Utilized MaNGOS data and Shadowburn's code. Integrated Mnesia database for management.

Building a Wow Server in Elixir

Building a Wow Server in Elixir

A developer documents building a World of Warcraft private server project, Thistle Tea, with Elixir. Challenges included cryptography, packet handling, and optimization. Utilized MaNGOS data, Shadowburn's code, and Elixir documentation. Implemented player features and database integration. Explored Elixir's benefits in MMO development.

My favorite tools and techniques for procedural gamedev

My favorite tools and techniques for procedural gamedev

Casey Primozic shares his procedural game development techniques, focusing on seamless textures, custom shaders, AI-generated textures, and volumetric effects, while exploring future applications like Constructive Solid Geometry for 3D manipulation.

Link Icon 5 comments
By @memsom - 4 months
Having used raster MBTiles a lot for offline mapping, I would truly love a generic process that could take vector MBTiles, and then create a fully rendered raster tile from that data with the given stylesheet. If anyone knows of such a cross platform library, I would really like to hear about it. I know of a few projects, but they always have very platform specific code. My use case is multiple platforms, but using the same mapping engine. Something like Skia for rendering and handing back a Skia Canvas/Image with the rendered tile would work very well. We still need "tiles" in other words, but the source would be generated on the fly and cached to reduce overhead,

Raster tiles get huge at level 12 onwards. For generic usage it is hard to take the entire planet and make it available in a way where any user can use the same file at any zoom level in any location. For me, vector would solve this in a much better way, as we have a lot more control over which features to include and what level of detail to have in specific areas to reduce the overall size of the data.

By @itissid - 4 months
This like protomaps? https://protomaps.com/
By @cyberes - 4 months
>But Flask does not give control of what happens when the client suddenly closes the connection.

It is so annoying that they don't give you a way to do this. I built an LLM inference API but am still working on how to cancel an inference job if a client cancels. I really don't want to rewrite my entire server in Twisted so I'll probably end up just building the HTTP responses like you did.

By @tinodb - 4 months
Note that titiler[0] exists, which is doing a pretty nice job.

[0] https://github.com/developmentseed/titiler