[GRASS-user] relative path to GISbase in Scripts

Glynn Clements glynn at gclements.plus.com
Fri May 13 20:50:19 EDT 2011


Johannes Radinger wrote:

> at the moment I am connecting to the sqlite database with the use of a absolute path in a pythonscript like:
> 
> database = sqlite3.connect('/users/Johannes Radinger/Documents/GRASS-GIS/Treene_location/Treene/sqlite.db')
> db = database.cursor()
> 
> I think it should be possible to set a relative Path in pyton like
> 
> database = sqlite3.connect('$relative/$path/$to/$location/sqlite.db') but how can that be done?

	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')

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list