.. _srs_wkt:

******************************************************************************
Georeferencing LAS files with LAS 1.4
******************************************************************************


:Author: Howard Butler
:Contact: hobu.inc at gmail dot com
:Date: 2/28/2011

Summary
------------------------------------------------------------------------------

This document proposes how to handle describing spatial reference systems 
in `ASPRS LAS`_ 1.4. LAS 1.4 prescribes that software developers add and 
prefer to use OGC WKT coordinate system description in the form of VLR 
records in LAS files.  Softwares can choose to continue to write GeoTIFF keys 
to support older applications, but they should prefer the OGC WKT if it is 
found in the file.

Rationale
------------------------------------------------------------------------------

LAS 1.3 and below have used `GeoTIFF`_ keys as described by the `GeoTIFF
specification`_, but use of the GeoTIFF keys within LAS has a number of
deficiencies:

* GeoTIFF is typically tied to the `EPSG database`_ and does not provide
  simple mechanisms for extended definitions.
* Only a few softwares provide support for working with GeoTIFF keys directly.
* The GeoTIFF specification has no organization backing its continued
  development.
* GeoTIFF does not offer a mechanism to represent transformations between
  datums, while OGC WKT offers the TOWGS84[] mechanism
* GeoTIFF does not offer the possibility of fitted coordinate systems.

WKT
------------------------------------------------------------------------------

The `OpenGIS Coordinate Transformation Service Implementation Specification`_
provides the "Well-known Text Representation of Spatial Reference Systems"
(WKT) language in section seven. WKT is much more expressive than GeoTIFF keys,
has an organization providing institutional heft and progress behind it, and a
number of open source and commercial softwares are available to support
parsing and interpreting WKT output.

There are a few dialects of WKT of which to be aware. The most common dialect
is the "ESRI WKT" dialect, which does not include TOWGS84 and authority nodes,
but there are others including "GDAL", "CSMap", "Oracle 9", "Oracle 10", and
"GeoTools." While the basic form of WKT in these different dialects (other
than ESRI) is the same, the names used for different items, such as
``PARAMETER``, can often be spelled differently. It should be assumed that all
WKT provided in LAS files should be of a dialect that is not the "ESRI WKT"
dialect, which lacks some important features -- notably TOWGS84 and AUTHORITY
nodes. 

.. _`OpenGIS Coordinate Transformation Service Implementation Specification`: http://www.opengeospatial.org/standards/ct
.. _`MetaCRS`: http://trac.osgeo.org/metacrs/



Implementation
------------------------------------------------------------------------------

WKT can be specified in two optional Variable Length Record (VLR) entries with the 
``LASF_Projection`` User ID. The `Math Transform WKT`_ can be used to apply 
transformations to the `Coordinate System WKT`_.

Math Transform WKT
..............................................................................

Math Transform WKT (section 7.1 of the `OGC Coordinate Transform Specification`_) 
can also be specified to apply to a ``FITTED_CS``-style coordinate system.  

OGC Math Transform WKT strings shall be provided in a VLR with the
following attributes:

* User ID: LASF_Projection
* Record ID: 2111

The following conditions should also apply:

* Because VLRs can only be 65536 bytes size, an OGC Math Transform WKT
  string in a VLR data block is functionally limited to 64K in size.
* The OGC Math Transform WKT VLR data shall be a null-terminated string.
* The OGC Math Transform WKT VLR data shall be considered UTF-8.
* The OGC Math Transform WKT VLR data shall be considered ``C``
  locale-based, and no localization of the numeric strings within the WKT
  should be performed.

.. note::
    Math Transform WKT's widespread use is not expected, but it is provided
    for completeness and flexibility.


Coordinate System WKT
..............................................................................

OGC Coordinate System WKT strings shall be provided in a VLR with the
following attributes:

* User ID: LASF_Projection
* Record ID: 2112

The following conditions should also apply:

* Because VLRs can only be 65536 bytes size, an OGC Coordinate System WKT
  string in a VLR data block is functionally limited to 64K in size.
* The OGC Coordinate System WKT VLR data shall be a null-terminated string.
* The OGC Coordinate System WKT VLR data shall be considered UTF-8.
* The OGC Coordinate System WKT VLR data shall be considered ``C``
  locale-based, and no localization of the numeric strings within the WKT
  should be performed.

.. note::
    Though not specifically mentioned in previous LAS specifications,
    coordinate system information (in GeoTIFF or WKT) applies to the final
    coordinate data that are produced by transforming the raw coordinates by
    the scale and offset specified in the header for the given dimension.

Transition
------------------------------------------------------------------------------

Older softwares may want to continue to use GeoTIFF keys, and it is not
desirable to have an abrupt discontinuity in the description of coordinate
systems for LAS data. Additionally, while many softwares may not need the
features of OGC WKT, its usage represents the strongest case for
interoperability with other software -- especially software in the GIS and CAD
domains that take advantage of the OGC WKT specification.

Softwares that currently write GeoTIFF VLR records into LAS files can continue
to do so in LAS 1.4. It is acceptable to write *only* GeoTIFF VLR records into
an LAS file, while softwares that choose to write OGC WKT VLRs must also
write GeoTIFF VLRs to promote backward compatibility. If a file is found to
have both OGC WKT and GeoTIFF VLRs, the OGC WKT description, which is more
expressive, should be preferred if possible.

Resources
------------------------------------------------------------------------------

The ASPRS LAS specification attempts to offload specification of coordinate
system description and transformation by standing on the shoulders of other
specifications in the ecosystem. To that end, there are options for both
software and support for an LAS developer to take advantage of. Those below
are provided for information purposes only, and are not expected to be
canonical. Use your favorite search engine for more details.

Software
..............................................................................

As mentioned previously, a number of open source and commercial softwares are
available to help an implementor of ASPRS LAS utilize Coordinate System and
Math Transform WKT in their software.

Some common open source softwares include:

* `GDAL`_'s `OSR`_
* `CS-Map`_
* `GeoTools`_/`Geotoolkit`_ 

Some commercial options include:

* `Blue Marble®`_ 
* `ArcGIS®`_

Questions
..............................................................................

If you have questions about how to produce WKT, please participate on
the `MetaCRS`_ mailing list. Examples of WKT may also be found on the
http://spatialreference.org website.

.. _`OSR`: http://www.gdal.org/ogr/osr_tutorial.html
.. _`ArcGIS®`: http://www.arcgis.com

.. _`Blue Marble®`: http://www.bluemarblegeo.com/
.. _`GDAL`: http://www.gdal.org
.. _`CS-Map`: http://trac.osgeo.org/csmap/
.. _`GeoTools`: http://www.geotools.org/
.. _`Geotoolkit`: http://www.geotoolkit.org/

.. _`OGC Coordinate Transform Specification`: http://www.opengeospatial.org/standards/ct


.. _`ASPRS LAS`: http://www.asprs.org/society/committees/standards/lidar_exchange_format.html
.. _`GeoTIFF specification`: ftp://ftp.remotesensing.org/pub/geotiff/spec/geotiff.rtf
.. _`GeoTIFF`: http://trac.osgeo.org/geotiff/
.. _`EPSG database`: http://www.epsg-registry.org/

