Oft-sigshp.bash

From Open Foris Wiki

Jump to: navigation, search

Creates a signature file of an image, e.g. Landsat, based on training area polygons in shapefile format. This file can be used in knn-classification with stand alone program oft-nn.

Usage:

  • oft-sigshp.bash <image> <shapefile_basename> <shapefile_id_fieldname> <shapefile_coverclass_fieldname> <ouput_sigfile>
  • oft-sigshp.bash <image> <shapefile_basename> <shapefile_id_fieldname> <shapefile_coverclass_fieldname> <ouput_sigfile> <image_projection_EPSG> <shp_projection_EPSG>


Either 5 or 7 parameters are needed, latter in the case your shapefile is in a different projection from the image file.

1 = imagefile
2 = shapefile
3 = field name storing id's in shape
4 = field name storing numeric class values in shape
5 = ouput signaturefilename
Options:
6 = projection of image file (optional)
7 = projection of shapefile (optional)

NOTE: do not put .shp into the second parameter (basename)!

Examples:

oft-sigshp.bash p165r66.tif covers ID TYPE_ID sigs.txt
oft-sigshp.bash p165r66.tif covers ID TYPE_ID sigs.txt EPSG:32637 EPSG:4326

Details:

  • The training areas and the image must be in the same projection OR you may give the projections in the command line as EPSG codes.
  • If the projections are not defined (for both or one of the inputs), or the program does not recognize it, the script will warn you. This is not dangerous if the files really are similarly aligned.
  • The ID's must fit into a 16-bit Unsigned image (~ 65500).
  • The class values may be either numerical or verbal (e.g. "bushland")


Exercise:

  • Get Example data set
  • For this exercise following tools are used: oft-sigshp.bash
  • Open your working directory using
cd /home/...

The script oft-sigshp.bash is able to create a signature file for both data types, numerical and factorial, depending on the stored data in your shapefile. In the next steps we will lead you through an example exercises for each data type:

Attribute table of landuse.shp.


1. oft-sigshp.bash creating signature file with numerical values

  • First, we run in the command line oft-sigshp.bash with the input raster landsat_t1.tif and your input shapefile landuse.shp. id stands for the shapefile_id_fieldname; newcol refers to the shapefile coverclass fieldname. If you look at the attribute table of your landuse.shp you will see that under newcol numerical data is stored. Output: file sig_newcol.txt.

Note: the extension .shp of your shapefile is not included in the command line - only the basename!

  • Run in terminal:
oft-sigshp.bash landsat_t1.tif landuse id newcol sig_newcol.txt EPSG:32620 EPSG:32620
  • Lets take a look at the first lines of our output sig_newcol.txt:
head sig_newcol.txt
1 11 52.097317 23.696463 24.919711 45.321753 65.427785 129.033459 32.060358 
2 22 54.157159 25.348832 28.176561 48.805278 72.468158 129.166550 34.397944 
4 44 53.864419 25.231642 27.932243 51.411361 71.957973 129.559346 33.277298 
5 55 54.367835 25.734659 28.453136 53.725893 74.190155 130.886716 36.174309 
6 66 50.987633 23.044892 23.452312 52.655091 65.861426 128.754701 29.121125 
7 -9999 52.926014 24.353222 27.224344 48.176611 77.276850 132.054893 38.276850 
8 88 54.133652 25.214797 28.140811 49.842482 74.985680 131.004773 37.408115 
9 99 54.772519 25.961832 29.036641 52.786260 78.035115 130.658015 39.607634 
10 1000 51.588723 23.134328 24.255390 45.487562 68.208955 130.310116 33.121061 
11 1111 53.236948 24.644578 27.423695 48.779116 68.943775 131.594378 33.905622 
  • The first column refers to the ID, col2 refers to the numerical data that stored under newcol in the shapefile, Col3 - col9 contain pixel values of band1 - band7 of the Landsat imagery.


2. oft-sigshp.bash creating signature file with factorial values

  • second, we run the script using the id column called colour, which stores factorial values. Output: sig_colour.txt. Output signature file: sig_colour.txt.
  • Run in terminal:
oft-sigshp.bash landsat_t1.tif landuse id colour sig_colour.txt EPSG:32620 EPSG:32620
  • Again let's take a closer look at the first lines of the output file sig_colour.txt:
head sig_colour.txt
1 red 52.097317 23.696463 24.919711 45.321753 65.427785 129.033459 32.060358 
2 green 54.157159 25.348832 28.176561 48.805278 72.468158 129.166550 34.397944 
4 orange 53.864419 25.231642 27.932243 51.411361 71.957973 129.559346 33.277298 
5 pink 54.367835 25.734659 28.453136 53.725893 74.190155 130.886716 36.174309 
6 red 50.987633 23.044892 23.452312 52.655091 65.861426 128.754701 29.121125 
7 blue 52.926014 24.353222 27.224344 48.176611 77.276850 132.054893 38.276850 
8 orange 54.133652 25.214797 28.140811 49.842482 74.985680 131.004773 37.408115 
9 green 54.772519 25.961832 29.036641 52.786260 78.035115 130.658015 39.607634 
10 orange 51.588723 23.134328 24.255390 45.487562 68.208955 130.310116 33.121061 
11 red 53.236948 24.644578 27.423695 48.779116 68.943775 131.594378 33.905622 
  • In comparison to the output of sig_newcol.txt we can now see that col2 of sig_colour.txt contains the factorial data.



Back to Open Foris Toolkit Main Page

Back to Tools & Exercises



Personal tools