Giter VIP home page Giter VIP logo

raster_cutting's Introduction

raster_cutting

Cut raster for each features in a vector layer

Google colab version

Just clone and run =))

https://colab.research.google.com/gist/soiqualang/2643abe44b6df2c73059762c1aaa25ed/raster_cutting_colab_gui_v2.ipynb#forceEdit=true&sandboxMode=true

Thông tin thêm về Google colab

https://dothanhlong.org/ipython-jupyter-notebook-va-google-collaboratory/

Local install version

Require

  • Python with GDAL installed
  • Path to bin folder of QGIS. Ex C:/Program Files/QGIS 2.18/bin/

You can install python GDAL by wheel package I downloaded

  • For Python 3.6 - 64 bit GDAL-2.4.1-cp36-cp36m-win_amd64.whl
  • For Python 3.6 - 32 bit GDAL-2.4.1-cp36-cp36m-win32.whl

Install wheel pip install GDAL-2.4.1-cp36-cp36m-win32.whl

SQlite version (Easier to config)

t1_sqlite.py

Config

fbin='C:/Program Files/QGIS 2.18/bin/'
rasterFile='C:/Users/soiqu/Desktop/raster_cutting/input/DBSCL_20180611_NSS.tif'
fout='C:/Users/soiqu/Desktop/raster_cutting/output/'
dbName='dbscl.sqlite'
#Vector table (layer) name
tblName='dbscl'
#Column name which used as condition to define each feature (ex. each province in dbscl layer)
dkCol='ten_eng'

Run script

  • Download and cd to this folder
  • Copy your raster file and sqlite vector layer to this folder
  • Config file t1_sqlite.py depending on your project
  • Run python t1_sqlite.py

PostgreSQL version

t1_pgsql.py

Config

fbin='C:/Program Files/QGIS 2.18/bin/'
rasterFile='C:/Users/soiqu/Desktop/raster_cutting/input/DBSCL_20180611_NSS.tif'
fout='C:/Users/soiqu/Desktop/raster_cutting/output/'
databaseServer = "localhost"
databaseName = "raster_cutting"
databaseUser = "postgres"
#Your password to login PostgreSQL
databasePW = "******"
#Your PostgreSQL port (defaul is 5432)
databasePort = "5433"
connString = "PG: host=%s dbname=%s user=%s password=%s port=%s" % (databaseServer,databaseName,databaseUser,databasePW,databasePort)
#Vector table (layer) name
tblName='dbscl'
#Column name which used as condition to define each feature (ex. each province in dbscl layer)
dkCol='ten_eng'

Run script

  • Download and cd to this folder
  • Copy your raster file and sqlite vector layer to this folder
  • Config file t1_pgsql.py depending on your project
  • Run python t1_pgsql.py

How to get SQLite file

You can export it from Shapefile by QGIS

Todo

  • Loop all rasters in a folder to cut
  • Make a version run on Linux (Google Colab)

Preferences

gdalwarp "C:/Program Files/QGIS 2.18/bin/gdalwarp" -cutline dbscl.sqlite -csql "select * from dbscl where ten_eng='Tra Vinh'" -crop_to_cutline -of GTiff -dstnodata -9999.0 -overwrite "DBSCL_20180611_NSS.tif" "C:/Users/soiqu/Desktop/raster_cutting/output/out_Tra Vinh.tif"

Subprocess http://queirozf.com/entries/python-3-subprocess-examples

Cut multi GeoTif in folder by a shapefile layer

raster_cutting_tiff_folder.py

Download raster_cutting_tiff_folder.py

Config folder raster, folder shapefile, folder output

Run tool with QGIS

Open Python Console in QGIS

Open file raster_cutting_tiff_folder.py in Python Console

Run tool and results

raster_cutting's People

Contributors

soiqualang avatar

Watchers

 avatar  avatar

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.