[GRASS-user] g.region usage in python for overriding N, S, E, W values

Anna Kratochvílová kratochanna at gmail.com
Mon Jan 14 23:18:03 PST 2013


Hi,

you should probably use r.region [1], not g.region [2]:
g.region rast=... sets the computational region to match the raster map
r.region map=... sets the boundary of a raster map

Regards,
Anna

[1] http://grass.osgeo.org/grass64/manuals/r.region.html
[2] http://grass.osgeo.org/grass64/manuals/g.region.html

On Tue, Jan 15, 2013 at 1:53 AM, Gökçen Güner <gokcenguner at gmail.com> wrote:
> Hi,
> I want to change North, East, South and West extent values of a raster map
> using python. In GUI I've used g.region function like this:
>
> g.region -g -a rast=band1_2005_etm at PERMANENT n=4256115 s=4045185 e=831315
> w=601785
> n=4256115
> s=4045185
> w=601785
> e=831315
>
> As you see what I got is what I set. But I couldn't do the same in python:
>
> def loadMap(inputMapPath, outBandName):
>     mapLoaded = grass.run_command('r.in.gdal', input=inputMapPath,
> output=outBandName, flags='o', overwrite=True)
>     if(mapLoaded == 0):
>         print "Map Loaded From " + inputMapPath + " to " + outBandName
>     else:
>         print "ERROR: Map Loaded From " + inputMapPath + " to " +
> outBandName
>     regionizeMap(outBandName)
>     print ""
>
> def regionizeMap(bandName):
>     mapRegionized = grass.run_command('g.region', rast=bandName, n=4256115,
> s=4045185, e=831315, w=601785, flags='a', overwrite=True)
>     if(mapRegionized == 0):
>         print "Map Regionized: " + bandName
>     else:
>         print "ERROR: Map Regionized: " + bandName
>     print ""
>
> def showRegionInfo(bandName):
>     r = grass.read_command('g.region', rast=bandName, flags='g',
> verbose=True)
>     print bandName
>     print r
>     print ""
>
> The output is:
>
> Map Loaded From D:\gis\data\l71175034_03420050627_b10histeqmatched.tif to
> band1_2005_etm
> Map Regionized: band1_2005_etm
>
>
> band1_2005_etm
> n=4257015
> s=4043385
> w=601785
> e=844215
>
> You can see the differnce here, I set east to 831315 but what i got is
> 844215. What can I do the achieve same result with GUI?
> Thanks in advance.
>
> _______________________________________________
> 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