Code Monkey home page Code Monkey logo

zonalstats's Introduction

ZonalStats : use scipy.ndimage for zonal stats of raster images

Zonal Statistics is a common function in summarizing data for subregions in a area of interest. The procedure ususally involves two dataset:

  • a raster layer (single band) with the data value to aggreate, and
  • a shapfile with sub-region information as polygons.

One straight forward idea is to loop through each polygon features to get the summary statistics , and this process can be extremely slow when the data size getting big(`・⊝・´ ). Here I utilize scipy function ndimage to speed up the process.

First, you have to convert the shapefile to image of the same size and resolution as the raster. This step is super easy since we have the awesome gdal_rasterize function. Here comes an simgple way using gdal_rasterize to generate a shapefile for you:

gdal_rasterize -tr 30 30 -te -379800.000 -603780.000 538230.000 450450.000 -a id -of  GTiff -a_srs EPSG:3310 training.shp training.tif

where -tr spefify the x and y resolution -te specify the xmin ymin xmax ymax -a the field the raster pixel value be based on -of data format, GTiff is actually the default -a_srs overwirte the original projection, DO NOT USE if you're not sure it correct

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.