[GRASS-user] Get current location projection in a Python Script

On May 25, 2010, at 1:29 AM, grass-user-request@lists.osgeo.org wrote:

Date: Tue, 25 May 2010 08:50:10 +0100
From: Kim Besson <kimbesson1981@gmail.com>
Subject: [GRASS-user] Get current location projection in a Python
  Script
To: grass-user@lists.osgeo.org
Message-ID:
  <AANLkTinVGIHZ3X8oStE4MWkdynHjPZyAo_Ve4KcvZs2U@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Greetings

I'm building a GRASS Python Script to automatically import a set of data to
my location. At GRASS book (chapter 3.3.3) it uses g.proj -wf to to check
current location projection. Can I use the same command in Python to
retrieve the same?

And how about calling gdalwarp in a Python-GRASS Script? can it be called
and used by a Python_GRASS Script? if so, is there any Python example with
that?

Regarding "g.proj -wf" command. I get a lot of information. I suppose
GDALWARP can read this right ? If not, How can I obtain current Location
EPSG code?

Thanks

Best regards,
Kim

Use the region() command from the GRASS Python library. <http://download.osgeo.org/grass/grass6_progman/pythonlib.html&gt;

Michael

Kim Besson:

> I'm building a GRASS Python Script to automatically import a set of data
> to my location. At GRASS book (chapter 3.3.3) it uses g.proj -wf to to
> check current location projection. Can I use the same command in Python
> to retrieve the same?
>
>
> And how about calling gdalwarp in a Python-GRASS Script? can it be called
> and used by a Python_GRASS Script? if so, is there any Python example
> with that?
>
> Regarding "g.proj -wf" command. I get a lot of information. I suppose
> GDALWARP can read this right ? If not, How can I obtain current Location
> EPSG code?

Michael Barton:

Use the region() command from the GRASS Python library.
<http://download.osgeo.org/grass/grass6_progman/pythonlib.html&gt;

Just for the records, a thread not _directly_ about it but close (enough?):
<http://osgeo-org.1803224.n2.nabble.com/Getting-rows-cols-of-a-region-in-a-
script-tc2787474.html#a2788062>

Nikos

On May 25, 2010, at 8:25 AM, Nikos Alexandris wrote:

Kim Besson:

I'm building a GRASS Python Script to automatically import a set of data
to my location. At GRASS book (chapter 3.3.3) it uses g.proj -wf to to
check current location projection. Can I use the same command in Python
to retrieve the same?

And how about calling gdalwarp in a Python-GRASS Script? can it be called
and used by a Python_GRASS Script? if so, is there any Python example
with that?

Regarding "g.proj -wf" command. I get a lot of information. I suppose
GDALWARP can read this right ? If not, How can I obtain current Location
EPSG code?

Michael Barton:

Use the region() command from the GRASS Python library.
<http://download.osgeo.org/grass/grass6_progman/pythonlib.html&gt;

Just for the records, a thread not _directly_ about it but close (enough?):
<http://osgeo-org.1803224.n2.nabble.com/Getting-rows-cols-of-a-region-in-a-
script-tc2787474.html#a2788062>

Nikos

The thread is for BASH and does not work for Python.

Michael

Kim Besson:

>>> I'm building a GRASS Python Script to automatically import a set of
>>> data to my location. At GRASS book (chapter 3.3.3) it uses g.proj -wf
>>> to to check current location projection. Can I use the same command in
>>> Python to retrieve the same?

>>> And how about calling gdalwarp in a Python-GRASS Script? can it be
>>> called and used by a Python_GRASS Script? if so, is there any Python
>>> example with that?
>>>
>>> Regarding "g.proj -wf" command. I get a lot of information. I suppose
>>> GDALWARP can read this right ? If not, How can I obtain current
>>> Location EPSG code?

Michael Barton:

>> Use the region() command from the GRASS Python library.
>> <http://download.osgeo.org/grass/grass6_progman/pythonlib.html&gt;

Nikos Alexandris:

> Just for the records, a thread not _directly_ about it but close
> (enough?):
> <http://osgeo-org.1803224.n2.nabble.com/Getting-rows-cols-of-a-region-in
> -a- script-tc2787474.html#a2788062>

The thread is for BASH and does not work for Python.

Michael, the thread started for bash but in the last posts (in it) python
stuff are demonstrated ( I recall so). Maybe I've posted directly a post where
no "python" is included? Hmm... let me see... ... ok, here it is:

1. http://www.mail-archive.com/grass-user@lists.osgeo.org/msg08280.html
2. http://www.mail-archive.com/grass-user@lists.osgeo.org/msg08288.html

Maybe they are outdated though (?).

Cheers, Nikos

On May 25, 2010, at 11:14 AM, Nikos Alexandris wrote:

Kim Besson:

I'm building a GRASS Python Script to automatically import a set of
data to my location. At GRASS book (chapter 3.3.3) it uses g.proj -wf
to to check current location projection. Can I use the same command in
Python to retrieve the same?

And how about calling gdalwarp in a Python-GRASS Script? can it be
called and used by a Python_GRASS Script? if so, is there any Python
example with that?

Regarding "g.proj -wf" command. I get a lot of information. I suppose
GDALWARP can read this right ? If not, How can I obtain current
Location EPSG code?

Michael Barton:

Use the region() command from the GRASS Python library.
<http://download.osgeo.org/grass/grass6_progman/pythonlib.html&gt;

Nikos Alexandris:

Just for the records, a thread not _directly_ about it but close
(enough?):
<http://osgeo-org.1803224.n2.nabble.com/Getting-rows-cols-of-a-region-in
-a- script-tc2787474.html#a2788062>

The thread is for BASH and does not work for Python.

Michael, the thread started for bash but in the last posts (in it) python
stuff are demonstrated ( I recall so). Maybe I've posted directly a post where
no "python" is included? Hmm... let me see... ... ok, here it is:

1. http://www.mail-archive.com/grass-user@lists.osgeo.org/msg08280.html
2. http://www.mail-archive.com/grass-user@lists.osgeo.org/msg08288.html

Maybe they are outdated though (?)

Cheers, Nikos

These work, but there is a better shortcut now from the GRASS Python library.

regiondict = grass.region()

will create a Python dictionary regiondict with values for extents and resolution. It's the same as creating a dictionary by parsing g.region -ugp

Michael

[...]

Nikos Alexandris:

>>> Just for the records, a thread not _directly_ about it but close
>>> (enough?):
>>> <http://osgeo-org.1803224.n2.nabble.com/Getting-rows-cols-of-a-region-i
>>> n -a- script-tc2787474.html#a2788062>

[...]

> 1. http://www.mail-archive.com/grass-user@lists.osgeo.org/msg08280.html
> 2. http://www.mail-archive.com/grass-user@lists.osgeo.org/msg08288.html

Michael Barton wrote:

These work, but there is a better shortcut now from the GRASS Python
library.

regiondict = grass.region()

will create a Python dictionary regiondict with values for extents and
resolution. It's the same as creating a dictionary by parsing g.region
-ugp

Attached a simple python script with various ways to get "rows, cols" from the
"current" region.

Nikos

(attachments)

g.region.resolution.py (2.35 KB)

Thanks. Quite helpful.

Michael
____________________
C. Michael Barton
Director, Center for Social Dynamics & Complexity
Professor of Anthropology, School of Human Evolution & Social Change
Arizona State University

voice: 480-965-6262 (SHESC), 480-727-9746 (CSDC)
fax: 480-965-7671 (SHESC), 480-727-0709 (CSDC)
www: www.public.asu.edu/~cmbarton, http://csdc.asu.edu

On May 30, 2010, at 2:41 AM, Nikos Alexandris wrote:

[...]

Nikos Alexandris:

Just for the records, a thread not _directly_ about it but close
(enough?):
<http://osgeo-org.1803224.n2.nabble.com/Getting-rows-cols-of-a-region-i
n -a- script-tc2787474.html#a2788062>

[...]

1. http://www.mail-archive.com/grass-user@lists.osgeo.org/msg08280.html
2. http://www.mail-archive.com/grass-user@lists.osgeo.org/msg08288.html

Michael Barton wrote:

These work, but there is a better shortcut now from the GRASS Python
library.

regiondict = grass.region()

will create a Python dictionary regiondict with values for extents and
resolution. It's the same as creating a dictionary by parsing g.region
-ugp

Attached a simple python script with various ways to get "rows, cols" from the
"current" region.

Nikos
<g.region.resolution.py>