Chris Harding, Aug. 27, 2019
TouchTerrain_standalone.py
pip install <whl file>
pip install vectors
# comment out (remove the #) the next line and run this cell to see if you could use ee (Earth Engine)
#import ee; ee.Initialize()
if you get:
Please authorize access to your Earth Engine account by running earthengine authenticate in your command line, and then retry.
comment out and run the cell below, the ! means it will run earthengine authenticate
inside a OS shell (commandline).
.config
in your home folder and create a authentication file (in a earthengine folder)import ee;ee.Initialize()
) and run it#!earthengine authenticate
Click on the cell below and hit Shift-Enter to run it (won't show anything, just does some path setup stuff)
# RUN THIS CELL TO START
# just some setup stuff - nothing to see here
import os, sys
from os.path import abspath
from pprint import pprint
#from glob import glob
# need to add parent folder to sys.path, so we can later import common, which is a sibling to standalne
this_folder = abspath(os.getcwd())
parentfolder = abspath(os.getcwd() + os.sep + "..")
sys.path.append(parentfolder)
#print(sys.path)
print('setup done')
Put your settings into the dictionary below and hit Shift-Enter
None null
True true
False false
args = {
# DEM/Area to print
# A: use local DEM raster (geotiff)
#"importedDEM": "pyramid.tif", # put file in same folder as this notebook file!
# B: use area and a DEM online source via EarthEngine
"importedDEM": None,
"DEM_name": "USGS/NED", # DEM source
"bllat": 44.50185267072875, # bottom left corner lat
"bllon": -108.25427910156247, # bottom left corner long
"trlat": 44.69741706507476, # top right corner lat
"trlon": -107.97962089843747, # top right corner long
# 3D print parameters
"tilewidth": 80, # width of each tile in mm, (tile height will be auto calculated)
"printres": 0.4, # resolution (horizontal) of 3D printer (= size of one pixel) in mm,
# should be your nozzle size or just a bit less!
# Using something like 0.01 will NOT print out a super detailed version
# as you slicer will remove such fine details anyway! Instead, you'll
# just wait a long time and get a super large STL file!
# If you want the original resolution of the DEM, use -1
"ntilesx": 1, # number of tiles in x
"ntilesy": 1, # number of tiles in y
"basethick": 0.5, # thickness (in mm) of printed base
"zscale": 3, # elevation (vertical) scaling
"fileformat": "STLb", # format of 3D model files: "obj" wavefront obj (ascii),
# "STLa" ascii STL or "STLb" binary STL.
# To export just the (untiled) raster (no mesh), use "GeoTiff"
"zip_file_name": "myterrain", # base name of zipfile, .zip will be added
# Expert settings
"tile_centered": False, # True-> all tiles are centered around 0/0, False, all tiles "fit together"
"CPU_cores_to_use" : 0, # 0: use all available cores, None: don't use multiprocessing (single core only)
# multi-core will be much faster for more than 1 tile
"max_cells_for_memory_only" : 5000^2, # if number of raster cells is bigger than this, use temp_files instead of memory.
# set this very high to force use of memory and lower it if you run out of memory
"no_bottom": False, # omit bottom triangles? Most slicers still work and it makes smaller files
"no_normal": True, # Don't calculate normals for triangles. This is significantly faster but some viewer may need them.
"bottom_image": None, # 1 band greyscale image used for bottom relief
"ignore_leq": None, # set all values <= this to NaN so they don't print
"unprojected": False, # don't project to UTM (for EE rasters only)
"projection": None, # None means use the closest UTM zone. Can be a EPSG number (int!) instead but not all work.
"only" : None, # if not None: list with x and y tile index (1 based) of the only tile to process
# e.g. [1,1] will only process the tile in upper left corner, [2,1] the tile right to it, etc.
}
########################################################
# if we want to work on a local raster, get the full pathname to it
if args["importedDEM"] != None:
args["importedDEM"]= abspath(args["importedDEM"])
#pprint(args)
print("settings stored, ready to process")
from common import TouchTerrainEarthEngine as TouchTerrain
# Process the data
# This may take some time! You'll see In[*] and some log messages (will also be in the logfile inside the zip)
# You may see some red stuff with 10%, etc. - don't worry, that's normal
totalsize, full_zip_file_name = TouchTerrain.get_zipped_tiles(**args) # all args are in a dict
print("\nDONE!\n\nCreated zip file", full_zip_file_name, "%.2f" % totalsize, "Mb")
# your zip file will be inside the tmp folder which is inside the same folder your notebook file is in
# If you want to unzip the zip file, run this cell
# (You will need to do this before using k3d for visualization)
import os.path
from glob import glob
folder, file = os.path.splitext(full_zip_file_name) # get folder of zip file
# unzip the zipfile into the folder it's already in
import zipfile
zip_ref = zipfile.ZipFile(full_zip_file_name, 'r')
zip_ref.extractall(folder)
zip_ref.close()
print ("unzipped files from", full_zip_file_name, "into the folder", folder)
print (folder, "contains these files:")
for f in glob(folder + os.sep + "*.*"): print(" ", f)
pip install k3d
) and run the cell belowimport k3d
# get all stl files in that folder
mesh_files = glob(folder + os.sep + "*.stl")
#print "in folder", folder, "using", mesh_files
plot = k3d.plot()
from random import randint
for m in mesh_files:
col = (randint(0,255) << 16) + (randint(0,255) << 8) + randint(0,255) # random rgb color as hex
print("adding to viewer:", m, hex(col))
buf = open(m, 'rb').read()
plot += k3d.stl(buf, color=col)
plot.display()