Module: geokeysToProj4

This library converts geokeys to Proj4 string and contains following functions:

  1. module:geokeysToProj4.toProj4 Does actual conversion
  2. module:geokeysToProj4.convertCoordinates Converts coordinates to use with proj4

In general, you want to:

  1. Read geokeys.
  2. Pass them to geokeysToProj4.toProj4() (let's call returned object projObj).
  3. Pass projObj.proj4 (Proj4 string) to proj4js.
  4. Convert pixel coordinates to CRS coordinates (let's call them crsX and crsY).
  5. Convert CRS coordinates to usable units (in most cases, meters, but GeoTIFF allows speed, angular speed, and scale): geokeysToProj4(crsX, crsY, projObj.coordinatesConversionParameters).
  6. The returned object contains X, Y, Z coordinates. which are ready to be projected with proj4js. So project them.

Of course, you can alter this workflow to use this library with any other (presumably, server-side) software.

Methods


<static> convertCoordinates(x, y, z, parameters)

Converts given coordinates to standard ones (i.e. meters or degrees).

Basically, a short way to multiply x, y, z by parameters.x, parameters.y and parameters.z respectively.

It does NOT accept image coordinates! Convert image coordinates to projection coordinates first (by multiplying image coordinates by image.getResolution() and adding coordinates of a top left corner) and then pass converted coordinates to this function.

Parameters:
Name Type Description
x number

X coordinate

y number

Y coordinate

z number

Pixel value, i.e. Z coordinate. If you don't use DEM, pass any number.

parameters Object

getProjectionParameters().coordinatesConversionParameters

Returns:

Converted coordinates

Type
module:geokeysToProj4.Point

<static> toProj4(geoKeys)

Converts GeoTIFFs geokeys to Proj4 string

Parameters:
Name Type Description
geoKeys GeoKeys

Object where keys are geokeys (named exactly as in GeoTIFF specification) and values are, well, their values.

Returns:

Projection parameters

Type
module:geokeysToProj4.ProjectionParameters

Type Definitions


ConversionErrors

Errors that have occurred during conversion.

Apart from listed properties, there's properties that named after geokeys with NotSupported suffix, i.e. ProjFalseOriginLongGeoKeyNotSupported. Values are EPSG codes assigned to those keys. These errors mean that the specified EPSG code is either not supported by this library, or it's new and hasn't been added yet. If it's the latter, please, create an issue at https://github.com/matafokka/geotiff-geokeys-to-proj4

If an error has not occurred, it won't be present in this object.

How to process these errors:

  1. If it's your program's user's GeoTIFF, show an error message.
  2. If it's your GeoTIFF, fix it in a GIS.
  3. If you're sure that file is fine or want to discuss it, please, create an issue at https://github.com/matafokka/geotiff-geokeys-to-proj4
Type:
  • Object
Properties:
Name Type Description
bothGCSAndPCSAreSet boolean

true When both GeodeticCRSGeoKey (or GeographicTypeGeoKey) and ProjectedCRSGeoKey (or ProjectedCSTypeGeoKey) geokeys are set. In this case, GeographicTypeGeoKey is used. The cause of this error is broken geokeys.

CRSNotSupported number

Specified CRS can't be represented as Proj4 string or it's new and hasn't been added to this library. Value is EPSG code of specified CRS.

GeogLinearUnitSizeGeoKeyNotDefined number

Geokey GeogLinearUnitsGeoKey is set to user-defined, but user hasn't specified GeogLinearUnitSizeGeoKey. In this case, every other key using this one assumed to be using meters. The cause of this error is broken geokeys.

GeogAngularUnitSizeGeoKeyNotDefined number

Geokey GeogAngularUnitsGeoKey is set to user-defined, but user hasn't specified GeogAngularUnitSizeGeoKey. In this case, every other key using this one assumed to be using degrees. The cause of this error is broken geokeys.

ProjLinearUnitSizeGeoKeyNotDefined number

Geokey ProjLinearUnitsGeoKey is set to user-defined, but user hasn't specified ProjLinearUnitSizeGeoKey. In this case, every other key using this one assumed to be using meters. The cause of this error is broken geokeys.

conversionNotSupported number

Conversion specified in ProjectionGeoKey is not supported by this library. Value is EPSG conversion code.

coordinateTransformationNotSupported number

Transformation specified in ProjMethodGeoKey (or ProjCoordTransGeoKey) is not supported by this library. Value is projection code. See http://geotiff.maptools.org/spec/geotiff6.html#6.3.3.3 for more information.

verticalCsNotSupported number

Vertical CS specified in VerticalGeoKey (or VerticalCSTypeGeoKey) is not supported by this library. Value is EPSG CS code.

verticalCsUnitsNotSupported number

Vertical CS specified in VerticalUnitsGeoKey is not supported by this library. Value is EPSG uom code.

verticalDatumsNotSupported number

Vertical datums are not supported by this library. If vertical CRS is user-defined, and VerticalDatumGeoKey is set, this error will be reported. Value is EPSG datum code.


CoordinateConversionParameters

Parameters to pass to module:geokeysToProj4.convertCoordinates or to convert coordinates manually

Type:
  • Object
Properties:
Name Type Description
x number

Multiply X coordinate by this parameter to convert it to standard units (meters or degrees)

y number

Multiply Y coordinate by this parameter to convert it to standard units (meters or degrees)

z number

Multiply Z coordinate (pixel value) by this parameter to convert it to standard units (meters)


GeoKeys

Geokeys. If you're working with geotiff library, this is result of image.getGeoKeys().

Type:
  • Object
Properties:
Name Type Description
GeodeticCRSGeoKey number

See GeoTIFF docs for more information

GeographicTypeGeoKey number

See GeoTIFF docs for more information

GeodeticDatumGeoKey number

See GeoTIFF docs for more information

GeogGeodeticDatumGeoKey number

See GeoTIFF docs for more information

PrimeMeridianGeoKey number

See GeoTIFF docs for more information

GeogPrimeMeridianGeoKey number

See GeoTIFF docs for more information

GeogLinearUnitsGeoKey number

See GeoTIFF docs for more information

GeogLinearUnitSizeGeoKey number

See GeoTIFF docs for more information

GeogAngularUnitsGeoKey number

See GeoTIFF docs for more information

GeogAngularUnitSizeGeoKey number

See GeoTIFF docs for more information

GeogEllipsoidGeoKey number

See GeoTIFF docs for more information

EllipsoidSemiMajorAxisGeoKey number

See GeoTIFF docs for more information

GeogSemiMajorAxisGeoKey number

See GeoTIFF docs for more information

EllipsoidSemiMinorAxisGeoKey number

See GeoTIFF docs for more information

GeogSemiMinorAxisGeoKey number

See GeoTIFF docs for more information

EllipsoidInvFlatteningGeoKey number

See GeoTIFF docs for more information

GeogInvFlatteningGeoKey number

See GeoTIFF docs for more information

PrimeMeridianLongitudeGeoKey number

See GeoTIFF docs for more information

PrimeMeridianLongitudeGeoKey number

See GeoTIFF docs for more information

GeogPrimeMeridianLongGeoKey number

See GeoTIFF docs for more information

ProjectedCRSGeoKey number

See GeoTIFF docs for more information

ProjectedCSTypeGeoKey number

See GeoTIFF docs for more information

ProjectionGeoKey number

See GeoTIFF docs for more information

ProjMethodGeoKey number

See GeoTIFF docs for more information

ProjCoordTransGeoKey number

See GeoTIFF docs for more information

ProjLinearUnitsGeoKey number

See GeoTIFF docs for more information

ProjLinearUnitSizeGeoKey number

See GeoTIFF docs for more information

ProjStdParallel1GeoKey number

See GeoTIFF docs for more information

ProjStdParallel2GeoKey number

See GeoTIFF docs for more information

ProjNatOriginLongGeoKey number

See GeoTIFF docs for more information

ProjNatOriginLatGeoKey number

See GeoTIFF docs for more information

ProjFalseEastingGeoKey number

See GeoTIFF docs for more information

ProjFalseNorthingGeoKey number

See GeoTIFF docs for more information

ProjFalseOriginLongGeoKey number

See GeoTIFF docs for more information

ProjFalseOriginLatGeoKey number

See GeoTIFF docs for more information

ProjFalseOriginEastingGeoKey number

See GeoTIFF docs for more information

ProjFalseOriginNorthingGeoKey number

See GeoTIFF docs for more information

ProjCenterLongGeoKey number

See GeoTIFF docs for more information

ProjCenterLatGeoKey number

See GeoTIFF docs for more information

ProjCenterEastingGeoKey number

See GeoTIFF docs for more information

ProjCenterNorthingGeoKey number

See GeoTIFF docs for more information

ProjScaleAtNatOriginGeoKey number

See GeoTIFF docs for more information

ProjScaleAtCenterGeoKey number

See GeoTIFF docs for more information

ProjAzimuthAngleGeoKey number

See GeoTIFF docs for more information

ProjStraightVertPoleLongGeoKey number

See GeoTIFF docs for more information

VerticalGeoKey number

See GeoTIFF docs for more information

VerticalCSTypeGeoKey number

See GeoTIFF docs for more information

VerticalUnitsGeoKey number

See GeoTIFF docs for more information

GeogTOWGS84GeoKey Array.<number>

Datum to WGS transformation parameters, unofficial key


Point

Represents a point. X and Y coordinates are not necessarily cartesian coordinates (might be lon/lat, depends on CRS) and not in this order (if axes has been swapped by GeoTIFF).

Type:
  • Object
Properties:
Name Type Description
x number

X coordinate (coordinate of a first axis of CRS) of a point

y number

Y coordinate (coordinate of a second axis of CRS) of a point

z number

Z coordinate (coordinate of a third axis of CRS) of a point, i.e. transformed pixel value. Always points up.


ProjectionParameters

Returned projection parameters

Type:
  • Object
Properties:
Name Type Description
proj4 string

Proj4 string

shouldConvertCoordinates boolean

If true, coordinates should be converted by using module:geokeysToProj4.convertCoordinates before passing to proj4js

coordinatesConversionParameters CoordinateConversionParameters

Parameters to pass to module:geokeysToProj4.convertCoordinates

coordinatesUnits "metre" | "metre per second" | "second" | "radian" | "radian per second" | "scale" | "scale per second" | "degree"

Coordinates units after conversion. EPSG defines speed, angular speed and scale as linear units, and GeoTIFF relies on EPSG. So there's a chance that coordinates will represent something's different from distance (in case of PCS). Note: GCS will always use degrees; if PCS uses angles, radians will be used.

isGCS boolean

If true, geographic (either 2D or 3D) CRS is used.

errors module:geokeysToProj4.ConversionErrors

Errors that have occurred while processing geokeys. If no error has occurred, there will be an empty object.