{ "metadata": { "name": "", "signature": "sha256:abc27b8651e5bbf4b8ebf95fe8b1cbd00876ec440a13a0a80364382150042917" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "GISDBASE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The GISDBASE is a directory with the structure used by GRASS GIS to store the data, it contain at least a LOCATION" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from grass.pygrass.gis import Gisdbase" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "gisdb = Gisdbase()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "gisdb.name" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "gisdb.locations()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "LOCATION" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The LOCATION is some geographic extent of interest that contains data sets that [should] all be in the **same coordinate system**. " ] }, { "cell_type": "code", "collapsed": false, "input": [ "from grass.pygrass.gis import Location\n", "\n", "Location()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "gisdb['loc_ncarolina_spm_base0.3.1']" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "northc = gisdb['loc_ncarolina_spm_base0.3.1']" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "northc.gisdbase" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "northc.name" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "northc.mapsets()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "MAPSET" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In a MAPSET you can organize GIS maps thematically or geographically or by project or whatever. Every GRASS session runs under the name of a MAPSET. A MAPSET may be a geographical subset or as large as the parent LOCATION. " ] }, { "cell_type": "code", "collapsed": false, "input": [ "from grass.pygrass.gis import Mapset\n", "\n", "Mapset()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "northc['user1']" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "# fails for simlink (on the live PERMANENT is a simlink to a different directory)\n", "#\n", "#permanent = northc['PERMANENT']" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "northc = northc['user1']" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "northc.gisdbase" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "northc.location" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "northc.name" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "northc.glist('raster')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "%timeit Mapset('user1').glist('raster')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "from grass.script import core as gcore" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "gcore.list_grouped('rast')['user1']" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "%timeit gcore.list_grouped('rast')['user1']" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "Mapset('user1').glist('raster', pattern='el*')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Region" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The REGION may be the entire area or subset of the chosen LOCATION. It is defined by northern, southern, eastern, and western bounds, as well as the raster grid resolution. It is controlled by the g.region module and is of primary importance for raster operations" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from grass.pygrass.gis.region import Region" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "reg = Region()\n", "reg" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "reg.items()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "reg.north" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "reg.ewres" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "reg.get_bbox()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "#!g.region --help" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "raw", "metadata": {}, "source": [ "# the following fails (traceback attached below)\n", "\n", "with Region(nsres=100., ewres=100.) as region:\n", " print(region.items())\n", "print(Region().items())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```\n", "---------------------------------------------------------------------------\n", "TypeError Traceback (most recent call last)\n", " in ()\n", "----> 1 with Region(nsres=100., ewres=100.) as region:\n", " 2 print(region.items())\n", " 3 print(Region().items())\n", "\n", "TypeError: __init__() got an unexpected keyword argument 'nsres'\n", "```" ] }, { "cell_type": "code", "collapsed": false, "input": [ "Region.nsres=100.\n", "Region.ewres=100." ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "Region()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Bbox" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Is a element of pygrass to create a Bounding Box, it use a GRASS GIS C structure" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from grass.pygrass.vector.basic import Bbox\n", "from grass.pygrass.vector.geometry import Point" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "bbox = Bbox()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "bbox" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "bbox.north = 10\n", "bbox.east = 10" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "point = Point(5, 5)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "bbox.contains(point)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Summary" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We have seen:\n", "\n", "* GISDBASE, LOCATION and MAPSET classes to work with the GRASS GIS file structure\n", "* REGION element to obtain informations about GRASS GIS Region and work with it\n", "* Bbox class to work with bounding box" ] } ], "metadata": {} } ] }