from IPython.core.display import Image

"""
Explanation: <h1><center>[Notebooks](../) - [Access to Geospatial data](../Access to Geospatial data)</center></h1>

OSSIM Command Line Applications
The following command line applications are distributed with OSSIM.
Core Programs

ossim-info Used to run ossim utilities function and to display metadata for imagery, maps, terrain, and vector data.
Utility functions
radians from degrees
degrees from radians
meters from feet
meters to feet
Meters per degree
height
Projections
Datums


Explore raster data
ground center
image center
ground and image center
general image information
meta data image information
image projection information
image rectangle





Utilities to Create Support Files
The following tools are used to create OSSIM support files:

ossim-img2rr Create reduced resolution data sets for an image.
ossim-cmm Determine the min/max pixel values of an image.
ossim-create-histo Compute a histogram for an image.
ossim-img2md Create meta data files.
ossim-tfw2ogeom Create a geom file from a TIFF World File.
ossim-extract-vertices Compute the valid vertices (corners) of an image.
ossim-preproc Create reduced resolution data sets, histograms, and so on. Application does directory walking and is threaded at a file level.
ossim-applanix2ogeom Create a geom file for Applanix Images.
ossim-create-cg Create an ossim coarse grid.
ossim-ecg2ocg Convert an enhanced coarse grid to an ossim coarse grid.


OSSIM-Applications

ossim-band-merge Merge multiple image files into a single n-band dataset.
ossim-chipper Render elevation data (e.g. shaded relief).
ossim-icp Convert an image from one format to another.
ossim-igen Execute image chains specified in a spec file.
ossim-orthoigen Tool to orthorectify, mosaic, and convert raster data between different formats. It provides a number of operations including subsetting, resampling, histogram matching, and reprojection of data.

ossim-rpf Various utilities for managing RPF data.


Import IPython utility to display images
End of explanation
"""


DATADIR='/home/main/notebooks/data/landsat/'

# we'll use the north_carolina image dataset
!ls {DATADIR} | grep tif 

"""
Explanation: Set the PATH to the natural earth dataset used in this notebook
End of explanation
"""


!ossim-info

"""
Explanation: ossim-info
top
End of explanation
"""


!ossim-info --deg2rad 20.54

"""
Explanation: Utility functions
radians from degrees
ossim-info --deg2rad &lt;degrees&gt;
End of explanation
"""


!ossim-info --rad2deg 0.35849

"""
Explanation: top
degrees from radians
ossim-info --rad2deg &lt;radians&gt;
End of explanation
"""


!ossim-info --ft2mtrs 1

"""
Explanation: top
meters from feet


0.3048 meters per foot
ossim-info --ft2mtrs &lt;feet&gt;
End of explanation
"""


!ossim-info --ft2mtrs-us-survey 1

"""
Explanation: 0.3048006096 meters per foot
ossim-info --ft2mtrs-us-survey &lt;feet&gt;
End of explanation
"""


!ossim-info --mtrs2ft 1

"""
Explanation: top
meters to feet


0.3048 meters per foot
ossim-info --mtrs2ft &lt;meters&gt;
End of explanation
"""


!ossim-info --mtrs2ft-us-survey  1

"""
Explanation: 0.3048006096 meters per foot
ossim-info --mtrs2ft-us-survey  &lt;meters&gt;
End of explanation
"""


# note we pass the path to the ossim_preference file to tell where the geoid file is
!ossim-info --height 47.54 157.40 -P /usr/local/share/ossim/ossim_preference

"""
Explanation: top
height
return the MSL and ellipoid height given a latitude longitude position
ossim-info --height &lt;latitude-in-degrees&gt; &lt;longitude-in-degrees&gt;
End of explanation
"""


!ossim-info --mtrsPerDeg 65.45

"""
Explanation: top
Meters per degrees
Gives meters per degree and meters per minute for a given latitude. 
ossim-info --mtrsPerDeg &lt;latitude&gt;
End of explanation
"""


!ossim-info --datums

"""
Explanation: top
Datums
Prints datum list.
ossim-info --datums
End of explanation
"""


!ossim-info --projections

"""
Explanation: Projections
Prints projections list
ossim-info --projections
End of explanation
"""


!ossim-info --cg {DATADIR}/p011r031_7t19990918_z19_nn10.tif -P /usr/local/share/ossim/ossim_preference

"""
Explanation: top
Explore raster data
ground center
```ossim-info --cg filename```
End of explanation
"""


!ossim-info  --ci {DATADIR}/p011r031_7t19990918_z19_nn10.tif -P /usr/local/share/ossim/ossim_preference

"""
Explanation: top
image center
```ossim-info  --ci filename```
End of explanation
"""


!ossim-info  -c {DATADIR}/p011r031_7t19990918_z19_nn10.tif -P /usr/local/share/ossim/ossim_preference

"""
Explanation: top
ground and image center
```ossim-info -c filename```
End of explanation
"""


!ossim-info  -i {DATADIR}/p011r031_7t19990918_z19_nn10.tif -P /usr/local/share/ossim/ossim_preference

"""
Explanation: top
general image information
```ossim-info -i filename```
End of explanation
"""


!ossim-info  -m {DATADIR}/p011r031_7t19990918_z19_nn10.tif -P /usr/local/share/ossim/ossim_preference

"""
Explanation: top
meta data image information
ossim-info -m filename
End of explanation
"""


!ossim-info  -p {DATADIR}/p011r031_7t19990918_z19_nn10.tif -P /usr/local/share/ossim/ossim_preference

"""
Explanation: top
image projection information
ossim-info -p filename
End of explanation
"""


!ossim-info  -r {DATADIR}/p011r031_7t19990918_z19_nn10.tif -P /usr/local/share/ossim/ossim_preference

"""
Explanation: top
image rectangle
ossim-info -r filename
End of explanation
"""


!ossim-img2rr {DATADIR}/p011r031_7t19990918_z19_nn10.tif -P /usr/local/share/ossim/ossim_preference

!ossim-img2rr {DATADIR}/p011r031_7t19990918_z19_nn20.tif -P /usr/local/share/ossim/ossim_preference

!ossim-img2rr {DATADIR}/p011r031_7t19990918_z19_nn30.tif -P /usr/local/share/ossim/ossim_preference

"""
Explanation: top
ossim-img2rr
End of explanation
"""


!ossim-cmm {DATADIR}/p011r031_7t19990918_z19_nn10.tif -P /usr/local/share/ossim/ossim_preference

!ossim-cmm {DATADIR}/p011r031_7t19990918_z19_nn20.tif -P /usr/local/share/ossim/ossim_preference

!ossim-cmm {DATADIR}/p011r031_7t19990918_z19_nn30.tif -P /usr/local/share/ossim/ossim_preference

!cat /home/main/notebooks/data/landsat/p011r031_7t19990918_z19_nn10.omd

"""
Explanation: ossim-cmm
End of explanation
"""


!ossim-img2md -P /usr/local/share/ossim/ossim_preference tiff_world_file {DATADIR}/p011r031_7t19990918_z19_nn10.tif {DATADIR}/p011r031_7t19990918_z19_nn10.tfw 

!cat /home/main/notebooks/data/landsat//p011r031_7t19990918_z19_nn10.tfw

"""
Explanation: ossim-img2md
Usage: ossim-img2md [options] &lt;metadata_writer&gt; &lt;input_file&gt; &lt;output_file&gt;


Valid metadata writer types:
envi_header   
ers_header    
ossim_fgdc    
ossim_geometry    
ossim_readme  
tiff_world_file   
jpeg_world_file
End of explanation
"""


!ossim-band-merge jpeg -P /usr/local/share/ossim/ossim_preference \
                 {DATADIR}/p011r031_7t19990918_z19_nn30.tif \
                 {DATADIR}/p011r031_7t19990918_z19_nn20.tif \
                 {DATADIR}/p011r031_7t19990918_z19_nn10.tif \
                 rgb.jpeg

!ossim-cmm rgb.jpeg -P /usr/local/share/ossim/ossim_preference

!cat rgb.omd

Image("rgb.jpeg")

"""
Explanation: ossim-band-merge
ossim-band-merge [-h][-o][-w tile_width] &lt;output_type&gt; &lt;input_file1&gt; &lt;input_file2&gt; ... &lt;output_file&gt;
Example, crete an RGB image from the single-band grayscale r,g,b images (Landsat 7)
End of explanation
"""


!ossim-create-histo {DATADIR}/p011r031_7t19990918_z19_nn30.tif \
{DATADIR}/p011r031_7t19990918_z19_nn20.tif \
{DATADIR}/p011r031_7t19990918_z19_nn10.tif

!ossim-orthoigen --hist-auto-minmax {DATADIR}/p011r031_7t19990918_z19_nn30.tif {DATADIR}/p011r031_7t19990918_z19_nn30_histmm.tif -P /usr/local/share/ossim/ossim_preference
!ossim-orthoigen --hist-auto-minmax {DATADIR}/p011r031_7t19990918_z19_nn20.tif {DATADIR}/p011r031_7t19990918_z19_nn20_histmm.tif -P /usr/local/share/ossim/ossim_preference
!ossim-orthoigen --hist-auto-minmax {DATADIR}/p011r031_7t19990918_z19_nn10.tif {DATADIR}/p011r031_7t19990918_z19_nn10_histmm.tif -P /usr/local/share/ossim/ossim_preference

!ossim-band-merge jpeg -P /usr/local/share/ossim/ossim_preference \
                 {DATADIR}/p011r031_7t19990918_z19_nn30_histmm.tif \
                 {DATADIR}/p011r031_7t19990918_z19_nn20_histmm.tif \
                 {DATADIR}/p011r031_7t19990918_z19_nn10_histmm.tif \
                 rgb_histmm.jpeg

Image('rgb_histmm.jpeg')

"""
Explanation: top
ossim-create-histo
End of explanation
"""


!ossim-chipper --color 255 255 255 \
              --azimuth 270 \
              --elevation 45 \
              --exaggeration 2.0 \
              --op hillshade \
              --color-table {DATADIR}/ossim-dem-color-table-template.kwl \
              --input-dem {DATADIR}/SRTM_fB03_p011r031.tif \
              hillshade.jpg -P /usr/local/share/ossim/ossim_preference

!ossim-info {DATADIR}/SRTM_fB03_p011r031.tif -P /usr/local/share/ossim/ossim_preference

!gdalinfo {DATADIR}/SRTM_fB03_p011r031.tif

Image('hillshade.jpg')

"""
Explanation: ossim-chipper
End of explanation
"""


# A complete list of ossim writers (driver) is given by:
!ossim-info --writers -P /usr/local/share/ossim/ossim_preference

#convert a geotiff to a geopdf
!ossim-icp ossim_pdf rgb_histmm.jpeg rgb_histmm.pdf

#view the results in a pdf viewer
#nohup evince lsat7_2002_30.pdf &

"""
Explanation: top
ossim-icp
ossim-icp [options] &lt;output_type&gt; &lt;input_file&gt; &lt;output_file&gt;
End of explanation
"""


#ossim-igen /home/user/ossim/rgb.spec

#display < /home/user/rgb.jpg

"""
Explanation: top
ossim-igen
Execute image chains specified in a spec file.
In the folowing example the spec file rgb.spec has been generated using  imagelinker, from an example session: /home/user/ossim/ossim-rgb.prj
End of explanation
"""


