<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br><br>On Mon, Apr 22, 2019 at 4:45 AM Facundo Ferrín <<a href="mailto:facundo.ferrin@gmail.com">facundo.ferrin@gmail.com</a>> wrote:<br>><br>> Hello!<br>><br>> I don't know if I'm expressing myself well. The use of GRASS is command-line, in the sense:<br>><br>> rass run --mapset=/some/directory/grassdata/ncspm/practice1 r.lake elevation=some/file.tiff<br>><br>><br>> What I propose is the use of a package to import from any Python script. For example, read a TIFF with GDAL or GeoPandas, perform some operations like removing some data and finally simplify the polygon.<br><div><br></div><div>GRASS is essentially a toolset consisting of several hundred modules which are called on the command line or in scripts. If you want to use this functionality, you need to call GRASS modules as done in e.g. <br></div><div><a href="https://trac.osgeo.org/grass/browser/grass/trunk/scripts">https://trac.osgeo.org/grass/browser/grass/trunk/scripts</a><br></div><div>></div>> GRASS is something like GDAL's option to create polygons from images:<br>><br>> <a href="https://gdal.org/gdal_polygonize.html">https://gdal.org/gdal_polygonize.html</a><br></div><div dir="ltr"><br></div><div>The GRASS equivalent is 'r.to.vect type=area'<br></div><div dir="ltr">><br>> My idea, or my need, is to use GRASS functions programmatically, as in this case.<br>><br>> <a href="https://pcjericks.github.io/py-gdalogr-cookbook/raster_layers.html#polygonize-a-raster-band">https://pcjericks.github.io/py-gdalogr-cookbook/raster_layers.html#polygonize-a-raster-band</a><br></div><div dir="ltr"><br></div><div dir="ltr">Convert an OGR File to a Raster</div><div>more generic: convert a vector to a raster<br></div><div dir="ltr"><div>The GRASS equivalent is 'v.to.rast'<br></div></div><div dir="ltr"><br></div><div dir="ltr">Clip a GeoTiff with Shapefile</div><div>more generic: clip a raster to vector polygons</div><div>In GRASS: convert to vector polygons to raster with 'v.to.rast', then create a MASK with 'r.mask'</div><div><br></div><div>Calculate zonal statistics</div><div>more precisely here: get raster statistics for each vector polygon</div><div dir="ltr"><div>The GRASS equivalent is 'v.rast.stats'<br></div></div><div dir="ltr"><br></div><div dir="ltr">Raster to vector line</div><div>In GRASS: use 'r.reclass' or 'r.mapcalc' to select pixel values that need to be converted to vector lines, then use r.to.vect type=line. BTW, the green lines in the example are wrong because they don#t go through the pixel centers.</div><div><br></div><div>Create raster from array</div><div><div dir="ltr"><div>The GRASS equivalent is 'r.in.ascii'</div><div><br></div></div><div dir="ltr">Create least cost path</div><div dir="ltr"><div dir="ltr"><div>The GRASS equivalent is 'r.cost' + 'r.path'<br></div><div><br></div><div>Replace No Data Value of Raster with new value</div><div><div>The GRASS equivalent is 'r.mapcalc' using "if(isnull(rastermap), <new_value>, rastermap)"<br></div><div><br></div></div></div></div></div>><br><div dir="ltr">> Is that among your ideas for the future? If that's the case and you're interested, let me know. If so, you could make some prototype use to start migrating the functionalities.<br></div><div dir="ltr"><br></div><div>All this can be easily implemented as a GRASS GIS addon in a Python script with much less code than in your example. Please have a look at</div><div><a href="https://trac.osgeo.org/grass/browser/grass/trunk/scripts">https://trac.osgeo.org/grass/browser/grass/trunk/scripts</a></div><div>to get started.<br></div><div>Alternatively, a QGIS plugin using GRASS GIS functionality would be an option (QGIS has a GRASS GIS interface that can be used for inspiration).<br></div><div dir="ltr"><br></div><div>my2c,</div><div>Markus M</div><div><br></div><div dir="ltr">><br>> Cheers!<br>><br>><br>> On 10/04/2019 16:47, Vaclav Petras wrote:<br>><br>> Hello Facundo,<br>><br>> Using the GRASS GIS algorithms in various settings is certainly something we are aiming for. However, as you probably understood from the conversation here, it is not clear what exactly you are trying to achieve considering the already available ways (APIs if you will). Also, to evaluate your proposal, we need to test your skills for this particular project. Therefore, I suggest you 1) implement a prototype of what you have in mind, 2) compare it with the existing approaches (see e.g. email from Markus M.), and 3) identify what is missing in the existing approaches and what would you need to add in order to make you prototype work.<br>><br>> Alternatively, or ideally in addition to the above, you can implement couple of the test and training tasks from the proposal already linked by Luca:<br>><br>> <a href="https://trac.osgeo.org/grass/wiki/GSoC/2019#Neweasy-to-useCLIandAPIforGRASSGIS">https://trac.osgeo.org/grass/wiki/GSoC/2019#Neweasy-to-useCLIandAPIforGRASSGIS</a><br>><br>> Best,<br>> Vaclav<br>><br>> On Thu, Mar 28, 2019 at 4:13 AM Markus Metz <<a href="mailto:markus.metz.giswork@gmail.com">markus.metz.giswork@gmail.com</a>> wrote:<br>>><br>>><br>>><br>>> On Thu, Mar 28, 2019 at 9:02 AM Maris Nartiss <<a href="mailto:maris.gis@gmail.com">maris.gis@gmail.com</a>> wrote:<br>>> ><br>>> > Hello Facundo,<br>>> > the easiest way would be moving functions of v.generalize into a<br>>> > library (e.g. grass_generalize) and thus make available for calling<br>>> > via ctypes.<br>>> > In the past I have had a good success manipulating GRASS vectors via<br>>> > ctypes. It takes more skill than a plain Python implementation but it<br>>> > is easier than a full blown C code and faster than pure Python one.<br>>> ><br>>> > Māris.<br>>> ><br>>> > ceturtd., 2019. g. 28. marts, plkst. 03:13 — lietotājs Facundo Ferrin<br>>> > (<<a href="mailto:facundo.ferrin@gmail.com">facundo.ferrin@gmail.com</a>>) rakstīja:<br>>> > ><br>>> > > Hi Luca!<br>>> > ><br>>> > > Thanks for replying! In my job, there were things we had to do programmatically. For example, to manipulate geometries that reach the backend from a GeoJSON we use tools like these:<br>>> > ><br>>> > > <a href="https://pcjericks.github.io/py-gdalogr-cookbook/geometry.html#create-geometry-from-wkt">https://pcjericks.github.io/py-gdalogr-cookbook/geometry.html#create-geometry-from-wkt</a><br>>> > ><br>>> > > However, polygon simplification does not work very well because it does not take topology into account. My idea was to port part of the GRASS algorithms to be able to use them without needing the graphical interface or command line, but only importing a library in a Python script.<br>>><br>>> In this particular case, the core of the corresponding python script would be three lines (import, simplify, export):<br>>><br>>> --><br>>> import grass.script as grass<br>>><br>>> grass.run_command('v.in.ogr', ...)<br>>> grass.run_command('v.generalize', ...)<br>>> grass.run_command('v.out.ogr', ...)<br>>> <--<br>>><br>>> The import step with v.in.ogr is needed because the vector to be simplified must be a native GRASS vector with topology.<br>>><br>>> How does your proposal differ from the QGIS-GRASS interface?<br>>><br>>> Markus M<br>>> > ><br>>> > > Is it something that you have in mind to do or that might be useful to you?<br>>> > ><br>>> > ><br>>> > > El jue., 28 de mar. de 2019 a la(s) 00:32, Luca Delucchi (<a href="mailto:lucadeluge@gmail.com">lucadeluge@gmail.com</a>) escribió:<br>>> > >><br>>> > >> On Tue, 26 Mar 2019 at 03:11, Facundo Ferrin <<a href="mailto:facundo.ferrin@gmail.com">facundo.ferrin@gmail.com</a>> wrote:<br>>> > >> ><br>>> > >> > Hi there!<br>>> > >><br>>> > >> Hi Facundo,<br>>> > >> ><br>>> > >> ><br>>> > >> > My name is Facundo Ferrin. I am a nuclear engineer who is taking a master in Computer Vision in Barcelona, and finally I found my opportunity to contribute to OSGeo by applying two things that I really like: Python and Backend development . I do not know exactly what I should write in this first email, so I'll start by listing the projects I'm interested in.<br>>> > >> ><br>>> > >> > I'm working in a company that is developing a platform for precision agriculture called Auravant (<a href="https://www.auravant.com/">https://www.auravant.com/</a>). I work as a backend developer and data analyst and I use daily almost every tool that you post in the ideas: GeoServer, PostGIS, QGis. I'm also porting a tool for polygon simplification called topoJSON (<a href="https://github.com/fferrin/topojson">https://github.com/fferrin/topojson</a>).<br>>> > >> ><br>>> > >> > ---<br>>> > >> > MY MAIN IDEA is to start porting GRASS tools into a python package that can be used in other projects (beyond the client to use by command line). I don't know if it's something you have in mind but for offline and automated analysis it would be very useful. I particularly had problems when I tried to simplify geometries since the geometry of polygons was not taken into account.<br>>> > >> > ---<br>>> > >><br>>> > >> Your idea is not clear to me, there are already two Python library to<br>>> > >> work with GRASS. you can find some ideas in the proposal page<br>>> > >> <a href="https://trac.osgeo.org/grass/wiki/GSoC/2019">https://trac.osgeo.org/grass/wiki/GSoC/2019</a> (for example<br>>> > >> Neweasy-to-useCLIandAPIforGRASSGIS) and<br>>> > >> <a href="https://trac.osgeo.org/grass/wiki/GSoC/2018">https://trac.osgeo.org/grass/wiki/GSoC/2018</a> (Improve GRASS integration<br>>> > >> in QGIS 3)<br>>> > >><br>>> > >> > Hope to hear from you soon!<br>>> > >> ><br>>> > >><br>>> > >> --<br>>> > >> ciao<br>>> > >> Luca<br>>> > >><br>>> > >> <a href="http://www.lucadelu.org">www.lucadelu.org</a><br>>> > ><br>>> > > _______________________________________________<br>>> > > grass-dev mailing list<br>>> > > <a href="mailto:grass-dev@lists.osgeo.org">grass-dev@lists.osgeo.org</a><br>>> > > <a href="https://lists.osgeo.org/mailman/listinfo/grass-dev">https://lists.osgeo.org/mailman/listinfo/grass-dev</a><br>>> > _______________________________________________<br>>> > grass-dev mailing list<br>>> > <a href="mailto:grass-dev@lists.osgeo.org">grass-dev@lists.osgeo.org</a><br>>> > <a href="https://lists.osgeo.org/mailman/listinfo/grass-dev">https://lists.osgeo.org/mailman/listinfo/grass-dev</a><br>>> _______________________________________________<br>>> grass-dev mailing list<br>>> <a href="mailto:grass-dev@lists.osgeo.org">grass-dev@lists.osgeo.org</a><br>>> <a href="https://lists.osgeo.org/mailman/listinfo/grass-dev">https://lists.osgeo.org/mailman/listinfo/grass-dev</a></div></div></div></div></div></div></div></div></div>