private void writeGeographicElevationGeoKeys(ArrayList<TiffIFDEntry> ifds, AVList params)
      throws IOException {
    long offset = this.theChannel.position();

    if (isElevation(params) && isGeographic(params)) {
      int epsg = GeoTiff.GCS.WGS_84;

      if (params.hasKey(AVKey.PROJECTION_EPSG_CODE))
        epsg = (Integer) params.getValue(AVKey.PROJECTION_EPSG_CODE);

      int elevUnits = GeoTiff.Unit.Linear.Meter;
      if (params.hasKey(AVKey.ELEVATION_UNIT)) {
        if (AVKey.UNIT_FOOT.equals(params.getValue(AVKey.ELEVATION_UNIT)))
          elevUnits = GeoTiff.Unit.Linear.Foot;
      }

      int rasterType = GeoTiff.RasterType.RasterPixelIsArea;
      if (params.hasKey(AVKey.RASTER_PIXEL)
          && AVKey.RASTER_PIXEL_IS_POINT.equals(params.getValue(AVKey.RASTER_PIXEL)))
        rasterType = GeoTiff.RasterType.RasterPixelIsPoint;

      short[] values =
          new short[] {
            // GeoKeyDirectory header
            GeoTiff.GeoKeyHeader.KeyDirectoryVersion,
            GeoTiff.GeoKeyHeader.KeyRevision,
            GeoTiff.GeoKeyHeader.MinorRevision,
            0, // IMPORTANT!! we will update count below, after the array initialization
            // end of header -

            // geo keys array

            /* key 1 */
            GeoTiff.GeoKey.ModelType,
            0,
            1,
            GeoTiff.ModelType.Geographic,
            /* key 2 */
            // TODO: Replace GeoTiff.RasterType.RasterPixelIsPoint
            GeoTiff.GeoKey.RasterType,
            0,
            1,
            (short) (0xFFFF & rasterType),
            /* key 3 */
            GeoTiff.GeoKey.GeographicType,
            0,
            1,
            (short) (0xFFFF & epsg),
            /* key 4 */
            GeoTiff.GeoKey.GeogAngularUnits,
            0,
            1,
            GeoTiff.Unit.Angular.Angular_Degree,
            /* key 5 */
            GeoTiff.GeoKey.VerticalCSType,
            0,
            1,
            GeoTiff.VCS.WGS_84_ellipsoid,
            /* key 6 */
            GeoTiff.GeoKey.VerticalUnits,
            0,
            1,
            (short) (0xFFFF & elevUnits),
          };

      // IMPORTANT!! update count - number of geokeys
      values[3] = (short) (values.length / 4);

      byte[] bytes = this.getBytes(values);
      this.theChannel.write(ByteBuffer.wrap(bytes));
      ifds.add(
          new TiffIFDEntry(GeoTiff.Tag.GEO_KEY_DIRECTORY, Tiff.Type.SHORT, values.length, offset));
    }
  }