Posts

Docker containment

 To make it easier to deploy on a live server and develop on a different environment we'll dockerize our projects. If you are not familiar with Docker you best read up on it here . But to simplify Docker allow us to run everything in a virtual environment so there no complication caused running on different systems. We'll need to add a couple of files for this. starting with a requirment.txt, This file will contain all the added dependencies for python. Currently we're only adding Django but if we later use more we just simply add it here and Docker will install all of them with PIP. Our file looks like this: Django == 3.0.7 Now it time to make the Dockerfile that will setup our environment. This will setup up the working directory and install the dependencies listed in requirment.txt and looks like this: # pull official base image FROM   python : 3.8.3-alpine # set work directory WORKDIR   /usr/src/app # install dependencies RUN   pip   install   --upgrade   pip COPY   ./r

Django

We now have a basic map integration, but no backend. Seeing we already are using some python scripts and web functionality, why not use a python web framework. Our two main choices here are Flask and Django. Seeing Django does more setup automagically then Flask we will be using this. If you have never used Django I highly recommend you follow there beginner tutorial . After an afternoon you'll understand be done with it and have a working understanding for Django development. Our site is still very basic. All we really need is a view for the map and a URL redirector to it. Later we'll expand this a lot but it's always good to get a basic working system then bite off to much to begin with. We are going to run few commands and not add much code for this. Start off with creating the project: django-admin startproject modeller Run it to test it worked: python manage.py runserver Create our map app: python manage.py startapp terrainmap Now we need to add a view for our map web

Map integration

 Web Map Interface: There are a number of ways to implement a map on the map. The option most known is probably with google maps API. We will not go with this option in this application but go with Leaflet . Leaflet is open-source and has all features most developers need. We will also be using  Tangram , as mapping engine. This will allow us to fully customize the look of our map, including a custom elevation map. Now we have an interface to show the map, an engine to change the look fully all we need now is map data. Here too there are different option but keeping with the open-source theme we will be going with OpenStreetMaps . More specifically Mapzen which is the tangram integration for OpenStreetMap.  Our map interface has two main functions, Show a map with elevation data and letting the user select a region they want. We'll start with the latter with this code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 <div id= "mapid&

Blender api script

Image
To generate a topographic model from a height map we are going to blender Python API. The used python script does the following: Get path for the used heightmap and output STL Create a plane and subdivide it. This give a higher number of vertices and looks like a higher 'resolution'. In this current example we use 200 cut which is the maximum for this operation. If a higher vertex count is need the operation can always be redone  The heightmap image get loaded as a texture and this texture get used for the displacement operation. The displacement strength controls the height of the displacement A solidify operation is used to give the plane some volume. This could also be done with an extrusion for a cleaner result. But a solidify is easier and in the next operation the this won't matter anyway A boolean operation is used on the plane to cut it in a circle. The used object for this is a cylinder. The intersection is used for the operation. Finally the STL is exported. Here

Nasa topographic data

Image
Nasa is a great general source for earth related maps be it weather, temperature, or topographical. In the following source we can get some height maps of earth: https://visibleearth.nasa.gov/images/73934/topography This source is great for topographic data of larger regions i.e. continents or whole countries.  You can one image of the entire planet or eight divides one with higher resolution

Project concept

Image
In this blog we will explore the possibility to create custom STL files based on topographic data sources via a web interface. General workflow: The user will select the the wanted terrain via a map interface, here he will set the coordinates and radius of the map. These properties get send to the web server which will request a height map from the corresponding data source. This can be via a API request or in a internal file.  The webserver launches blender via a terminal command a launches the internal python script. This script will get the height map and needed model properties After the python script has been processed blender will export a STL file and render a image of the model. The render part may be optional The webserver fetches the STL file and optional rendered image and sends these through to the web interface. Now the user can preview the model via the rendered image and download the wanted STL model. The currently planned development process for this project is the foll