I have a remote machine where my GRASS binaries (7.8) are available and I want to apply this solution https://gis.stackexchange.com/a/255899/36712 to my data set of thousands of small images. In most PyGRASS tutorials I find the API works more like an remote to the GUI, in other words you apply functions to layers present in the GrassGUI for example
gscript.parse_command('r.univar', map='elevation', flags='g') where I apply the function
r.univar to the layer
I allready found the
grass-session libary allowing me to create a session without "starting" GRASS. Most of the tutorials I find are also either old referring to Python 2.7 or don't realy cover how to load a dataset or what would even better how I could pass a variable containing the file object to GrassGIS. How I imaging the code should look like is this:
from grass_session import Session with Session(gisdb="/tmp", location="location", create_opts="EPSG:4326"): for png in list_of_png_files: geo_tiff = transform_png_to_geotiff_with_gdal(png) #either i need to do this: Loaded_geotiff = load_geotiff_with_grass(geo_tiff) #or I can work directly with the geo_tiff Variable output = processing.runalg('grass:r.mapcalculator',geo_tiff) thined = processing.runalg('grass7:r.thin',output) lines = processing.runalg('grass7:r.to.vect',thined) save_lines_to_shp(lines)
How can I achieve this? The PyGRASS API seems so counterintuitive and it's hard to understand how this is supposed to work.