Posts

Showing posts with the label Raster

Getting started with Raster and PostGIS - I

Image
Steps for loading a raster in PostGIS (PgSql 9.4/ PostGIS 2.2) and pull it from database to view in QGIS 2.14.17. 1. Generate SQL for raster [NOTE: Do not create PostGIS table name starts with underscore, it creates problem while adding raster to QGIS from PostGIS database using DB Manager]         raster2pgsql -s 4326 -I -C -M -F -t 50x50 -N nan biodiv_ssolnw.tif > biodiv_ssolnw.sql 2. Import generated raster into PostGIS database [Make sure to enable postgis extension in db]          psql -h localhost -U postgres -d ecolservicedb -f biodiv_ssolnw.sql the output is: Processing 1/1: ags_473038164.tif BEGIN CREATE TABLE INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 … … …. CREATE INDEX ANALYZE NOTICE:  Adding SRID constraint CONTEXT:  PL/pgSQL function addrasterconstraints(name,name,name,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean) line 53 at RETURN...

Read a raster file into an Array using C# and GDAL

If you are creating a new project- set up GDAL & C# environment as described  here Code snippet: Read raster into an Array using GDAL and C# //Register all drivers Gdal.AllRegister(); //Read dataset Dataset rasterDataset = Gdal.Open("rasterName.tif", Access.GA_ReadOnly); if (rasterDataset == null) { Console.WriteLine("Unable to read input raster.."); System.Environment.Exit(-1); } //raster bands int bandCount = rasterDataset.RasterCount; if (bandCount > 1) { Console.WriteLine("Input error, please provide single band raster image only.."); System.Environment.Exit(-1); }

Clip a raster with shapefile using C# and Gdal

Image
Over the week, I stumbled on problem clipping raster with feature using C# and Gdal and come up with following solution, which clips the features and fills no data value for missing raster  values inside the extent. If you are creating a new project- set up GDAL & C# environment as described  here