[GRASS-user] relative path to GISbase in Scripts
Johannes Radinger
jradinger at gmx.at
Sun May 15 10:20:44 EDT 2011
Am 14.05.2011 um 08:32 schrieb Markus Neteler:
> On Sat, May 14, 2011 at 2:50 AM, Glynn Clements
> <glynn at gclements.plus.com> wrote:
>>
>> Johannes Radinger wrote:
>>
>>> at the moment I am connecting to the sqlite database with the use of a absolute path in a pythonscript like:
> ...
>>
>> import grass.script as grass
>> import os.path
>>
>> env = grass.gisenv()
>>
>> gisdbase = env['GISDBASE']
>> location = env['LOCATION_NAME']
>> mapset = env['MAPSET']
>>
>> path = os.path.join(gisdbase, location, mapset, 'sqlite.db')
>
> Added to
> http://grass.osgeo.org/wiki/GRASS_and_Python#Path_to_GISDBASE
Thank you for adding it to the wiki, I think that can be useful for a lot other people.
Just two related questions:
1) I think it is not possible but I just want to ask: Can that method be anyhow used also for the
g.parser options? I tried:
#%Option
#% key: PS_map
#% type: string
#% required: no
#% multiple: no
#% key_desc: name
#% description: Name for PostScript output file
#% gisprompt: new_file,file,output
#% guisection: Optional
#% answer: os.path.join(gisdbase, location, mapset, 'PS_map_result')
#%end
But for sure this is just a string and therefore doesn't work. But is it somehow possible to use
relative information about the path to a file in the answer-option for g.parser?
2) How can I get the path to the script-file i am running at the moment in GRASS? like ./././GRASS/6.5/Modules/bin/script.py? This should work on every operating system.
/johannes
>
> Markus
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user
More information about the grass-user
mailing list