[GRASS-user] Getting Started with GRASS Python Scripts

Moritz Lennert mlennert at club.worldonline.be
Fri May 24 00:27:13 PDT 2013


On 23/05/13 22:49, Martin Lacayo wrote:
> Hello,
>
> I am having trouble getting started with GRASS Python scripts. I am
> using GRASS 6.4 on Debian. Could some provide a basic example of a
> Python script that imports a raster and exports the same raster? In
> particular I am interested in seeing the entire setup of a database
> (locally on disk), location, and mapset from start to finish. Every
> example I have found starts with an existing database, location, and
> mapset. I have been able to get past this part by using the GUI, but I
> need to be able to script their creation.

A database is just a directory, so new problem creating that.

You can create a new location with g.proj location= and a new mapset 
with g.mapset -c. But for these commands to work, you need to be in an 
existing location. IMHU, the easiest is to have a dummy location set up 
that you can connect to in your script, create the new location and 
mapset, and then connect to that new location.

In theory you could create your own location manually, but that implies 
creating all the support files (PROJ, DEFAULT_WIND, etc).


> Have I understood correctly that a database can only contain one
> projection, which is set when it is first created, and that besides
> importing and exporting data all processing has to happen with data
> that is in the database?

Yes. You can possibly work with v./r.external, but IIRC that does not 
give you full topology, so not all all GRASS modules are sure to work as 
expected (don't know about r.viewshed, though).

> Is it possible to script the creation of a database (locally on disk),
> location, and mapset? And how would you remove them afterwards?

To remove a location or mapset you just delete the relevant directory.


Moritz


More information about the grass-user mailing list