[GRASS-dev] [GRASS GIS] #2873: Simplify usage of GRASS in Python from outside

GRASS GIS trac at osgeo.org
Mon Jan 25 03:13:11 PST 2016


#2873: Simplify usage of GRASS in Python from outside
-------------------------+-------------------------------------------------
  Reporter:  wenzeslaus  |      Owner:  grass-dev@…
      Type:              |     Status:  new
  enhancement            |
  Priority:  major       |  Milestone:  7.1.0
 Component:  Python      |    Version:  svn-trunk
Resolution:              |   Keywords:  startup, installation, scripts,
                         |  interpreter, windows installer, pygrass,
       CPU:              |  temporal, bootstrap, boilerplate
  Unspecified            |   Platform:  All
-------------------------+-------------------------------------------------

Comment (by pmav99):

 I think that the scope of this proposal is very wide. IMHO importing
 dynamic libraries in a cross platform way and providing an official API
 are different issues.

 WRT to providing an official API for working with GRASS Locations/Mapsets
 I believe that the proper python idiom is to use a
 [https://pymotw.com/2/contextlib/index.html#module-contextlib| context
 manager]. In other words, the user should not have to do anything E.g.:

 {{{#!python
 import grass.some_namespace.GrassSession

 with GrassSession("/path/to/gisdb/location/mapset"):
     # work with the specified Location/Mapset
 }}}

 This could be expanded to creating temporary Locations/Mapsets:
 {{{#!python
 import grass.some_namespace.GrassSession

 # not cleaning up might make sense when you debug a script.
 with GrassSession.temporary(cleanup=False):
     # create a temporary location/mapset and optionally clean up when
 exiting the context
 }}}

 or even creating new locations/mapsets:
 {{{#!python
 import grass.some_namespace.GrassSession

 with GrassSession.create_from_epsg(mapset_path, epsg):
     # create a new location/mapset

 with GrassSession.create_from_geofile(mapset_path, geofile_path):
     # create a new location/mapset
 }}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2873#comment:7>
GRASS GIS <https://grass.osgeo.org>



More information about the grass-dev mailing list