<?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 gdal)</title><link>https://www.grulic.org.ar/~mdione/glob/</link><description></description><atom:link href="https://www.grulic.org.ar/~mdione/glob/categories/gdal.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>Sat, 15 Nov 2025 20:52:05 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Measure your optimnizations</title><link>https://www.grulic.org.ar/~mdione/glob/posts/measure-your-optimnizations/</link><dc:creator>Marcos Dione</dc:creator><description>&lt;p&gt;One of the parts of having my own map style with hypsometric contour lines is that I
have to generate those contour lines. There's a tool in GDAL, particularly the one that
actually does everything based on DEM files, called &lt;code&gt;gdaldem&lt;/code&gt; that
can generate shapefiles with contour lines that &lt;code&gt;mapnik&lt;/code&gt; can read.
But since my source files are 1x1° files, I will have to generate one layer for
each shapefile  and that doesn't scale very well, especially
at planet size.&lt;/p&gt;
&lt;p&gt;So what I do is I convert those shapefiles to SQL files and then I inject
them into my database one by one, and then I can use &lt;code&gt;mapnik&lt;/code&gt;'s own support for filtering
by bbox when it's rendering, so that should be faster&lt;sup id="fnref:4"&gt;&lt;a class="footnote-ref" href="https://www.grulic.org.ar/~mdione/glob/posts/measure-your-optimnizations/#fn:4"&gt;4&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;I put the SQL files in my file system,
and then I import them by hand as I need them, and I'm running out of space again. A few years
ago I had a 1TB disk, and that was enough, and now I am at the 2TB disk,
and it's getting small. I have the impression that the new DEMs I am using are bigger,
even if I streamlined every layer so it uses as less space as possible.&lt;/p&gt;
&lt;p&gt;One of the things I'm doing
is converting my processing script into a &lt;code&gt;Makefile&lt;/code&gt;, so I can remove intermediary files. My process goes
from the original DEM files, that are in LatLon, I project them to WebMerkator.
This file becomes the source for the terrain files, which gives the hypsometric
tints, and I generate the contours from there, and then I do a
&lt;a href="https://www.grulic.org.ar/~mdione/glob/posts/trying-to-calculate-proper-shading/"&gt;compensation for slope shade and hill shade&lt;/a&gt;.
Notice that I get
two intermediary files that I can easily remove, which are first, the reprojected file, because
once I have the terrain and contour files, I can remove it, I don't care anymore;
and also the compensated file, I don't need it anymore once I have the shade files.
The &lt;code&gt;Makefile&lt;/code&gt; is covering that part,
once the files are generated, the intermediary files are gone.&lt;/p&gt;
&lt;p&gt;Going back to the SQL files, I don't inject SQL data directly into my database, because I don't have space for
that. So, I just generate this SQL file and I compress it, so it's not using so much space,
because SQL is really a lot of text. I've been using &lt;code&gt;xz&lt;/code&gt; as the compressor,
and I have been blindly using its highest compression level, CL 9.
What do I mean with
blindly? I noticed it actually takes a lot of time. I just measured it with one tile,
and it took 451 seconds. That's 7.5 minutes per degree tile,
which is a lot. So I asked myself, what's the compression ratio to time
spent ratio?&lt;/p&gt;
&lt;p&gt;I took a single file and I compressed it with all the compression levels
between 1 and 9, and I took the time and the space in the final file. I made a scatter graph,
and it looks like this pretty weird Z figure&lt;sup id="fnref:2"&gt;&lt;a class="footnote-ref" href="https://www.grulic.org.ar/~mdione/glob/posts/measure-your-optimnizations/#fn:2"&gt;2&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://www.grulic.org.ar/~mdione/glob/images/xz_compression_levels-time_and_sizes.png"&gt;&lt;/p&gt;
&lt;p&gt;Here's the raw data&lt;sup id="fnref:1"&gt;&lt;a class="footnote-ref" href="https://www.grulic.org.ar/~mdione/glob/posts/measure-your-optimnizations/#fn:1"&gt;1&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style="text-align: center;"&gt;level&lt;/th&gt;
&lt;th style="text-align: center;"&gt;time_in_seconds&lt;/th&gt;
&lt;th style="text-align: center;"&gt;readable_time&lt;/th&gt;
&lt;th style="text-align: right;"&gt;size_in_bytes&lt;/th&gt;
&lt;th style="text-align: center;"&gt;comp_ratio&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="text-align: center;"&gt;1&lt;/td&gt;
&lt;td style="text-align: center;"&gt;57.84&lt;/td&gt;
&lt;td style="text-align: center;"&gt;57s&lt;/td&gt;
&lt;td style="text-align: right;"&gt;129_486_376&lt;/td&gt;
&lt;td style="text-align: center;"&gt;29.21%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: center;"&gt;2&lt;/td&gt;
&lt;td style="text-align: center;"&gt;117.40&lt;/td&gt;
&lt;td style="text-align: center;"&gt;1m57s&lt;/td&gt;
&lt;td style="text-align: right;"&gt;129_993_440&lt;/td&gt;
&lt;td style="text-align: center;"&gt;29.33%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: center;"&gt;3&lt;/td&gt;
&lt;td style="text-align: center;"&gt;252.28&lt;/td&gt;
&lt;td style="text-align: center;"&gt;4m12s&lt;/td&gt;
&lt;td style="text-align: right;"&gt;130_306_780&lt;/td&gt;
&lt;td style="text-align: center;"&gt;29.40%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: center;"&gt;4&lt;/td&gt;
&lt;td style="text-align: center;"&gt;212.26&lt;/td&gt;
&lt;td style="text-align: center;"&gt;3m32s&lt;/td&gt;
&lt;td style="text-align: right;"&gt;102_359_596&lt;/td&gt;
&lt;td style="text-align: center;"&gt;23.09%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: center;"&gt;5&lt;/td&gt;
&lt;td style="text-align: center;"&gt;347.51&lt;/td&gt;
&lt;td style="text-align: center;"&gt;5m47s&lt;/td&gt;
&lt;td style="text-align: right;"&gt;98_992_464&lt;/td&gt;
&lt;td style="text-align: center;"&gt;22.33%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: center;"&gt;6&lt;/td&gt;
&lt;td style="text-align: center;"&gt;344.58&lt;/td&gt;
&lt;td style="text-align: center;"&gt;5m44s&lt;/td&gt;
&lt;td style="text-align: right;"&gt;99_114_560&lt;/td&gt;
&lt;td style="text-align: center;"&gt;22.36%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: center;"&gt;7&lt;/td&gt;
&lt;td style="text-align: center;"&gt;370.20&lt;/td&gt;
&lt;td style="text-align: center;"&gt;6m10s&lt;/td&gt;
&lt;td style="text-align: right;"&gt;99_043_096&lt;/td&gt;
&lt;td style="text-align: center;"&gt;22.34%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: center;"&gt;8&lt;/td&gt;
&lt;td style="text-align: center;"&gt;416.48&lt;/td&gt;
&lt;td style="text-align: center;"&gt;6m56s&lt;/td&gt;
&lt;td style="text-align: right;"&gt;99_005_352&lt;/td&gt;
&lt;td style="text-align: center;"&gt;22.33%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: center;"&gt;9&lt;/td&gt;
&lt;td style="text-align: center;"&gt;451.85&lt;/td&gt;
&lt;td style="text-align: center;"&gt;7m31s&lt;/td&gt;
&lt;td style="text-align: right;"&gt;99_055_552&lt;/td&gt;
&lt;td style="text-align: center;"&gt;22.35%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;I'm not going to explain the graph or table, except to point to the two obvious parts: the jump from CL 3 to 4,
where it's not only the first and only noticeable space gain, it also takes less time; and the fact that compressions
levels 1-3 and 4-9 have almost no change in space gained. So I either use CL 1 or 4. I'll go for 1, until I run out of
space again.&lt;/p&gt;
&lt;p&gt;All this to say: whenever you make an
optimization, measure all the dimensions, time, space, memory consumption,
and maybe you have other constraints like, I don't know, heat produced, stuff like that. Measure and compare.&lt;/p&gt;
&lt;div class="footnote"&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;Sorry for the ugly table style. I still don't know how to style it better. &lt;a class="footnote-backref" href="https://www.grulic.org.ar/~mdione/glob/posts/measure-your-optimnizations/#fnref:1" title="Jump back to footnote 1 in the text"&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:2"&gt;
&lt;p&gt;Sorry for the horrible scales. Either I don't know it enough, or LibreOffice is quite limited on how to format the
  axises&lt;sup id="fnref:3"&gt;&lt;a class="footnote-ref" href="https://www.grulic.org.ar/~mdione/glob/posts/measure-your-optimnizations/#fn:3"&gt;3&lt;/a&gt;&lt;/sup&gt;. &lt;a class="footnote-backref" href="https://www.grulic.org.ar/~mdione/glob/posts/measure-your-optimnizations/#fnref:2" title="Jump back to footnote 2 in the text"&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:3"&gt;
&lt;p&gt;No, I won't bother to see how the plural is made, this is taking me long enough already :-P &lt;a class="footnote-backref" href="https://www.grulic.org.ar/~mdione/glob/posts/measure-your-optimnizations/#fnref:3" title="Jump back to footnote 3 in the text"&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:4"&gt;
&lt;p&gt;This claim has not been proven and it's not in the scope of this post. &lt;a class="footnote-backref" href="https://www.grulic.org.ar/~mdione/glob/posts/measure-your-optimnizations/#fnref:4" title="Jump back to footnote 4 in the text"&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</description><category>compression</category><category>contours</category><category>dem</category><category>gdal</category><category>mapnik</category><category>optimization</category><category>shapefiles</category><category>shp2pgsql</category><category>xz</category><guid>https://www.grulic.org.ar/~mdione/glob/posts/measure-your-optimnizations/</guid><pubDate>Tue, 20 Aug 2024 13:53:57 GMT</pubDate></item><item><title>Automating blender based hillshading with Python</title><link>https://www.grulic.org.ar/~mdione/glob/posts/automating-blender-based-hillshading-with-python/</link><dc:creator>Marcos Dione</dc:creator><description>&lt;p&gt;Remember my &lt;a href="http://www.grulic.org.ar/~mdione/glob/posts/blender-hillshading-and-mapnik/"&gt;Blend based hillshading&lt;/a&gt;? I
promised to try to automate it, right? Well, it seems I have the interest and stamina now, so that's what I'm doing.
But boys and girls and anything in between and beyond, the stamina is waning and the culprit is Blender's internals
being exposed into a non-Pythonic API&lt;sup id="fnref:3"&gt;&lt;a class="footnote-ref" href="https://www.grulic.org.ar/~mdione/glob/posts/automating-blender-based-hillshading-with-python/#fn:3"&gt;3&lt;/a&gt;&lt;/sup&gt;. I swear if I worked in anything remotely close to this, I would be writing a
wrapper for all this. But in the meantime, it's all a discovery path to something that does not resemble a
hack. Just read some of
&lt;a href="https://docs.blender.org/api/current/info_quickstart.html#data-creation-removal"&gt;Blender's Python Quickstart&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When you are familiar with other Python APIs you may be surprised that new data-blocks in the bpy API cannot be
created by calling the class:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nx"&gt;bpy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Mesh&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nx"&gt;Traceback&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;most&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;recent&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;last&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="nx"&gt;File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;blender_console&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;line&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nx"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;bpy_struct&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;__new__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;expected&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;single&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;argument&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;This is an intentional part of the API design. The Blender Python API can’t create Blender data that exists outside
the main Blender database (accessed through bpy.data), because this data is managed by Blender (save, load, undo,
append, etc).&lt;/p&gt;
&lt;p&gt;Data is added and removed via methods on the collections in bpy.data, e.g:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;mesh = bpy.data.meshes.new(name="MyMesh")
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;That is, instead of making the constructor call this internal API, they make it fail miserably and force you to use the
internal API! Today I was mentioning that Asterisk's programming language was definitely designed by a
Telecommunications Engineer, so I guess this one was designed by a 3D artist? But I digress...&lt;/p&gt;
&lt;p&gt;One of the first thing about Blender's internals is that one way to work is based on Contexts. This makes sense when
developing plugins, where you mostly need to apply things to the
selected object, but for someone really building everything from scratch like I need to, it feels weird.&lt;/p&gt;
&lt;p&gt;One of the advantages is that you can open a Python console and let Blender show you the calls it makes for every step
you make on the UI, but it's so context based that the results is useless as a script. Or for instance, linking the
output of a thing into he the input of another is registered as a drag-and-drop call that includes the distance the
mouse moved during the drag, so it's relative of the output dot where you started and what it links to also depends on
the physical and not logical position of the things you're linking,&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;bpy.ops.node.link(detach=False, drag_start=(583.898, 257.74))
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;It takes quite a lot of digging around in a not very friendly REPL&lt;sup id="fnref:1"&gt;&lt;a class="footnote-ref" href="https://www.grulic.org.ar/~mdione/glob/posts/automating-blender-based-hillshading-with-python/#fn:1"&gt;1&lt;/a&gt;&lt;/sup&gt; with limited scrollback and
not much documentation to find more reproducible, less context dependent alternatives. This is what's eating up my
stamina, it's not so fun anymore. Paraphrasing someone on Mastodon: What use is a nice piece of Open Software if it's
documentation is not enough to be useful&lt;sup id="fnref:2"&gt;&lt;a class="footnote-ref" href="https://www.grulic.org.ar/~mdione/glob/posts/automating-blender-based-hillshading-with-python/#fn:2"&gt;2&lt;/a&gt;&lt;/sup&gt;?&lt;/p&gt;
&lt;p&gt;Another very important thing is that all objects have two views: one that has generic properties like position and
rotation, which can be reacheched by &lt;code&gt;bpy.data.objects&lt;/code&gt;; and one that has specific properties like a light's power or a
camera's lens angle, which can be reached by f.i. &lt;code&gt;bpy.data.cameras&lt;/code&gt;. This was utterly confusing, specially since
all &lt;code&gt;bpy.data&lt;/code&gt;'s documentation is &lt;strong&gt;4 lines long&lt;/strong&gt;. Later I found out you can get specific data from the generic one in
the &lt;code&gt;.data&lt;/code&gt; attribute, so the take out is: &lt;strong&gt;always get your objects from &lt;code&gt;bpy.data.objects&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Once we get over that issue, things are quite straightforward, but not necessarily easy. The script as it is can already
be used with &lt;code&gt;blender --background --python &amp;lt;script_file&amp;gt;&lt;/code&gt;, but have in account that when you do that, you start with
the default generic 3D setup, with a light, a camera and a cube. You have to delete the cube, but you can get a
reference to the other two to reuse them.&lt;/p&gt;
&lt;p&gt;Then comes the administrative stuff around just rendering the scene. To industrialize it and be able to quickly test
stuff, you can try to get command line options. You can use Python's &lt;code&gt;argparser&lt;/code&gt; module for this, but have in account
that those &lt;code&gt;--background --python blender.py&lt;/code&gt; options are going to be passed to the script, so you either ignore unknown
options or you declare those too:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="n"&gt;mdione&lt;/span&gt;&lt;span class="nv"&gt;@ioniq&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="o"&gt;~/&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;projects&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;elevation&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;blender&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;background&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;python&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;blender&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;
&lt;span class="n"&gt;Blender&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;3.6.2&lt;/span&gt;
&lt;span class="k"&gt;Read&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;prefs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;"/home/mdione/.config/blender/3.6/config/userpref.blend"&lt;/span&gt;
&lt;span class="k"&gt;usage&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;blender&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;-h&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;--render-samples RENDER_SAMPLES&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;--render-scale RENDER_SCALE&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;--height-scale HEIGHT_SCALE&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;FILE&lt;/span&gt;
&lt;span class="nl"&gt;blender&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;unrecognized&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;--background --python&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Also, those options are going to be passed to Blender! So at the end of your run, Blender is going to complain that it
doesn't understand your options:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="n"&gt;unknown&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;argument&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;loading&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;render&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;samples&lt;/span&gt;
&lt;span class="n"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Cannot&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/home/mdione/src/projects/elevation/--render-samples"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;No&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;such&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ow"&gt;or&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;directory&lt;/span&gt;
&lt;span class="n"&gt;Blender&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;quit&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The other step you should do is to copy the Geo part of GeoTIFF to the output file. I used &lt;code&gt;rasterio&lt;/code&gt;, mostly because at
first I tried &lt;code&gt;gdal&lt;/code&gt; (I was already using &lt;code&gt;gdal_edit.py&lt;/code&gt; to do this in my previous manual procedure), but it's API was
quite confusing and &lt;code&gt;rasterio&lt;/code&gt;'s is more plain. But, &lt;code&gt;rasterio&lt;/code&gt; can't actually open a file just to write the metadata
like &lt;code&gt;gdal&lt;/code&gt; does, so I had to open the output file, read all data, open it again for writing (this truncates the file)
and write metadata and data.&lt;/p&gt;
&lt;p&gt;Now, some caveats. First, as I advanced in my last post, the method as it is right now has issues at the seams. Blender
can't read GDAL VRT files, so either I build 9 planes instead of 1 (&lt;strong&gt;all&lt;/strong&gt; the neighbors are needed to properly
calculate the shadows because Blender is also taking in account light reflected back from other features, meaning
mountains) or for each 1x1 tile I generate another with some buffer. I will try the first one and see if it fixes this
issue without much runtime impact.&lt;/p&gt;
&lt;p&gt;Second, the script is not 100% parametrized. Sun size and power are fixed based on my tests. Maybe in the future. Third,
I will try to add a scattering sky, so we get a bluish tint to the shadows, and set the Sun's color to something
yellowish. These should probably be options too.&lt;/p&gt;
&lt;p&gt;Fourth, and probably most important. I discovered that this hillshading method is really sensible to missing or bad data,
because they look like dark, deep holes. This is probably a deal breaker for many, so you either fix your data, or you
search for better data, or you live with it. I'm not sure what I'm going to do.&lt;/p&gt;
&lt;p&gt;So, what did I do with this? Well, first, find good parameters, one for render samples and another for height scale.
Render time grows mostly linearly with render samples, so I just searched for the one before detail stopped appearing;
the value I found was 120 samples.
When we left off I was using 10 instead of 5 for height scale, but it looks too exaggerated on hills (but it looks
AWESOME in mountains like the Mount Blanc/Monte Bianco! See below), so I tried to pinpoint a good balance. For me it's 8,
maybe 7.&lt;/p&gt;
&lt;p&gt;Why get these values right? Because like I mentioned before, a single 1x1°, 3601x5137px tile takes some 40m in my laptop
at 100 samples, so the more tuned the better. One nice way to quickly test is to lower the samples or use the
&lt;code&gt;--render-scale&lt;/code&gt; option of the script to reduce the size of the output. Note that because you reduce both dimensions at
the same time, the final render (and the time that takes) is actually the square of this factor: 50% is actually 25%
(because 0.50 * 0.50 = 0.25).&lt;/p&gt;
&lt;p&gt;So, without further addo, here's my script. If you find it useful but want more power, open issues or PRs, everything
is welcome.&lt;/p&gt;
&lt;p&gt;https://github.com/StyXman/blender_hilllshading &lt;sup id="fnref:5"&gt;&lt;a class="footnote-ref" href="https://www.grulic.org.ar/~mdione/glob/posts/automating-blender-based-hillshading-with-python/#fn:5"&gt;5&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;Try to use the &lt;code&gt;main&lt;/code&gt; branch; &lt;code&gt;develop&lt;/code&gt; is considered unstable and can be broken.&lt;/p&gt;
&lt;p&gt;A couple of images of the shadows applied to my style as teaser, both using only 20 samples and x10 height scale:&lt;/p&gt;
&lt;p&gt;Dhaulagiri:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://www.grulic.org.ar/~mdione/glob/images/Dhaulagiri.jpg"&gt;&lt;/p&gt;
&lt;p&gt;Mont Blanc/Monte Bianco:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://www.grulic.org.ar/~mdione/glob/images/Mont_Blanc-Monte_Bianco.jpg"&gt;&lt;/p&gt;
&lt;p&gt;Man, I love the fact that the tail of the Giacchiaio del Miage is in shadows, but the rest is not; or how
Monte Bianco/Mont Blanc's shadow reaches across the valley to the base of la Tête d'Arp. But also notice the bad data
close to la Mer de Glace.&lt;/p&gt;
&lt;div class="footnote"&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;Ok, TBH here, I'm very much used to &lt;code&gt;ipython&lt;/code&gt;'s console, it's really closer to the plain &lt;code&gt;python&lt;/code&gt; one. No tab
completion, so lots of calls to &lt;code&gt;dir()&lt;/code&gt; and a few &lt;code&gt;help()&lt;/code&gt;s. &lt;a class="footnote-backref" href="https://www.grulic.org.ar/~mdione/glob/posts/automating-blender-based-hillshading-with-python/#fnref:1" title="Jump back to footnote 1 in the text"&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:2"&gt;
&lt;p&gt;I couldn't find it again. Mastodon posts are not searchable by default, which I understand is good for privacy, but
on the other hand the current clients don't store anything locally, so you can't even search what you already saw.
I have several semi-ranting posts about this and I would show them to you, but they got lost on Mastodon. See what I
mean? &lt;a class="footnote-backref" href="https://www.grulic.org.ar/~mdione/glob/posts/automating-blender-based-hillshading-with-python/#fnref:2" title="Jump back to footnote 2 in the text"&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:3"&gt;
&lt;p&gt;So you have an idea, this took me a whole week of free time to finish, including but not in the text, my old nemesis,
terracing effect. This thing is &lt;strong&gt;brittle&lt;/strong&gt;. &lt;a class="footnote-backref" href="https://www.grulic.org.ar/~mdione/glob/posts/automating-blender-based-hillshading-with-python/#fnref:3" title="Jump back to footnote 3 in the text"&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:4"&gt;
&lt;p&gt;Yeah, maybe the API is mostly designed for this. &lt;a class="footnote-backref" href="https://www.grulic.org.ar/~mdione/glob/posts/automating-blender-based-hillshading-with-python/#fnref:4" title="Jump back to footnote 4 in the text"&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:5"&gt;
&lt;p&gt;My site generator keeps breaking. This is the second time I have to publicly admit this. Maybe next weekend I'll
gather steam and replace it with &lt;code&gt;nikola&lt;/code&gt;. &lt;a class="footnote-backref" href="https://www.grulic.org.ar/~mdione/glob/posts/automating-blender-based-hillshading-with-python/#fnref:5" title="Jump back to footnote 5 in the text"&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</description><category>blender</category><category>dem</category><category>elevation</category><category>gdal</category><category>gis</category><category>hillshading</category><category>openstreetmap</category><category>python</category><category>rasterio</category><guid>https://www.grulic.org.ar/~mdione/glob/posts/automating-blender-based-hillshading-with-python/</guid><pubDate>Sun, 05 Nov 2023 16:19:45 GMT</pubDate></item></channel></rss>