![]() ![]() When dealing with large grids, reading raster data in blocks rather than as a whole is advisable, because there may not be enough RAM to store an entire file at once. Reading and processing raster data does have its challenges. The use of a NumPy array to iterate through the grid cells was found in an answer by user “gene” on GIS StackExchange. The code was written and tested for QGIS 2.6 feedback on any issues is most welcome. This post focuses on the functionality of the program, while its inner workings can be grasped from comments in the Python source code posted at. X.style = “path\\to\\qml\\style\\file.qml” # Cycle 5 times and display every 2nd cycle Some other interesting features include changing animation speed, jumping cycles, and applying customized layer styles: # Adjust delay to 3 seconds X = GameofLife(raster="path\\to\\raster\\file.tif")ĭate source: City of Toronto Open Data # Instantiate a starting board with a raster X = GameofLife(raster="path\\to\\customraster\\file.tif") # Instantiate a starting board with the custom raster Y.toRaster("path\\to\\customraster\\file.tif") # Create a raster with the custom cells object in the directory # Generate a raster from a list of tuples X = GameofLife(raster="path\\to\\filledraster\\file.tif") # Instantiate a starting board with the filled raster Y.toRaster("path\\to\\filledraster\\file.tif") ![]() # Create a raster with the filled cells object in the directory The gaming board may be initialized with a random raster, a filled raster, a custom raster, or from a pre-defined raster file: # The default is a random raster, we can set the width and height as well Let’s start by initializing and cycling a gaming board using default parameters: # Instantiate a starting board The core function is the manipulation of individual raster cells based on a coded algorithm – in this case, the rules defined by the Game of Life. Our implementation takes an object-oriented approach, in which an object of a Game of Life class is instantiated and the gaming board is updated with the cycle() method using the QGIS python console. The project was inspired by Anita Graser’s visit to Ryerson’s Lab for Geocomputation in October 2014, during which Anita developed a vector-based version of the Game of Life in QGIS (see ). ![]() The source code was written by Master of Spatial Analysis student Richard Wen with input from Dr. Using NumPy, GDAL, and pyQGIS, we implemented the Game of Life, where NumPy manipulates the arrays, GDAL handles reading and writing of the raster data, and pyQGIS visualizes the rasters and their relative changes. The Geospatial Data Abstraction Library (GDAL) is a library for translating raster and vector geospatial data formats available as a binding for Python. Numerical Python (NumPy) is a package developed for Python that is geared towards scientific computation with support for multi-dimensional arrays and matrices. The free and open-source Geographic Information System (GIS) software package QGIS offers support for scripting with the Python programming language (pyQGIS module), which enables the use of powerful libraries such as NumPy and GDAL for dealing with raster data. A dead cell with three live neighbours becomes alive (reproduction).A live cell with two or three live neighbours continues to live.A live cell with less than two or more than three live neighbours dies (under-population, overcrowding).At each iteration of the game clock, the following rules are applied : Each cell interacts with its eight adjacent neighbours to determine its next state. The “game” starts with a grid (“board”) of binary cells, which represent either alive (populated) or dead (empty) states. ![]() Blog post authored by Richard Wen and Claus RinnerĪ great way to demonstrate the manipulation of geospatial raster data is Conway’s Game of Life. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |