Re: [GRASS-user] Getting Started with GRASS Python Scripts
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Il 24/05/2013 21:13, Martin Lacayo ha scritto: Hello Paolo, Yes, my initial thought was to just use GRASS via SEXTANTE. I tired to do this, but did not have any luck. I posted previously on 14/5/2013 to qgis-users with the subject How to run SEXTANTE algorithms outside of QGIS Python console? but did not get a solution to the problem I encountered, which I thought was related to creating a QGIS instance so that I could make calls to SEXTANTE. If you have any suggestions that would be much appreciated. Hi Martin, better ask on qgis-dev or on IRC, most developers read it. All the best. - -- Paolo Cavallini - Faunalia www.faunalia.eu Full contact details at www.faunalia.eu/pc Nuovi corsi QGIS e PostGIS: http://www.faunalia.it/calendario -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAlGjMj8ACgkQ/NedwLUzIr4HIwCfSk0xqZOnfaFjc24GaHvWF9gP FvYAn3xKhrBdvuUijTwLdgQIqXw3Ly7H =3q/V -END PGP SIGNATURE- ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Getting Started with GRASS Python Scripts
Martin Lacayo wrote #remove the location from disk print 'Removing location %s' % location_uri os.system(rm -rf %s % location_uri) Rather than rely on having 'rm' available you could also do: import shutil shutil.rmtree(location_uri) -- View this message in context: http://osgeo-org.1560.x6.nabble.com/Getting-Started-with-GRASS-Python-Scripts-tp5055380p5055759.html Sent from the Grass - Users mailing list archive at Nabble.com. ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Getting Started with GRASS Python Scripts
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 ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Getting Started with GRASS Python Scripts
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Il 23/05/2013 22:49, Martin Lacayo ha scritto: My ultimate goal is to decrease our development time for our open source ecosystem service tools: http://invest-natcap.googlecode.com, but more specifically at the moment I am trying to use r.viewshed so I do not have to write my own. Why not using GRASS through SEXTANTE for this? In this case you have nothing to do, just call whatever module you need. All the best. - -- Paolo Cavallini - Faunalia www.faunalia.eu Full contact details at www.faunalia.eu/pc Nuovi corsi QGIS e PostGIS: http://www.faunalia.it/calendario -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAlGfGNUACgkQ/NedwLUzIr5QQQCcCyEDZmgSjTO2gnRC+Jk5jGRf 1esAmwSA0nx2cNbrRNNBkPtcotrdZvHt =NNfh -END PGP SIGNATURE- ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Getting Started with GRASS Python Scripts
Hello Paolo, Yes, my initial thought was to just use GRASS via SEXTANTE. I tired to do this, but did not have any luck. I posted previously on 14/5/2013 to qgis-users with the subject How to run SEXTANTE algorithms outside of QGIS Python console? but did not get a solution to the problem I encountered, which I thought was related to creating a QGIS instance so that I could make calls to SEXTANTE. If you have any suggestions that would be much appreciated. Thank you, Martin On Fri, May 24, 2013 at 12:37 AM, Paolo Cavallini cavall...@faunalia.it wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Il 23/05/2013 22:49, Martin Lacayo ha scritto: My ultimate goal is to decrease our development time for our open source ecosystem service tools: http://invest-natcap.googlecode.com, but more specifically at the moment I am trying to use r.viewshed so I do not have to write my own. Why not using GRASS through SEXTANTE for this? In this case you have nothing to do, just call whatever module you need. All the best. - -- Paolo Cavallini - Faunalia www.faunalia.eu Full contact details at www.faunalia.eu/pc Nuovi corsi QGIS e PostGIS: http://www.faunalia.it/calendario -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAlGfGNUACgkQ/NedwLUzIr5QQQCcCyEDZmgSjTO2gnRC+Jk5jGRf 1esAmwSA0nx2cNbrRNNBkPtcotrdZvHt =NNfh -END PGP SIGNATURE- ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
[GRASS-user] Getting Started with GRASS Python Scripts
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. 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? My ultimate goal is to decrease our development time for our open source ecosystem service tools: http://invest-natcap.googlecode.com, but more specifically at the moment I am trying to use r.viewshed so I do not have to write my own. Is it possible to script the creation of a database (locally on disk), location, and mapset? And how would you remove them afterwards? Any help or references would be very appreciated. Thank you, Martin ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Getting Started with GRASS Python Scripts
On Thu, 23 May 2013, Martin Lacayo wrote: 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? Martin, You seem to confuse database, location, and mapset. There is only one database (here, it's in /home/rshepard/grassdata/) where everything is stored. The database can contain multiple locations, each one with a specific projection. For example, I have a number of projects in Washington state so I have (among others) Washington-Counties/, Washington-HUC/, Washington-Hydro/, Washington-LL/, Washington-NED/, and Washington-NHD/. Notice that Washington-LL is in long/lat; others might be in SPCS, UTM, or whatever other projection is used by the data source. I also have project-specific locations. Each of these has a basic PERMANENT/ map se and multiple other map sets that might have different boundaries, themes, and so on. HTH, Rich -- Richard B. Shepard, Ph.D. | Have knowledge, will travel. Applied Ecosystem Services, Inc. | http://www.appl-ecosys.com Voice: 503-667-4517 Fax: 503-667-8863 ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Getting Started with GRASS Python Scripts
Rich, Thank you. Yes, that does help. I hadn't realized that in this case database was essentially synonymous with user directory. Several things have now clicked into place. -Martin On Thu, May 23, 2013 at 2:06 PM, Rich Shepard rshep...@appl-ecosys.com wrote: On Thu, 23 May 2013, Martin Lacayo wrote: 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? Martin, You seem to confuse database, location, and mapset. There is only one database (here, it's in /home/rshepard/grassdata/) where everything is stored. The database can contain multiple locations, each one with a specific projection. For example, I have a number of projects in Washington state so I have (among others) Washington-Counties/, Washington-HUC/, Washington-Hydro/, Washington-LL/, Washington-NED/, and Washington-NHD/. Notice that Washington-LL is in long/lat; others might be in SPCS, UTM, or whatever other projection is used by the data source. I also have project-specific locations. Each of these has a basic PERMANENT/ map se and multiple other map sets that might have different boundaries, themes, and so on. HTH, Rich -- Richard B. Shepard, Ph.D. | Have knowledge, will travel. Applied Ecosystem Services, Inc. | http://www.appl-ecosys.com Voice: 503-667-4517 Fax: 503-667-8863 ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Getting Started with GRASS Python Scripts
On Thu, 23 May 2013, Martin Lacayo wrote: Thank you. Yes, that does help. I hadn't realized that in this case database was essentially synonymous with user directory. Several things have now clicked into place. Martin, Yeah, it ain't intuitive. :-) Took me a while to get my head around the GRASS structure, but that was with 4.0. It's sunk in over the years since then. Rich -- Richard B. Shepard, Ph.D. | Have knowledge, will travel. Applied Ecosystem Services, Inc. | http://www.appl-ecosys.com Voice: 503-667-4517 Fax: 503-667-8863 ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Getting Started with GRASS Python Scripts
I think I have now figured out most of the answers to my question, but I am still wondering about some file management. Is the following command a normal way to make a location with a projection from a georeferenced file: g.proj -c georef=/home/user/raster.tif location=example Is there a command to delete a location? I found g.mremove, but that seems to remove data, not locations. Thank you, Martin On Thu, May 23, 2013 at 3:02 PM, Rich Shepard rshep...@appl-ecosys.com wrote: On Thu, 23 May 2013, Martin Lacayo wrote: Thank you. Yes, that does help. I hadn't realized that in this case database was essentially synonymous with user directory. Several things have now clicked into place. Martin, Yeah, it ain't intuitive. :-) Took me a while to get my head around the GRASS structure, but that was with 4.0. It's sunk in over the years since then. Rich -- Richard B. Shepard, Ph.D. | Have knowledge, will travel. Applied Ecosystem Services, Inc. | http://www.appl-ecosys.com Voice: 503-667-4517 Fax: 503-667-8863 ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Getting Started with GRASS Python Scripts
Martin Lacayo wrote: I think I have now figured out most of the answers to my question, but I am still wondering about some file management. Is the following command a normal way to make a location with a projection from a georeferenced file: g.proj -c georef=/home/user/raster.tif location=example Yes. Is there a command to delete a location? No; just remove the directory. If the database is shared by multiple users, creating or deleting locations may require root privilege. -- Glynn Clements gl...@gclements.plus.com ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Getting Started with GRASS Python Scripts
Martin Lacayo wrote: I think I have now figured out most of the answers to my question, but I am still wondering about some file management. If I may chime in, I repeat what Richard already explained actually, just for fun :-) The GRASS GIS data base is the root (of all good geospatial analyses :D). Inside it are put Locations. There can be only one reference system per Location. And, inside a Location, Mapsets help to organise stuff. Note, there is always a PERMANENT Mapset per Location and users may/should use it as a pool for imported data from which to draw the material that is to be processed. Is the following command a normal way to make a location with a projection from a georeferenced file: g.proj -c georef=/home/user/raster.tif location=example Absolutely. But, 1) be careful to define a location= otherwise the current location will be altered. 2) only from inside an existing GRASS Location! From outside, you may use something like the following grass70 -c /geo/geodata/SomePointOfInterest.kml /geo/grassdb/testing/Test_Location In this example, the georeferenced file SomePointOfInterest.kml will be used obtain information about the spatial reference system and a Location will be created. Actually, any georeferenced file recognised by GDAL/OGR should be a valid source Depending on how many of the directories given in the path pre-exist, a Mapset will be created (if GISDBASE and LOCATION pre-exist), a LOCATION will be created as the last part of the defined path (if only the GISDBASE pre- exists), etc. Please, check also the output of 'grass --help' if working in the command line (because the word Scripts is mentioned in the subject of this thread). Is there a command to delete a location? No. One has/can simply delete it as any other directory. I found g.mremove, but that seems to remove data, not locations. Yes, g.remove is for removing single elements inside a GRASS GIS data base (raster and vector maps, groups of raster maps and other). g.mremove (note _m_remove instead of simply remove) is for removing multiple elements/maps in one go by defining a naming pattern using regular expressions. Best, Nikos ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Getting Started with GRASS Python Scripts
Martin Lacayo wrote: I am having trouble getting started with GRASS Python scripts. Note the following useful GRASS-Wiki pages: - http://grasswiki.osgeo.org/wiki/GRASS_and_Python - http://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library 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? You mean importing in the GRASS GIS data base? Like, you have created a Location (no matter which way) and you want to use on of the r.in.* modules to import data in a specific Location? Or is it to load raster maps, already in a GRASS Location, into Python for further processing? 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. This section in GRASS-Wiki might be of your interest: http://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly#Python_example. Also, check this source: http://geoinformatics.fsv.cvut.cz/gwiki/On_scripting_GRASS_GIS:_Building_location-independent_command_line_tools#External_GRASS_Initialisation Is it possible to script the creation of a database (locally on disk), location, and mapset? So, yes it is. Best, Nikos ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user