<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>.:: Marcos Dione/StyXman's glob ::. (Posts about srtm)</title><link>https://www.grulic.org.ar/~mdione/glob/</link><description></description><atom:link href="https://www.grulic.org.ar/~mdione/glob/categories/srtm.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2025 &lt;a href="mailto:mdione@grulic.org.ar"&gt;Marcos Dione&lt;/a&gt; </copyright><lastBuildDate>Thu, 29 May 2025 15:41:12 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Towards the perfect map pt 0.5</title><link>https://www.grulic.org.ar/~mdione/glob/posts/towards-the-perfect-map-pt-05/</link><dc:creator>Marcos Dione</dc:creator><description>&lt;p&gt;So it's been a long while that I talked about my quest towards the perfect map
for in-car navigation and general orientation. This post is to fix that.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.grulic.org.ar/~mdione/glob/posts/marble-osm-and-monav-as-in-car-navigation-for-maemo/"&gt;I started with marble, monav and
OSM tiles&lt;/a&gt;.
The tiles proved inefficient for in-car navigation because of the
non-contrasting palette, which makes differentiating ways from blocks very
difficult in the sunlight. &lt;a href="https://www.grulic.org.ar/~mdione/glob/posts/marble-using-cloudmade-tiles-with-hillshading/"&gt;Then I switched to creating maps with
CloudMade&lt;/a&gt;, which
at the beginning seemed enough, but then I noticed that the solution was not
complete, as it lacked some features (in OSM terms) that couldn't be mapped.
When I started to look for alternatives, I found a site that showed
&lt;a href="https://www.grulic.org.ar/~mdione/glob/posts/building-tilesets-with-tilemill/"&gt;TileMill&lt;/a&gt;,
which &lt;a href="https://www.grulic.org.ar/~mdione/glob/posts/building-tilesets-with-tilemill-and-osm-data/"&gt;can use OSM data&lt;/a&gt; from a database, and
specially &lt;a href="http://mapbox.com/tilemill/docs/guides/terrain-data/"&gt;its ability to create relief maps, with altitude coloring, slope and
hillshading&lt;/a&gt;. I was doomed :)&lt;/p&gt;
&lt;p&gt;I started exploring the relief part. relief data is available from several
sources, the most prominent being the ones derived from the &lt;a href="http://en.wikipedia.org/wiki/Shuttle_Radar_Topography_Mission"&gt;Shuttle Radar
Topography Mission&lt;/a&gt;,
like &lt;a href="http://www.cgiar-csi.org/data/srtm-90m-digital-elevation-database-v4-1"&gt;CGIAR-CSI&lt;/a&gt; or
&lt;a href="http://www.viewfinderpanoramas.org/dem3.html"&gt;Jonathan de Ferranti&lt;/a&gt;. Discussing
with a friend, he told me to stick to the first ones, as de Ferranti's data has been
smoothed by hand and is not always the best. Also, his several sources have
incompatible licenses, so it should be unusable. With this data I also generated
contour lines, which you will recognize from topographic maps.&lt;/p&gt;
&lt;p&gt;The next step is how to use OSM data. I started using &lt;a href="http://download.geofabrik.de/"&gt;GeoFabrik's
extracts&lt;/a&gt;,
first importing the data into a database, but this takes a lot of time, memory
and disk space. I switched to the shapefiles, but this introduced several problems.
First, the sum of the data contained in the several shapefiles for a region
(landuse, natural, places, points, railways, roads and waterways) are not the
entire set of data; for instance, all data related to ski lifts is not there.
I wanted those. So I reluctantly reverted to importing the data in a database.&lt;/p&gt;
&lt;p&gt;Then there's the problem of rendering a usable map. Both TileMill and OSM render
the tiles using Mapnik, which implements the so called Painter's algorithm: you
define layers and they're 'painted' from bottom up, one on top of the other.
So, what do you put in a layer? You define a data source, which is a select in
the database, and you link it to a style. A style defines several rules, which
can provide extra filters (which technically you could do
in the database, but simplifies the data source definitions), min and/or max
scales (related to zoom levels) and how to paint them: fill a polygon, draw a
line, put a symbol, write some text, etc.&lt;/p&gt;
&lt;p&gt;Clearly, just like that, the complexity is big. Defining if a feature appears
in a zoom level or not and how, specially if it changes between zoom levels,
is quite complex. Then you have more factors: putting borders to a line is
actually implemented as drawing two lines, one thicker, defining the borders,
and then a thinner one on top of it, defining the inner part, done in two
different layers. This is called
casing. Also, think that you have to change the casing and the fill color when
there is a tunnel or add an extra casing (layer) for a bridge, and even when there are
several bridges on top of each other (think of complex highway junctions; implementet with more layers)! TileMill
proved to be good for testing, but this level of nitpicking was too much for it.&lt;/p&gt;
&lt;p&gt;For a while I flirted with the idea of generating the Mapnik input file with a
structural description of what I wanted, but I aborted it before it became a monster.
I learned something from Frankenstein!&lt;/p&gt;
&lt;p&gt;So, why not come full circle and take a look at how the &lt;a href="http://wiki.openstreetmap.org/wiki/Mapnik"&gt;OSM tiles are
generated&lt;/a&gt;?
This was definitely the right move. Instead of trying to mimic the complex set of
rules and layers that make OSM tiles perfect, just edit the xml files to take out
uninteresting data, modify some zoom levels here and there to make some things
appear sooner (I'm very interested in gas stations, hospitals, parkings,
archaeological sites and viewpoints), and edit the colors. I can even export
what I have done in TileMill to a Mapnik project, extract the part where a define
the relief layers and add them as the background.&lt;/p&gt;
&lt;p&gt;So the final setup is as following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use elevation information from CGIAR-CSI, process them as TileMill says.&lt;/li&gt;
&lt;li&gt;Use Geofabrik's &lt;code&gt;pbf&lt;/code&gt; extracts; import them in a PostGis Database as per &lt;a href="http://wiki.openstreetmap.org/wiki/Mapnik#Populate_the_PostGIS_Database"&gt;this
  page in OSM's wiki&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Use TileMill for initial designing, specially about color changes.&lt;/li&gt;
&lt;li&gt;Modify osm.xml by hand, picking out what's not wanted, changing zoom levels for some stuff.&lt;/li&gt;
&lt;li&gt;Use a script to extract colors and line widths from osm.xml; use the colors designed with TileMill.&lt;/li&gt;
&lt;li&gt;Use a modified version of generate_tiles.py to render big areas or special cities.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I almost have it finished with the scripts that allows me to iterate over the
last two steps without much hand intervention (except tweaking the values, of
course). When I'm done I'll publish it, then clean it up, then republish :)&lt;/p&gt;</description><category>gis</category><category>openstreetmap</category><category>srtm</category><guid>https://www.grulic.org.ar/~mdione/glob/posts/towards-the-perfect-map-pt-05/</guid><pubDate>Thu, 30 Apr 2015 14:03:22 GMT</pubDate></item><item><title>Processing huge DEM datasets</title><link>https://www.grulic.org.ar/~mdione/glob/posts/processing-huge-DEM-datasets/</link><dc:creator>Marcos Dione</dc:creator><description>&lt;p&gt;As I mentioned in one of my lasts posts about it, I started using SRTM 1 arc
data for rendering my maps. So far, with the 3 arc dataset, I was able to
generate a huge image by stitching the tiles with &lt;code&gt;gdal_merge.py&lt;/code&gt;, then
generating the 3 final images (height, slope and hill shade) plus one
intermediary for the slope, all with &lt;code&gt;gdaldem&lt;/code&gt;. Now this is no longer
possible, as the new dataset is almost 10x the old one, so instead of going that
way, I decided to try another one.&lt;/p&gt;
&lt;p&gt;With &lt;code&gt;gdalbuildvrt&lt;/code&gt; it is possible to generate an XML file that 'virtually'
stitches images. This means that any attempt to access data through this file
will actually make the library (&lt;code&gt;libgdal&lt;/code&gt;) to find the proper tile(s) and access
them directly.&lt;/p&gt;
&lt;p&gt;So now the problem becomes processing each tile individually and then virtual
stitching them. The first part is easy, as I just need to do the same I was
doing to the huge stitched image before. I also took the opportunity to use
tiled files, which instead of storing the image one scan line at a time (being
1 arc second resolution, each scan line has 3601 pixels; the extra one is for
overlapping with the neighbors), it stores the file in 256x256 sub-tiles, possibly
(that is, no tested) making rendering faster by clustering related data closer.
The second step, with &lt;code&gt;gdalbuildvrt&lt;/code&gt;, should also be easy.&lt;/p&gt;
&lt;p&gt;The first block on the way is the fact that SRTM tiles above 50°N are only 1801
pixels wide, most posibly because it makes no sense anyways. This meant that I
had to preprocess the original tiles so &lt;code&gt;libgdal&lt;/code&gt; didn't have to do the
interpolation at render time (in fact, it already has to do it once while
rendering, using the &lt;code&gt;lanczos&lt;/code&gt; scaling algorithm). This was done with &lt;code&gt;gdalwarp&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The second one came from slope and hill shading tiles. As the algortihm goes, it
generates some 'fade out' values in the edges, and when &lt;code&gt;libgdal&lt;/code&gt; was stitching
them, I could see it as a line in the seam. This was fixed by passing
&lt;code&gt;-compute_edges&lt;/code&gt; to &lt;code&gt;gdaldem&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Finally, for some reason &lt;code&gt;gdalbuildvrt&lt;/code&gt; was generating some very strange &lt;code&gt;.vrt&lt;/code&gt;
files. The format of these files is more or less the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For each band in the source tiles it creates a band in the result.&lt;ul&gt;
&lt;li&gt;For each source tile, it describes:&lt;ul&gt;
&lt;li&gt;The source file&lt;/li&gt;
&lt;li&gt;The source band&lt;/li&gt;
&lt;li&gt;The size and tiling of the source (3601², 256²)&lt;/li&gt;
&lt;li&gt;The rectangle we want from the source (0², 3601²)&lt;/li&gt;
&lt;li&gt;The rectangle in the result (x, y, 3601²)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The problem I saw was some weird declararions of the rectangles in the result,
where the coordinates or the sizes didn't match what I expected.
I will try to figure this out with the GDAL poeple in the following weeks, but
first I want to make sure that the source tiles are easily downloadable (so far
I have only found download options through
&lt;a href="http://earthexplorer.usgs.gov"&gt;USGS' EarthExplorer&lt;/a&gt;, which requires you to be
logged in in order to download tiles, which means that it is not very
scriptable, so not very reproducible).&lt;/p&gt;
&lt;p&gt;So for the moment I'm using my own &lt;code&gt;.vrt&lt;/code&gt; file generator, completely not generic
enough for release, but soon. I also took the opportunity to make the rectangles
in the result non-overlapping, being just 3600² in size. I know that the
generated file works because I'm also generating smaller samples of the
resulting layers (again, height, slope and hill shading) for rendering smaller
zoom levels.&lt;/p&gt;
&lt;p&gt;The only remaining question about huge DEM datasets is contour generation. So
far I had just generated contour lines for each tile and lived with the fact
that they too look ugly at the seams.&lt;/p&gt;</description><category>gdal</category><category>gis</category><category>srtm</category><guid>https://www.grulic.org.ar/~mdione/glob/posts/processing-huge-DEM-datasets/</guid><pubDate>Thu, 30 Apr 2015 13:03:22 GMT</pubDate></item></channel></rss>