Oft-cuttile.pl

From Open Foris Wiki

Jump to: navigation, search

Cuts image tiles on the basis of a given list of locations. The script :

  1. converts the point locations into the projection of the image,
  2. cuts a set of 20 km x 20 km tiles around the locations
  3. converts the tiles to the coordinate system of the points


Usage: oft-cuttile.pl <coord_list> <CRS_file> <input_dir> <output_basename>

  • <coord_list> is a text file containing the coordinates of the center of the tiles. It must arranged as id x y
  • <CRS_file> is a text file containing the projection definitions of the dataset in PROJ4 format.
  • <input_dir> is the directory containing the image. Image must be in geotiff format, extension must be .TIF with capitals.
  • <output_basename> is the base name of the tiles that will be generated


Exercise:

  • Open your working directory using
cd /home/.../OFGT-data

1. First, you need to convert the imagery into .TIF format. You can use the gdal_translate function to convert the input imagery from any gdal supported format to TIF using the option [-of GTiff].

gdal_translate -of GTiff images/landsat_t1.tif results/landsat_t1.TIF

2. In the next step we take a closer look at our additional input data coordinates.txt and proj.txt.

  • coordinates.txt is a space separated text file with 3 columns: ID, X_coordinates and Y_coordinates. Create it by typing
gedit results/coordinates.txt 

Then copy paste the following list and save your file.

1 767360 -2415219
2 755310 -2378377
3 781072 -2379346
4 789936 -2440150
  • proj.txt must contain one line with the projection definition of the tiles coordinates and one line with the projection definition of the imagery. Here it is UTM zone 20, for both, with the following proj4 format:
+init=epsg:32620 +proj=utm +zone=20 +datum=WGS84 +units=m +no_defs +ellps=WGS84

Create the file

gedit results/proj.txt

Paste the projection definition twice, as two separate lines. Save proj.txt

+init=epsg:32620 +proj=utm +zone=20 +datum=WGS84 +units=m +no_defs +ellps=WGS84
+init=epsg:32620 +proj=utm +zone=20 +datum=WGS84 +units=m +no_defs +ellps=WGS84

NB: If you do not have it, you can get the PROJ4 format of an image by using the function cs2cs.

cs2cs -v +init=epsg:32620

If you don't know the EPSG code of your image, use gdalinfo for your imagery:

gdalinfo landsat_t1.TIF

3. Now we run the actual script to create the tiles in the terminal.

cd results
oft-cuttile.pl coordinates.txt proj.txt . Tiles


The four tiles overlayed on base image, displayed with differing band composition to base imagery.



Back to Open Foris Toolkit Main Page

Back to Tools & Exercises



Personal tools