SAGA GIS Import Point Cloud From txt-file ( batch processing ), interpolate a grid and save as GeoTIFF

User Forum
Max
2014-05-06
2014-05-21
  • Max

    Max - 2014-05-06

    Hello experts ;-)

    I'm working on the following topic: I have Laserscanner-Data (XYZI) stored as txt-files and I want to generate raster surfaces (GeoTIFF) from the txt-files via IDW (Inverse Distance Weighted). The final results should be one GeoTIFF based on the height/Z-information and one GeoTIFF based
    on the intensity-information for each input-txt-file. Using the SAGA GIS GUI on Windows7 64bit, I do these steps:
    1st) "Import/Export - Shapes" Module "Import Point Cloud From Text File" (Parameters: "X" "Y" "Z" + one extra attribute called "Intensity")
    2nd) "Grid - Gridding" Module "Inverse Distance Weighted" (Parameters: Attribute "Z" or "Intensity")

    NOW, MY QUESTION IS: How can I realize this procedure via BATCH PROCESSING for all txt-files, that are stored in one directory? My main problem is, that I don't know how to access the point cloud result from the 1st Module when I run the 2nd Module. Is the txt-file loaded into "-POINTS:" in the module "Import Point Cloud from Text File"? And if, is "*.sgrd" the right format for these points?
    Where can these points be accessed in the Module "Inverse Distance Weighted"? "-SHAPES:"? And last but not least, how can I finally save the GeoTIFFs?

    I'd really be glad of some help! But please keep in mind that this is my first task in batch processing at all ;-) Therefore, an example would be great!
    Thanks in advance!!!

    Here is the raw code I've got so far:

    set PATH=%PATH%;C:\SAGA
    SET WORK=C:\data
    
    FOR /F %%i IN ('dir/b %WORK%\*.txt') DO
    (
    
    saga_cmd io_shapes "Import Point Cloud from Text File" ^
    -POINTS=NULL ^
    -FILE=%WORK\%%i ^
    -XFIELD=1 ^
    -YFIELD=2 ^
    -ZFIELD=3 ^
    -ATTRIBS=1 ^
    -FIELDSEP=1 
    
    saga_cmd grid_gridding "Inverse Distance Weighted" ^ 
    -SHAPES=NULL ^
    -FIELD=0 ^
    -TARGET=0 ^
    -SEARCH_RANGE=0 ^
    -SEARCH_RADIUS=10.000000 ^
    -SEARCH_POINTS_ALL=0 ^
    -SEARCH_POINTS_MAX=20 ^
    -SEARCH_DIRECTION=0 ^
    -WEIGHTING=0 ^
    -WEIGHT_POWER=2.000000 ^
    -WEIGHT_BANDWIDTH=1.000000 ^
    -USER_XMIN=0.000000 ^
    -USER_XMAX=0.000000 ^
    -USER_YMIN=0.000000 ^
    -USER_YMAX=0.000000 ^
    -USER_SIZE=0.010000 ^
    -USER_COLS=0 ^
    -USER_ROWS=0 ^
    -USER_GRID=NULL ^
    -GRID_GRID=NULL
    
    )
    

    HERE IS SOME SAMPLE DATA:

    X[m] Y[m] Z[m] I[12bit]
    375660.23806 2047917.98046 570.03326 2605
    375660.23399 2047917.97962 570.03296 2757
    375660.23058 2047917.97904 570.03119 2820
    375660.22466 2047917.97766 570.03277 2761
    375660.22142 2047917.97713 570.03088 2707
    375660.21584 2047917.97581 570.03265 2763
    375660.21107 2047917.97478 570.03296 2679
    375660.20666 2047917.97389 570.03246 2611
    375660.20118 2047917.97263 570.03381 2639
    375660.19719 2047917.97182 570.03337 2605
    375660.19310 2047917.97100 570.03275 2541
    375660.18848 2047917.97004 570.03259 2672
    375660.18527 2047917.96950 570.03081 2764
    375660.18013 2047917.96832 570.03208 2712
    375660.17555 2047917.96735 570.03212 2696
    375660.17171 2047917.96663 570.03085 2688
    375660.16718 2047917.96567 570.03094 2706
    375660.16311 2047917.96483 570.03068 2642
    375660.15801 2047917.96369 570.03152 2587
    375660.15294 2047917.96257 570.03222 2626
    375660.14953 2047917.96196 570.03070 2692
    375660.14551 2047917.96114 570.03042 2663
    375660.14187 2047917.96046 570.02924 2706
    375660.13814 2047917.95978 570.02787 2715
    375660.13357 2047917.95879 570.02811 2757
    375660.12898 2047917.95778 570.02872 2770
    375660.12360 2047917.95653 570.03020 2660
    375660.11858 2047917.95542 570.03082 2700
    375660.11551 2047917.95493 570.02884 2752
    375660.11026 2047917.95369 570.03050 2804
    375660.10694 2047917.95311 570.02891 2751
    375660.10250 2047917.95219 570.02870 2788
    375660.09964 2047917.95176 570.02640 2691
    375660.09530 2047917.95082 570.02672 2706
    375660.09089 2047917.94988 570.02684 2663
    375660.08584 2047917.94876 570.02760 2689
    375660.08198 2047917.94800 570.02687 2712
    375660.07825 2047917.94725 570.02630 2797
    375660.07369 2047917.94627 570.02657 2859
    375660.07023 2047917.94566 570.02502 2739
    375660.06658 2047917.94497 570.02400 2664
    375660.06147 2047917.94376 570.02563 2781
    375660.05707 2047917.94283 570.02570 2758

     
  • Volker Wichmann

    Volker Wichmann - 2014-05-06

    Hi,

    for general information on command line scripting I would suggest to have a look at the following tutorial: https://sourceforge.net/projects/saga-gis/files/SAGA%20-%20Documentation/Tutorials/Command_Line_Scripting/

    The usage of the Import Point Cloud from Text File differs between saga_gui and saga_cmd, like stated in the Description tab of the module:

    Module usage is different between SAGA GUI and SAGA CMD: With SAGA GUI you will get prompted to choose the fields to export, and to provide the field names and datatypes to use once you execute the module.
    With SAGA CMD you have to provide three strings with the -FIELDS, -FIELDNAMES and -FIELDTYPES parameters. The first one must contain the field numbers, the second one the field names and the third one the choices of the datatype (see the GUI which number equals which datatype). Each field entry has to be separated by semicolon. Field numbers start with 1, e.g. -FIELDS="5;6;8" -FIELDNAMES="intensity;class;range" -FIELDTYPES="2;2;3"

    Besides that, you have to provide the -SKIP_HEADER parameter flag as your input file has a header line. The -POINTS parameter is the output point cloud, it has the file extension .spc ("SAGA Point Cloud").

    Provide this dataset with the -SHAPES parameter of the Inverse Distance Weighted module and set the -FIELD parameter to 2 (z-coordinate). The output of the module is a grid dataset with the extension .sgrd ("SAGA Grid"). It is specified either with the -USER_GRID or -GRID_GRID parameter, depending on your choice with the -TARGET parameter.

    Finally you can convert your .sgrd file to GeoTIFF with the io_gdal "GDAL: Export Raster" module.

     
  • Max

    Max - 2014-05-21

    Hi Volker,
    thanks for your great help! Unfortunately, I still have some problems:
    When I try to run this...

    C:\Users\*******\Desktop\BATCH SAGA>saga_cmd io_shapes "Import Point Cloud fr
    om Text File" -POINTS=C:\TestDaten\SagaTemps\part1.spc -FILE=C:\TestDaten\part1_
    mit_header.txt -FIELDS="1;2;3;4" -FIELDNAMES="X;Y;Z;I" -FIELDTYPES="4;4;4;3" -S
    KIP_HEADER=1 -FIELDSEP=1
    

    ... an error occurs saying "Unexpected characters following option 'SKIP_HEADER'"
    Only if I remove the whole parameter -SKIP_HEADER=1 the process starts working, BUT then the following message comes up "Error: Error parsing attribute fields: field index out of range".

    Here is the whole cmd.exe-dialog for this:

    C:\Users\*******\Desktop\BATCH SAGA>saga_cmd io_shapes "Import Point Cloud fr
    om Text File" -POINTS=C:\TestDaten\SagaTemps\part1.spc -FILE=C:\TestDaten\part1_
    ohne_header.txt -FIELDS="1;2;3;4" -FIELDNAMES="X;Y;Z;I" -FIELDTYPES="4;4;4;3" -F
    IELDSEP=1
    _____________________________________________
    
       #####   ##   #####    ##
      ###     ###  ##       ###
       ###   # ## ##  #### # ##
        ### ##### ##    # #####
     ##### #   ##  ##### #   ##
    _____________________________________________
    
    _____________________________________________
    library path:   D:\Programme\saga_2.1.0_win32\saga_2.1.0_win32\modules\io_shapes
    .dll
    library name:   Import/Export - Shapes
    module name :   Import Point Cloud from Text File
    author      :   V. Wichmann, LASERDATA GmbH (c) 2009
    _____________________________________________
    
    Parameters
    
    Point Cloud: <not set>
    Text File: C:\TestDaten\part1_ohne_header.txt
    X is Column ...: 1
    Y is Column ...: 2
    Z is Column ...: 3
    Fields: 1;2;3;4
    Field Names: X;Y;Z;I
    Field Types: 4;4;4;3
    Skip first line: no
    Field Separator: space
    
    Error: Error parsing attribute fields: field index out of range
    Error: executing module [Import Point Cloud from Text File]
    

    Maybe I've chosen the wrong datatypes for the fields? With regard to my sample data (in my first post) I need double for X,Y and Z and (long)integer for the Intensity value... Are these types coded right above?
    Maybe you can help me once again ;-)

     
    Last edit: Max 2014-05-21
  • Volker Wichmann

    Volker Wichmann - 2014-05-21

    Hi,

    in case you have a header, simply pass

    -SKIP_HEADER
    

    without any further arguments (it's a boolean parameter, and is thus interpreted as true in case you pass it and as false in case you omit the parameter completely).

    Regarding your second call and the errors which result from it: x,y,z are referenced by the -XFIELD, -YFIELD and -ZFIELD parameters, the -FIELDS, -FIELDNAMES and -FIELDTYPES parameters are only required for additional attributes. With only intensity being an additional attribute I would expect that the following should work (intensity seems to be an integer, so you can use 2 as Fieldtype):

    -FIELDS="4" -FIELDNAMES="I" -FIELDTYPES="2"
    
     

Log in to post a comment.