ChHarding / TouchTerrain_for_CAGEO

Touch Terrain: A python app to create 3D printable terrain models (STL/OBJ) from only elevation data (via Google Earth Engine) or from a local geotiff. Has been used for CNC terrain models. Runs as a web app (http://touchterrain.org), as .py file (standalone.py) or as jupyter notebook. Docker image: https://github.com/ChHarding/TouchTerrain_jupyter_docker
http://touchterrain.geol.iastate.edu
210 stars 45 forks source link

Error when setting the tilewidth_scale parameters while using a local geotiff #94

Open vgalin opened 2 months ago

vgalin commented 2 months ago

Hello,

I'm using TouchTerrain_standalone.py with local Geotiff files (localized in Europe), but I keep getting "squished" STLs on the Y axis. At first I thought it was a projection issue but even after reprojecting to Web Mercator (EPSG 3857) and ensuring visually with QGIS that the geotiff has the correct shape/projection, the resulting STL is still squished.

I started to wonder if it had something to do with the tilewidth and the tilewidth_scale, but I couldn't test my hypothesis as setting tilewidth_scale to any value besides null seem to lead to an error :

$ python TouchTerrain_standalone.py config.json
WARNING:root:EE init() error (with .config/earthengine/credentials) No module named 'googleapiclient' (This is OK if you don't use earthengine anyway!)
Wrote example_config.json with default values, you can use it as a template but make sure to rename it!
reading config.json
info: polyURL has missing or invalid value, using defaults where possible
info: gpxPathHeight has missing or invalid value, using defaults where possible
info: gpxPixelsBetweenPoints has missing or invalid value, using defaults where possible
info: gpxPathThickness has missing or invalid value, using defaults where possible
info: no_normals has missing or invalid value, using defaults where possible

Using these config values:
CPU_cores_to_use = 0
DEM_name = None
basethick = 1
bllat = None
bllon = None
bottom_image = None
clean_diags = False
fileformat = STLb
fill_holes = None
gpxPathHeight = 100
gpxPathThickness = 5
gpxPixelsBetweenPoints = 20
ignore_leq = True
importedDEM = tarn_masked_webmercator_epsg3857.tif
importedGPX = []
lower_leq = None
max_cells_for_memory_only = 25000000
min_elev = None
no_bottom = False
no_normals = True
ntilesx = 1
ntilesy = 1
offset_masks_lower = None
only = None
polyURL = None
poly_file = None
printres = 0.2
smooth_borders = True
tile_centered = False
tilewidth = 120
tilewidth_scale = 100000
trlat = None
trlon = None
unprojected = False
use_geo_coords = None
zip_file_name = tarn_stl_gen
zscale = 2.0
Log for creating 1 x 1 3D model tile(s) from tarn_masked_webmercator_epsg3857.tif

INFO:root:Log for creating 1 x 1 3D model tile(s) from tarn_masked_webmercator_epsg3857.tif

started: 16:15:02.838146
INFO:root:started: 16:15:02.838146
C:\Users\...\TouchTerrain_for_CAGEO\touchterrain_venv\Lib\site-packages\osgeo\gdal.py:312: FutureWarning: Neither gdal.UseExceptions() nor gdal.DontUseExceptions() has been explicitly called. In GDAL 4.0, exceptions will be enabled by default.
  warnings.warn(
WARNING:root:Warning: raster cells are not square (30.000000000000007x41.560263669301726) , using30.000000000000007
source raster upper left corner (x/y):  170881.6572 5496564.5782
INFO:root:source raster upper left corner (x/y):  170881.6572 5496564.5782
source raster cells size 30.000000000000007 m  (3036, 5197)
INFO:root:source raster cells size 30.000000000000007 m  (3036, 5197)
projection: WGS 84 / Pseudo-Mercator
INFO:root:projection: WGS 84 / Pseudo-Mercator
z-scale: 2.0
INFO:root:z-scale: 2.0
basethickness: 1
INFO:root:basethickness: 1
fileformat: STLb
INFO:root:fileformat: STLb
tile_centered: False
INFO:root:tile_centered: False
no_bottom: False
INFO:root:no_bottom: False
no_normals: True
INFO:root:no_normals: True
ignore_leq: True
INFO:root:ignore_leq: True
lower_leq: None
INFO:root:lower_leq: None
importedGPX: []
INFO:root:importedGPX: []
undefined GDAL value: None
INFO:root:undefined GDAL value: None
ignoring elevations <=  True  (were set to NaN)
INFO:root:ignoring elevations <=  True  (were set to NaN)
Traceback (most recent call last):
  File "C:\Users\...\TouchTerrain_for_CAGEO\TouchTerrain_standalone.py", line 249, in <module>
    main()
  File "C:\Users\...\TouchTerrain_for_CAGEO\TouchTerrain_standalone.py", line 204, in main
    totalsize, full_zip_file_name = TouchTerrain.get_zipped_tiles(**args) # all args are in a dict
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\...\TouchTerrain_for_CAGEO\touchterrain\common\TouchTerrainEarthEngine.py", line 1190, in get_zipped_tiles
    tilewidth = region_size_in_meters[1] / tilewidth_scale * 1000 # new tilewidth in mm
                ^^^^^^^^^^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'region_size_in_meters' where it is not associated with a value

For reference, here is the content of the config.json file I'm using :

{
    "DEM_name": null,
    "bllat": null,
    "bllon": null,
    "trlat": null,
    "trlon": null,
    "importedDEM": "region.tif",
    "printres": 0.2,
    "ntilesx": 1,
    "ntilesy": 1,
    "tilewidth": 120,
    "basethick": 1,
    "zscale": 2.0,
    "fileformat": "STLb",
    "tile_centered": false,
    "zip_file_name": "stl_gen",
    "CPU_cores_to_use": 0,
    "max_cells_for_memory_only": 25000000,
    "no_bottom": false,
    "bottom_image": null,
    "ignore_leq": true,
    "lower_leq": null,
    "unprojected": false,
    "only": null,
    "importedGPX": [],
    "smooth_borders": true,
    "offset_masks_lower": null,
    "fill_holes": null,
    "poly_file": null,
    "min_elev": null,
    "tilewidth_scale": 100000,
    "clean_diags": false,
    "sqrt": false,
    "use_geo_coords": null,
    "projection": "EPSG 3857"
}

Am I missing something?