Using libosmium to generate a pixel-art tilemap of a location?

Hello.

I am planning to use OSM data for a little project of mine.

The user inputs two sets of coordinates that describe a rectangle on Earths surface. Then he sets a tile-size, so for example tiles are 2m by 2m.

Then, my program generates a set of points to check for in that rectangle. Each point corresponds to one tile.

I am assuming that the rectangle is so small, that Earths curvature does not distort the tile’s size too much.

Then, I check what is at that point. Is it a road, a forest, house, field etc.; and depending on that I assign a certain graphic/value/whatever in the corresponding tile to that point.

Essentially, distribute points in that rectangle the user provides, check what each point is on, and set the corresponding tile to a proper value.

The result should be an approximation of that location in pixel-art graphics.

Now, the only thing I need to know, and I could not figure it out from the documentation or feature list, is can libosmium check what multi-polygon (house, forest, lake) or way (roads) is near/on a point given by longitude or latitude.

I am new to working with maps using programs, so I am unsure if this is the best way to do what I want. I would want to use OSM, since I think it is the easiest way to keep all of my data on my machine. I do not want to use API calls to any online service.

Essentialy, I want to make a program that when given OSM database, spits out that pixel-art. All localy.

Alternatively, if you are aware of any tool that would help me in doing this project, I’ll gladly take a look at it, but I need it do be available with c++.

Thanks, Hubert.

Libosmium doesn’t have the functions to find something near a point or so. So libosmium could be part of a solution part but you’d need a lot more stuff to build around it.

But: What you are describing is basically what a map renderer does. Turn OSM data into pixels. There is plenty of software out there that does exactly that. Only usually with much higher resolution. But in theory I don’t see why you can’t use a software like Mapnik or so to render low-resolution “pixel art” maps. Usually rendering software has a “DPI” setting or so. Find that and change it and experiment.

3 Likes

Hi Hubert,

Welcome to OpenStreetMap!

GeoDesk may be a possible solution. You can issue spatial queries against a geographic object library (a compact database containing OSM features) and obtain the various features at or near a given location.

For example, to gather all water areas at a specific coordinate:

    Features world("/path/to/your/gol");
    Features water = world("a[natural=water]");
    Coordinate myLocation = Coordinate::ofLonLat(-0.16535,51.50484);
    for(Feature feature: water(myLocation))
    {
        ...
    }

The above should return the Serpentine in London’s Hyde Park.

You can download OpenStreetMap data from planet.openstreetmap.org, but you may wish to start out with regional extracts, such as those provided by Geofabrik.

OSM datasets are typically provided as .osm.pbf files (A format that is extremely compact due to tight compression, but does not support random-access queries). Using the GeoDesk GOL Tool you can turn these .osm.pbf files into a GOL (a single-file database with indexes for fast queries). Prior to creating a GOL, you can also use the Osmium tool (a command-line utility built on libosmium) to combine multiple .osm.pbf files or perform other pre-processing.

The entire GeoDesk toolkit is free & open-source. The C++ version is relatively new (released last November), so there aren’t as many examples yet as there are for the Java and Python kits – but feel free to post any questions on this forum or on GitHub if you need help with specific use cases.

1 Like

Thank you for your reply!
I am very new to dealing with maps in programs, so I did not know that I need to search for something like “map renderer”.
Ill take a look, thanks!

This looks like it could do the trick. Thank you!

Your project sounds a bit like OpenLandcoverMap and Mapscii.

Both are open source, so you could check how they do it?

1 Like