Smarthome Extravaganza – Part 3 : “Elevation is the key”
Perfectionism may be the greatest quality of the some people, but for me, in has more or less always been the pain in the ass. After finishing the very first 3D modelling of my house as described in the Smart home extravaganza – Part 2, I decided to continue making the virtualization of our house and property.
Most designers and people would just be okay with the rendered 3D models of the house and outdoor buildings such as warehouse and workshop in their “about right” locations on the 3D view virtualization of our property I’m making, but not me. As our yard is more or less uneven divided into higher and lower areas of grass, trees and bedrock, I really felt compelling need to make a realistic 3D presentation of the yard also which would be added as a terrain in my Unity3D application for smart home controlling.
Now there would be several better options for this I would be living in the United States where USGS has made an excellent and precise DEM files for several areas of the country, but for unpleasant fact for me, I live in Finland and even if our NLS (national land survey of finland) has done some excellent geological survey for coordinates and elevations all through the country, the level of the details varies from 10 to 2 meters map precision depending of the fact where you live. For more populated areas in the southern Finland the precision is very good and material quite versatile, but for more rural areas, such as this country area where we live, map precision is not so good, remaining only to 10 meters precision.
Although for most use, the map precision of 10 meters containing coordinates, roads, buildings and land elevation is more than sufficient, for my needs it was just too low. When I tried to get correct land elevation of our property, it eventually turned out that the final resolution of the grayscale heightmap was only 15×15 pixels with low precision, even if how well I tried to scale and detail it.
Geocaching brings the answer
After pondering the problem for a while, my old geocaching skills reminded me of the great elevation and coordinate tracking system GPSs have always provided, not to mention my dearest GPS ever, Garmin GPSMAP 64st, which is, let me underline this, the best GPS I have ever used. I have always loved GPSMAP series ever since my first GPS-love of the life, GPSMAP 60csx. With realization of using GPS to get elevation measurements of our yard, I started make research of the matter.
For my great disappointment, I did NOT find any software which would convert GPX data (GPX Exchange format) from my GPS to a height-based grayscale bitmap, so I figured out I need to make one by myself. From this I took my GPSMAP 64st and headed outside. After half-hour of getting running nose from the freezing air and bruises from the colliding in to branches and roots of the trees in our yard, I finally had managed to map our yard by going everywhere around it and hold my GPS steadily in the same height on my lap.
After exporting data to my computer, it decided to use PHP as a development platform for the heigthmap converted. The procedure itself is quiet easy: GPX file is basically a XML-format based file with easy structure of the Latitude and Longitude coordinates assigned with the elevation this I converted into a basic PHP array and then used PHP’s GD image libraries to generate a grayscale bitmap with Lat/Long converted into X/Y coordinates. The first ending results can be seen on the right.
As we can see, there is grey filled circles (I wanted to say grey balls, but that would have sounded..) around the black map. I tried varying with the size of the .. eh .. balls .. but with the bigger .. balls .. they would have overlapped the earlier plotted heights. I also considered doing semi-transparent circles which would overlay the underlying graphics but though it would be have been little bit pointless because area of the map is not that big and heights do not vary so much.
Next point of the process was making the correlations for the map so it would present direct X/Y mapping, i.e., straighten the map out. This was done simply with croppin’ and rotating with the Photoshop. This was done mainly because the target of the final heightmap would be Unity3D’s terrain heightmap so it needed to be straightened out as the terrain object does not really like tilted bitmaps.
Now, my original idea was this: Walk around the yard with my GPS, let it map the elevations and assign them to coordinates. Then code a little bit and make a software which plots the heights to the XY bitmap as a grayscale circles and then simply blur the whole image with Gaussian blue and import the resulting image to the Unity3D’s terrain’s heightmap, but as always, things don’t follow their original path.
With the generating of the plotted bitmap, it early come to realization that the plotted data was simply too sparse: I had expected my GPS to plot much more precise data with more rapid update-rate, but since I was simply too cold to walk around and too in the middle of darkness as I was doing this in late evening, I guess the results reflected of too rapid data gathering. My original idea of Gaussian blurring dotted circles soon showed a problem because surrounding area of the plottings was simply a background black, so using Gaussian blur it gave too dark nearest-neightbours areas which did not reflect actual heights as showed in the right.
To correct this it meant either of two things: Either I would need to remake the walk using more and more times gathering data around the yard, or I would have sort out to some manual labour with the Photoshop. As my timeline for next few days is quite limited, I took the shorter and faster route of manipulating original plotted image by hand adding bigger areas around the original plots using same colors as the elevation plots were. Results are around on the left.
With this process, It helped out to see the actual elevation differences around our yard, but still caused problems because of the dark areas around the bitmap, so I ended up taking a brush-tool into use and smudged areas around the plots with same near-same colors as the plots were maintaining the height mapping of the area. This also gave me a chance to make few corrections to the plotting which were caused by the trees as I recalled the elevation also from my personal memory storage device called brains. The end results of the hand-corrected bitmap can be soon on the lower right.
Now I finally had, little bit of hand-made and little bit of crazy looking heightmap on my hand so to get the final soften results which I could import into Unity3D’s terrain object’s heigthmap without looking completely ridiculous, I decided to use Gaussian blur into the bitmap so it would smooth our the results. The results of the blurring can be seen on the left.
As we can see, it finally actually starts looking like a real heightmap, and all we needed was a little bit of GPS walking, tumbling into a roots and branches and getting a running nose from a freezing windy air.. not forgetting all the coding, graphics manipulation and little frustration between all of this.
To ease up the importing to the Terrain object, I did a final correction to the bitmap by adding more contrast and decreasing lightness so the elevation varying would be more easily to comprehend and use. The actual and very final results of the first plot gathering can be seen on the right.
As a perfectionist I am, I am not going to use this as a final result of my 3D smart home visualization but it will be sufficient enough for my first beta-testing of the app I am creating and will be a good base heightmap for the Terrain object to use. For the final app and visualization I will use more precisely mapped yard with less or none hand made mapping and manipulation.
As for the results
The final and imported [beta] heightmap used in terrain object can be seen below.
Yes. There is a hell of a lot still to do here.