Data Analysis using Python-I

Slides:



Advertisements
Similar presentations
Geoprocessing with GDAL and Numpy in Python Delong Zhao
Advertisements

Baburao Kamble (Ph.D) University of Nebraska-Lincoln Data Analysis Using R Week3: Data Input/Output (Import/Export) in R.
UGIC 2009 Introduction to Open Source RS/GIS programming with Python Chris Garrard RS/GIS Laboratory Utah State University.
With support from: NSF DUE in partnership with: George McLeod Prepared by: Geospatial Technician Education Through Virginia’s Community Colleges.
GIS Matthew Rosencrans Tom DiLiberto. Outline What is GIS? What can we do with it? What data can we work with?
Raster Data. The Raster Data Model The Raster Data Model is used to model spatial phenomena that vary continuously over a surface and that do not have.
CS 128/ES Lecture 5a1 Raster Formats (II). CS 128/ES Lecture 5a2 Spatial modeling in raster format  Basic entity is the cell  Region represented.
NR 422: GIS Review Jim Graham Fall What is GIS? Geographic Information System? Geographic Information Science? A system that provides the ability.
SuperPad 3 Full-Function Mobile GIS Software. Overview  SuperPad, full-function mobile GIS software, is designed for field survey and data collection.
Introduction to GIS and Data Francisco Olivera, Ph.D., P.E. Department of Civil Engineering Texas A&M University.
Marine GIS Applications using ArcGIS Global Classroom training course Marine GIS Applications using ArcGIS Global Classroom training course By T.Hemasundar.
Esri International User Conference | San Diego, CA Technical Workshops | Lidar Solutions in ArcGIS Clayton Crawford July 2011.
ESRM 250 & CFR 520: Introduction to GIS © Phil Hurvitz, KEEP THIS TEXT BOX this slide includes some ESRI fonts. when you save this presentation,
ESRM 250 & CFR 520: Introduction to GIS © Phil Hurvitz, KEEP THIS TEXT BOX this slide includes some ESRI fonts. when you save this presentation,
Rebecca Boger Earth and Environmental Sciences Brooklyn College.
CE 525 1/17/2013. Quiz #3 Question 1 You look in the phone book and see names associated with phone numbers. Is this geographic data?
Intro. To GIS Lecture 4 Data: data storage, creation & editing
Spatial data models (types)
GIS1: Overview of GIS and Visualization with Maps
Geospatial Data Abstraction Library (GDAL) Enhancement for ESDIS (GEE) Increasing Accessibility and Interoperability of NASA Data Products with GIS Tools.
ABT 182 / HYD 182 Environmental Analysis using GIS Week 7-1 More GDAL & OGR.
Geospatial Development with Python
Major parts of ArcGIS ArcView -Basic mapping, editing and Analysis tools ArcEditor -all of ArcView plus Adds ability to deal with topological and network.
GIS Data Structure: an Introduction
The IRI Climate Data Library: translating between data cultures Benno Blumenthal International Research Institute for Climate Prediction Columbia University.
Introduction to ArcView NPS Introduction to GIS: Lecture 2 Based on NINC, ESRI and Other Sources.
How do we represent the world in a GIS database?
The world of RASTER data Modeling... Elevation....etc. The Spatial Analyst Extension.
GDAL/OGR. GDAL/OGR GDAL/OGR : Frank Warmerdam Tools for reading, writing, and processing GDAL - Geospatial Data Abstraction Library GDAL - Geospatial.
A.Batchimeg GDAL Geospatial Data Abstraction Library GDAL Geospatial Data Abstraction Library
Raster Concepts.
CFR 250/590 Introduction to GIS, Autumn D Analysis & Surface Modeling © Phil Hurvitz, vector_analysis_1.ppt 1  Overview 3D Analysis &
Graphics workshop Library and Information Services University of St Andrews.
Copyright © 2006 by Maribeth H. Price 15-1 Chapter 15 Raster Analysis.
GIS Data Structures How do we represent the world in a GIS database?
LDOPE QA Tools Sadashiva Devadiga (SSAI) MODIS LDOPE January 18, 2007.
INTRODUCTION TO GIS  Used to describe computer facilities which are used to handle data referenced to the spatial domain.  Has the ability to inter-
U.S. Department of the Interior U.S. Geological Survey Automatic Generation of Parameter Inputs and Visualization of Model Outputs for AGNPS using GIS.
How To configure GDAL. 2 What is GDAL? GDAL is a translator library for raster and vector geospatial data formats that is released under an X/MIT style.
Spatial Data Models Geography is concerned with many aspects of our environment. From a GIS perspective, we can identify two aspects which are of particular.
Kurt Menke, GISP Quantum GIS (QGIS) Plugins. Extending QGIS Plugins Think ArcGIS extensions and script tools Core Plugins Core Plugins Contributed Plugins.
Geoprocessing and georeferencing raster data
GeoServer Prof. Wenwen Li School of Geographical Sciences and Urban Planning 5644 Coor Hall
GIS Data Shape files, Rasters, Coordinate Systems, ArcGIS.
Geospatial Data Abstraction Library(GDAL) Sabya Sachi.
Bob Bruce, P.Eng Mapping and Lands Branch, Manitoba Conservation A Survey of Open Source Geospatial Software APEGM PD Breakfast.
Each entity of land has spatial information!
Multimedia Subject: Informatics of Technology II year
Extending ArcGIS via programming
Chapter 8 Raster Analysis.
Geoinformatics tools with Perl: integration, development, needs
GEOGRAPHICAL INFORMATION SYSTEM
INTRODUCTION TO GEOGRAPHICAL INFORMATION SYSTEM
Desktop ArcGIS GIS File Types
LAND COVER CLASSIFICATION WITH THE IMPACT TOOL
Spatial Models – Raster Stacy Bogan
Digital Data Format and Storage
Introduction to GIS.
Lecture 22: Using ArcToolbox Tools in Python
National Scientific Library at Tbilisi State University
Spatial Analysis: Raster
Data Analysis using Python-I
Elaine B. Darby GIS – Fall 2005
Preparing raster files for Condatis
Introduction to ArcGIS
Fourth Year – Software Engineering
Raster Data Analysis.
Lecture 2 Components of GIS
Spatial Analysis: Raster
Mapping packages Unfortunately none come with Anaconda (only geoprocessing is which does lat/long to Cartesian conversions). matplotlib.
Presentation transcript:

Data Analysis using Python-I Baburao Kamble and Ayse Kilic University of Nebraska-Lincoln University of Nebraska-Lincoln GIS in Water Resources Lecture, 2014

Objectives To be able to understand and write Python scripts 9/17/2018 Objectives To be able to understand and write Python scripts Numerical, Text (Weather) &Geospatial (Environmental) data manipulation

Agenda Part I: Basic Python Programming 9/17/2018 Agenda Part I: Basic Python Programming Python Syntax, Strings, Array, Conditional and Control flow, Functions File Input/Output and Text Data Processing Part II: Geospatial Data Analysis Installation of GDAL bindings on windows operating system Reading Raster (Landsat and DEM) data Using GDAL function from command line (interpolation, translation) Raster Processing. NDVI calculation DN2Rad2Ref

Why use GDAL/NumPy instead of canned GIS software? Not advisable if what you want to do is easily handled within ArcGIS/Imagine/etc. – there is a lot of programming overhead Well suited for process model applications where the logic at a cell based is too complex Example: Grid algebra : grid1 + grid2 (probably use GIS) Finding NN in multidimensional space (maybe use GDAL/Numpy) Also useful if your spatial data is NOT standard GIS formats (JPEG, PNG, etc.)

Geoprocessing with GDAL and Numpy in Python GDAL - Geospatial Data Abstraction Library Numpy - the N-dimensional array package for scientific computing with Python. Both of them are open source software Read raster dataset using GDAL Do some calculation using Numpy Output to geospatial dataset using GDAL

Python Libraries for Geospatial Development There are two popular Python libraries for raster and vector data: GDAL (Geospatial Data Abstraction Library) Is for raster-based geospatial data; aailable for download at: http://gdal.org Windows user use Frank Warmerdam’s “FWTools” open source GIS binaries for Windows (32 bit); available at: http://fwtools.maptools.org # includes gdal and ogr OGR Is for vector-based geospatial data and is available for download at: http://gdal.org/ogr NOTE: These are now merged together and are downloaded together under the common name GDAL

GDAL (Geospatial Data Abstraction Library) Presents an “abstract data model” for processing spatial data Can be used directly from C/C++ and can be “wrapped” for use with Python, Perl, VB, C#, R, Java … Early developers have chosen Python as their scripting language and documentation is relatively good for this.

GDAL Geospatial Data Abstraction Library Raster data access UGIC 2009 GDAL Geospatial Data Abstraction Library Raster data access Supports about 100 different formats ArcInfo grids, ArcSDE raster, Imagine, Idrisi, ENVI, GRASS, GeoTIFF HDF4, HDF5 USGS DOQ, USGS DEM ECW, MrSID TIFF, JPEG, JPEG2000, PNG, GIF, BMP

NumPy (Numerical Python) An array/matrix package for Python Well suited for image processing – i.e. one function can operate on the entire array Slicing by dimensions and applying functions to these slices is concise and straightforward Nearly 400 methods defined for use with NumPy arrays (e.g. type conversions, mathematical, logical, etc.)

GDAL and NumPy Since GDAL 1.3(?), GDAL has implemented NG (New Generation) Python bindings which includes NumPy Process: Get raster band(s) Convert the raster band(s) to a NumPy array using ReadAsArray() Open GDALDataset Write out GDALDataset Process the raster band(s) using NumPy functionality Convert the NumPy array to GDAL raster bands using WriteAsArray()

GDAL GDAL installation 9/17/2018 GDAL GDAL installation Make sure NumPy is installed (http://sourceforge.net/projects/numpy/files/) Download gdalwin32exe160.zip from http://download.osgeo.org/gdal/win32/1.6/ Unzip to C:\gdalwin32-1.6

Test Your GDAL in Python 9/17/2018 Test Your GDAL in Python

GDAL Supports more than 100 raster formats 9/17/2018 GDAL Supports more than 100 raster formats http://www.gdal.org/formats_list.html Finding available formats gdalinfo --formats

GDAL Data Model GDAL’s data model includes: Dataset, which hold the raster data in a collection of raster bands Raster Band: represents a band, channel, or layer within an image (e.g., RGB image has red, green, and blue components of the image) Raster size: specifies the width of the image in pixels and overall height of the image in lines Georeferencing transform converts from x,y coordinates into georeferenced coordinates (on the surface of Earth) Affine transformation mathematical formula allowing operations such as X offset, Y offset, X scale, Y scale, horizontal shear, vertical shear Coordinate system includes the projection and datum Metadata provide additional information about the dataset

GDAL example Python code Use GDAL to calculate the average of the height values contained in a DEM: from osgeo import gdal, gdalconst dataset = gdal.Open(”DEM.dat”) band = dataset.GetRAsterBand(1) fmt= “<“ + (“h” * band.XSize) totHeight = 0 for y in range (band.Ysize): scanline = band.ReadRaster (0, y, band.Xsize, 1, band.Xsize, 1, band.DataType) values = struct.unpack(fmt, scanline) for value in values: totHeight = totHeight + value average = totHeight / (band.xSize * band.YSize) print “Average height = “, average

OGR Datasource: represents the file (e.g., a country), has many: Layers: sets of related data, e.g., terrain, contour lines, roads layers Spatial reference: specifies datum and projection Attributes: additional metadata about the feature Geometry: specifies the shape and location of the feature. Are recursive, i.e., can have sub-geometries

OGR example Python code import osgeo.ogr from osgeo import ogr shapefile = ogr.Open(“TM_WORLD_BORDERS-0.3.shp”) layer = shapefile.GetLayer (0) for i in range (layer.GetFeatureCount()): feature = layer.GetFeature(i) name = feature.GetField(“NAME”) geometry = feature.GetGeometryRef() print i, name, geometry.GetGeometryName()

Sample 1 Read two tif files (red band and nir band) Calculate Output NDVI in same projection and georeference as the input file. Numpy example

Raster File input/output 9/17/2018 Raster File input/output read_raster.py read_Write_raster_in_Block.py NDVI.py DN2rad2ref.py

GDAL Command Line Utilities 20202020 GDAL Command Line Utilities gdalinfo - report information about a file. gdal_translate - Copy a raster file, with control of output format. gdaladdo - Add overviews to a file…pyramids gdalwarp - Warp an image into a new coordinate system. gdal_contour - Contours from DEM. gdaldem - Tools to analyze and visualize DEMs. rgb2pct.py - Convert a 24bit RGB image to 8bit paletted. pct2rgb.py - Convert an 8bit paletted image to 24bit RGB. dal_merge.py - Build a quick mosaic from a set of images. gdal_rasterize - Rasterize vectors into raster file. gdaltransform - Transform coordinates. nearblack - Convert nearly black/white borders to exact value. gdal_grid - Create raster from the scattered data. gdal_polygonize.py - Generate polygons from raster. gdal_sieve.py - Raster Sieve filter. gdal_fillnodata.py - Interpolate in nodata regions. gdal-config - Get options required to build software using GDAL.