alecsandrei / PySAGA-cmd

PySAGA-cmd is a simple way of running SAGA GIS tools using Python.
MIT License
2 stars 0 forks source link

stl output size from tin is 0 #2

Open sugizo opened 1 month ago

sugizo commented 1 month ago

env google colab os : ubuntu jammy (x64)

steps

!apt update
!apt install -y saga gdal-bin
pip install -U PySAGA-cmd
!gdal_translate -of GSBG /usr/local/lib/python3.10/dist-packages/PySAGA_cmd/assets/DEM_30m.tif DEM_30m.grd
!saga_cmd tin_tools 0 -GRID DEM_30m.grd -VALUES DEM_30m.grd -TIN DEM_30m
!saga_cmd io_shapes 12 -TIN DEM_30m.shp -ZFIELD 'DEM_30m' -BINARY 1 -FILE DEM_30m
!ls -la

result not expected, output DEM_30m.stl 0 byte

total 10912
drwxr-xr-x 1 root root    4096 May 28 18:32 .
drwxr-xr-x 1 root root    4096 May 28 16:25 ..
drwxr-xr-x 4 root root    4096 May 23 13:24 .config
-rw-r--r-- 1 root root       6 May 28 18:28 DEM_30m.cpg
-rw-r--r-- 1 root root 5489737 May 28 18:28 DEM_30m.dbf
-rw-r--r-- 1 root root  563096 May 28 18:28 DEM_30m.grd
-rw-r--r-- 1 root root     903 May 28 18:28 DEM_30m.grd.aux.xml
-rw-r--r-- 1 root root     298 May 28 18:28 DEM_30m.mshp
-rw-r--r-- 1 root root       0 May 28 18:28 DEM_30m.prj
-rw-r--r-- 1 root root 3941380 May 28 18:28 DEM_30m.shp
-rw-r--r-- 1 root root 1126180 May 28 18:28 DEM_30m.shx
-rw-r--r-- 1 root root       0 May 28 18:31 DEM_30m.stl

expected result can have *.stl output that can be view or open, like execute from saga_gui

alecsandrei commented 1 month ago

Hello!

PySAGA-cmd is just a Python wrapper around the command line interface of SAGA GIS. You might want to repost your issue on the official SAGA GIS repository https://github.com/saga-gis/saga-gis.

I will still give you my personal opinion on this, though. SAGA GIS does not support read/write operations on TIN files, so you can not save the "Grid to TIN" output locally. If you will look inside the generated DEM_30m.shp you will see that it is a point vector. Your workflow works when you try with saga_gui because SAGA GIS has some way of handling TIN files inside the GUI application, but not inside the command line interface.

I think you can still make this happen through the command line interface if you create a toolchain. There are some toolchain resources online which could help you get started. After you create and import the toolchain xml file, you can use it with the command line interface and automate your workflows.

If you have any more questions, let me know!

sugizo commented 1 month ago

thanks for suggestion, already tried it but imo it's nonsense,

better use saga_cmd like my first post, because can pass parameter value while in toolchain xml, the values is vagued

e.g.

<?xml version="1.0" encoding="UTF-8"?>
<toolchain saga-version="8.5.0">
  <group>toolchains</group>
  <identifier>tes</identifier>
  <name>tes</name>
  <description>created from history</description>
  <parameters>
    <input varname="tool_01__VALUES" type="grid_list">
      <name>Values</name>
    </input>
    <input varname="tool_01__GRID" type="grid">
      <name>Grid</name>
    </input>
    <output varname="tool_01__TIN" type="tin">
      <name>TIN</name>
    </output>
  </parameters>
  <tools>
    <tool library="tin_tools" tool="0" name="Grid to TIN">
      <output id="TIN">tool_01__TIN</output>
      <input id="GRID">tool_01__GRID</input>
      <input id="VALUES">tool_01__VALUES</input>
    </tool>
  </tools>
</toolchain>

the problem is during the last command on my first post : saga_cmd io_shapes 12 -TIN DEM_30m.shp -ZFIELD 'DEM_30m' -BINARY 1 -FILE DEM_30m

already tried from inside python script too, again same like first post, the last command produce 0 file size e.g.

file_name = 'DEM_30m'

path = f'/usr/local/lib/python3.10/dist-packages/PySAGA_cmd/assets/{file_name}.tif'

io_gdal_0 = saga / 'io_gdal' / 0
output_0 = io_gdal_0.execute(files = path, grids = file_name, ignore_stderr = True, verbose = True)
print(output_0.stdout)

tin_tools_0 = saga / 'tin_tools' / 0
output_1 = tin_tools_0.execute(grid = f'{file_name}.sgrd', values = f'{file_name}.sgrd', tin = f'{file_name}_0', ignore_stderr = True, verbose = True)
print(output_1.stdout)

io_shapes_0 = saga / 'io_shapes' / 12
output_1_1 = io_shapes_0.execute(tin = f'{file_name}_0.shp', zfield = f'{file_name}_0', binary = 1, file = f'{file_name}.stl', ignore_stderr = True, verbose = True)
print(output_1_1.stdout)

best regards