This library converts geokeys to Proj4 string and contains following functions:
module:geokeysToProj4.toProj4Does actual conversionmodule:geokeysToProj4.convertCoordinatesConverts coordinates to use with proj4
In general, you want to:
- Read geokeys.
- Pass them to
geokeysToProj4.toProj4()(let's call returned objectprojObj). - Pass
projObj.proj4(Proj4 string) to proj4js. - Convert pixel coordinates to CRS coordinates (let's call them
crsXandcrsY). - Convert CRS coordinates to usable units (in most cases, meters, but GeoTIFF allows speed, angular speed, and scale):
geokeysToProj4(crsX, crsY, projObj.coordinatesConversionParameters). - 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, zbyparameters.x,parameters.yandparameters.zrespectively.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 xnumber X coordinate
ynumber Y coordinate
znumber Pixel value, i.e. Z coordinate. If you don't use DEM, pass any number.
parametersObject getProjectionParameters().coordinatesConversionParameters
Returns:
Converted coordinates
-
<static> toProj4(geoKeys)
-
Converts GeoTIFFs geokeys to Proj4 string
Parameters:
Name Type Description geoKeysGeoKeys Object where keys are geokeys (named exactly as in GeoTIFF specification) and values are, well, their values.
Returns:
Projection parameters
Type Definitions
-
ConversionErrors
-
Errors that have occurred during conversion.
Apart from listed properties, there's properties that named after geokeys with
NotSupportedsuffix, 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-proj4If an error has not occurred, it won't be present in this object.
How to process these errors:
- If it's your program's user's GeoTIFF, show an error message.
- If it's your GeoTIFF, fix it in a GIS.
- 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 bothGCSAndPCSAreSetboolean trueWhen bothGeodeticCRSGeoKey(orGeographicTypeGeoKey) andProjectedCRSGeoKey(orProjectedCSTypeGeoKey) geokeys are set. In this case,GeographicTypeGeoKeyis used. The cause of this error is broken geokeys.CRSNotSupportednumber 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.
GeogLinearUnitSizeGeoKeyNotDefinednumber Geokey
GeogLinearUnitsGeoKeyis set to user-defined, but user hasn't specifiedGeogLinearUnitSizeGeoKey. In this case, every other key using this one assumed to be using meters. The cause of this error is broken geokeys.GeogAngularUnitSizeGeoKeyNotDefinednumber Geokey
GeogAngularUnitsGeoKeyis set to user-defined, but user hasn't specifiedGeogAngularUnitSizeGeoKey. In this case, every other key using this one assumed to be using degrees. The cause of this error is broken geokeys.ProjLinearUnitSizeGeoKeyNotDefinednumber Geokey
ProjLinearUnitsGeoKeyis set to user-defined, but user hasn't specifiedProjLinearUnitSizeGeoKey. In this case, every other key using this one assumed to be using meters. The cause of this error is broken geokeys.conversionNotSupportednumber Conversion specified in
ProjectionGeoKeyis not supported by this library. Value is EPSG conversion code.coordinateTransformationNotSupportednumber Transformation specified in
ProjMethodGeoKey(orProjCoordTransGeoKey) 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.verticalCsNotSupportednumber Vertical CS specified in
VerticalGeoKey(orVerticalCSTypeGeoKey) is not supported by this library. Value is EPSG CS code.verticalCsUnitsNotSupportednumber Vertical CS specified in
VerticalUnitsGeoKeyis not supported by this library. Value is EPSG uom code.verticalDatumsNotSupportednumber Vertical datums are not supported by this library. If vertical CRS is user-defined, and
VerticalDatumGeoKeyis set, this error will be reported. Value is EPSG datum code. -
CoordinateConversionParameters
-
Parameters to pass to
module:geokeysToProj4.convertCoordinatesor to convert coordinates manuallyType:
- Object
Properties:
Name Type Description xnumber Multiply X coordinate by this parameter to convert it to standard units (meters or degrees)
ynumber Multiply Y coordinate by this parameter to convert it to standard units (meters or degrees)
znumber Multiply Z coordinate (pixel value) by this parameter to convert it to standard units (meters)
-
GeoKeys
-
Geokeys. If you're working with
geotifflibrary, this is result ofimage.getGeoKeys().Type:
- Object
Properties:
Name Type Description GeodeticCRSGeoKeynumber See GeoTIFF docs for more information
GeographicTypeGeoKeynumber See GeoTIFF docs for more information
GeodeticDatumGeoKeynumber See GeoTIFF docs for more information
GeogGeodeticDatumGeoKeynumber See GeoTIFF docs for more information
PrimeMeridianGeoKeynumber See GeoTIFF docs for more information
GeogPrimeMeridianGeoKeynumber See GeoTIFF docs for more information
GeogLinearUnitsGeoKeynumber See GeoTIFF docs for more information
GeogLinearUnitSizeGeoKeynumber See GeoTIFF docs for more information
GeogAngularUnitsGeoKeynumber See GeoTIFF docs for more information
GeogAngularUnitSizeGeoKeynumber See GeoTIFF docs for more information
GeogEllipsoidGeoKeynumber See GeoTIFF docs for more information
EllipsoidSemiMajorAxisGeoKeynumber See GeoTIFF docs for more information
GeogSemiMajorAxisGeoKeynumber See GeoTIFF docs for more information
EllipsoidSemiMinorAxisGeoKeynumber See GeoTIFF docs for more information
GeogSemiMinorAxisGeoKeynumber See GeoTIFF docs for more information
EllipsoidInvFlatteningGeoKeynumber See GeoTIFF docs for more information
GeogInvFlatteningGeoKeynumber See GeoTIFF docs for more information
PrimeMeridianLongitudeGeoKeynumber See GeoTIFF docs for more information
PrimeMeridianLongitudeGeoKeynumber See GeoTIFF docs for more information
GeogPrimeMeridianLongGeoKeynumber See GeoTIFF docs for more information
ProjectedCRSGeoKeynumber See GeoTIFF docs for more information
ProjectedCSTypeGeoKeynumber See GeoTIFF docs for more information
ProjectionGeoKeynumber See GeoTIFF docs for more information
ProjMethodGeoKeynumber See GeoTIFF docs for more information
ProjCoordTransGeoKeynumber See GeoTIFF docs for more information
ProjLinearUnitsGeoKeynumber See GeoTIFF docs for more information
ProjLinearUnitSizeGeoKeynumber See GeoTIFF docs for more information
ProjStdParallel1GeoKeynumber See GeoTIFF docs for more information
ProjStdParallel2GeoKeynumber See GeoTIFF docs for more information
ProjNatOriginLongGeoKeynumber See GeoTIFF docs for more information
ProjNatOriginLatGeoKeynumber See GeoTIFF docs for more information
ProjFalseEastingGeoKeynumber See GeoTIFF docs for more information
ProjFalseNorthingGeoKeynumber See GeoTIFF docs for more information
ProjFalseOriginLongGeoKeynumber See GeoTIFF docs for more information
ProjFalseOriginLatGeoKeynumber See GeoTIFF docs for more information
ProjFalseOriginEastingGeoKeynumber See GeoTIFF docs for more information
ProjFalseOriginNorthingGeoKeynumber See GeoTIFF docs for more information
ProjCenterLongGeoKeynumber See GeoTIFF docs for more information
ProjCenterLatGeoKeynumber See GeoTIFF docs for more information
ProjCenterEastingGeoKeynumber See GeoTIFF docs for more information
ProjCenterNorthingGeoKeynumber See GeoTIFF docs for more information
ProjScaleAtNatOriginGeoKeynumber See GeoTIFF docs for more information
ProjScaleAtCenterGeoKeynumber See GeoTIFF docs for more information
ProjAzimuthAngleGeoKeynumber See GeoTIFF docs for more information
ProjStraightVertPoleLongGeoKeynumber See GeoTIFF docs for more information
VerticalGeoKeynumber See GeoTIFF docs for more information
VerticalCSTypeGeoKeynumber See GeoTIFF docs for more information
VerticalUnitsGeoKeynumber See GeoTIFF docs for more information
GeogTOWGS84GeoKeyArray.<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 xnumber X coordinate (coordinate of a first axis of CRS) of a point
ynumber Y coordinate (coordinate of a second axis of CRS) of a point
znumber 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 proj4string Proj4 string
shouldConvertCoordinatesboolean If true, coordinates should be converted by using
module:geokeysToProj4.convertCoordinatesbefore passing to proj4jscoordinatesConversionParametersCoordinateConversionParameters Parameters to pass to
module:geokeysToProj4.convertCoordinatescoordinatesUnits"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.
isGCSboolean If
true, geographic (either 2D or 3D) CRS is used.errorsmodule:geokeysToProj4.ConversionErrors Errors that have occurred while processing geokeys. If no error has occurred, there will be an empty object.