@Test public void testThreeGeoTIFFTagsWithOneAscii() { metadata.addGeoShortParam(2300, 4576); metadata.addGeoAscii(2400, "String"); metadata.addGeoShortParam(2401, 3456); final List<TIFFField> list = Utils.createGeoTIFFFields(metadata); assertNotNull(list); assertEquals(2, list.size()); final TIFFField dirField = list.get(0); final TIFFField asciiField = list.get(1); assertEquals(GeoTIFFTagSet.TAG_GEO_KEY_DIRECTORY, dirField.getTag()); assertEquals(GeoTIFFTagSet.TAG_GEO_ASCII_PARAMS, asciiField.getTag()); assertEquals(TIFFField.TIFF_SHORT, dirField.getType()); assertEquals(TIFFField.TIFF_ASCII, asciiField.getType()); assertEquals(16, dirField.getCount()); assertEquals(1, asciiField.getCount()); final char[] expected = { 1, 1, 2, 3, 2300, 0, 1, 4576, 2400, GeoTIFFTagSet.TAG_GEO_ASCII_PARAMS, 7, 0, 2401, 0, 1, 3456 }; assertArrayEquals(expected, dirField.getAsChars()); assertEquals("String|", asciiField.getAsString(0)); }
@Test public void testVersionAndModelTiePoint() { metadata.addModelTiePoint(1, 2, 3, 4, 5, 6); metadata.addModelTiePoint(2, 3, 4, 5, 6, 7); metadata.addModelTiePoint(3, 4, 5, 6, 7, 8); final List<TIFFField> list = Utils.createGeoTIFFFields(metadata); assertNotNull(list); assertEquals(2, list.size()); final TIFFField dirField = list.get(0); assertEquals(GeoTIFFTagSet.TAG_GEO_KEY_DIRECTORY, dirField.getTag()); assertEquals(TIFFField.TIFF_SHORT, dirField.getType()); assertEquals(4, dirField.getCount()); assertArrayEquals(new char[] {1, 1, 2, 0}, dirField.getAsChars()); final TIFFField tiePointField = list.get(1); assertEquals(GeoTIFFTagSet.TAG_MODEL_TIE_POINT, tiePointField.getTag()); assertEquals(TIFFField.TIFF_DOUBLE, tiePointField.getType()); assertEquals(3 * 6, tiePointField.getCount()); final double[] expected = { 1, 2, 3, 4, 5, 6, 2, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 8 }; assertEquals(true, Arrays.equals(expected, tiePointField.getAsDoubles())); }
@Test public void testThreeGeoTIFFTagsWithOneDouble() { metadata.addGeoShortParam(2300, 4576); metadata.addGeoDoubleParam(2400, 4.5); metadata.addGeoShortParam(2401, 3456); final List<TIFFField> list = Utils.createGeoTIFFFields(metadata); assertNotNull(list); assertEquals(2, list.size()); final TIFFField dirField = list.get(0); final TIFFField doubleField = list.get(1); assertEquals(GeoTIFFTagSet.TAG_GEO_KEY_DIRECTORY, dirField.getTag()); assertEquals(GeoTIFFTagSet.TAG_GEO_DOUBLE_PARAMS, doubleField.getTag()); assertEquals(TIFFField.TIFF_SHORT, dirField.getType()); assertEquals(TIFFField.TIFF_DOUBLE, doubleField.getType()); assertEquals(16, dirField.getCount()); assertEquals(1, doubleField.getCount()); final char[] expected = { 1, 1, 2, 3, 2300, 0, 1, 4576, 2400, GeoTIFFTagSet.TAG_GEO_DOUBLE_PARAMS, 1, 0, 2401, 0, 1, 3456 }; assertArrayEquals(expected, dirField.getAsChars()); assertEquals(true, Arrays.equals(new double[] {4.5}, doubleField.getAsDoubles())); }
/** @return the crs as a string */ public String getHumanReadableCoordinateSystem() { StringBuilder sb = new StringBuilder(); if (this.geoKeyDirectoryTag.containsKey(new Integer(GeoTiffKey.PCSCitationGeoKey))) { int[] key_entry = this.geoKeyDirectoryTag.get(new Integer(GeoTiffKey.PCSCitationGeoKey)); // check if value of field is located in GeoAsciiParamsTag (34737) if (key_entry[0] == GeoTiffTag.GeoAsciiParamsTag) { TIFFField field = this.tifdir.getField(GeoTiffTag.GeoAsciiParamsTag); int ascii_length = key_entry[1]; int ascii_start = key_entry[2]; // return the string between the two byte-locations - 1 (the // last '|') String s = field.getAsString(0); if (s != null) { sb.append(s.substring(ascii_start, ascii_length - 1)); } } else { sb.append("No asci crs field is located in GeoAsciiParamsTag ("); sb.append(GeoTiffKey.PCSCitationGeoKey).append(")."); } } else { sb.append("<empty>"); } // GeogCitationGeoKey return sb.toString(); }
/** * GeoAsciiParamsTag: <br> * Tag = 34737 (87B1.H) <br> * Type = ASCII <br> * Owner: SPOT Image, Inc. <br> * N = variable * * <p>This tag is used to store all of the DOUBLE valued GeoKeys, referenced by the * GeoKeyDirectoryTag. The meaning of any value of this double array is determined from the * GeoKeyDirectoryTag reference pointing to it. FLOAT values should first be converted to DOUBLE * and stored here. * * <p>A baseline GeoTIFF-reader must check for and convert the final "|" pipe character of a key * back into a NULL before returning it to the client software. * * @return the fields */ public String[] getGeoAsciiParamsTag() { // TODO: getGeoAsciiParamsTag(int count, int value_offset)!!! TIFFField field = this.tifdir.getField(GeoTiffTag.GeoAsciiParamsTag); String gapt = field.getAsString(0); LOG.debug(gapt); StringTokenizer st = new StringTokenizer(gapt, "|"); LOG.debug("countTokens: " + st.countTokens()); String[] gapt_fields = new String[st.countTokens()]; int i = 0; while (st.hasMoreTokens()) { gapt_fields[i++] = st.nextToken(); } for (int j = 0; j < gapt_fields.length; j++) { LOG.debug(gapt_fields[j]); } return gapt_fields; }
@Test public void testVersionOnly() { final List<TIFFField> list = Utils.createGeoTIFFFields(metadata); assertNotNull(list); assertEquals(1, list.size()); final TIFFField dirField = list.get(0); assertEquals(GeoTIFFTagSet.TAG_GEO_KEY_DIRECTORY, dirField.getTag()); assertEquals(TIFFField.TIFF_SHORT, dirField.getType()); assertEquals(4, dirField.getCount()); final char[] expected = {1, 1, 2, 0}; assertArrayEquals(expected, dirField.getAsChars()); }
@Test public void testVersionAndModelPixelScale() { metadata.setModelPixelScale(1, 2, 3); final List<TIFFField> list = Utils.createGeoTIFFFields(metadata); assertNotNull(list); assertEquals(2, list.size()); final TIFFField dirField = list.get(0); assertEquals(GeoTIFFTagSet.TAG_GEO_KEY_DIRECTORY, dirField.getTag()); assertEquals(TIFFField.TIFF_SHORT, dirField.getType()); assertEquals(4, dirField.getCount()); assertArrayEquals(new char[] {1, 1, 2, 0}, dirField.getAsChars()); final TIFFField scaleField = list.get(1); assertEquals(GeoTIFFTagSet.TAG_MODEL_PIXEL_SCALE, scaleField.getTag()); assertEquals(TIFFField.TIFF_DOUBLE, scaleField.getType()); assertEquals(3, scaleField.getCount()); assertEquals(true, Arrays.equals(new double[] {1, 2, 3}, scaleField.getAsDoubles())); }
@Test public void testVersionAndModelTransformation() { metadata.setModelTransformation( new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}); final List<TIFFField> list = Utils.createGeoTIFFFields(metadata); assertNotNull(list); assertEquals(2, list.size()); final TIFFField dirField = list.get(0); assertEquals(GeoTIFFTagSet.TAG_GEO_KEY_DIRECTORY, dirField.getTag()); assertEquals(TIFFField.TIFF_SHORT, dirField.getType()); assertEquals(4, dirField.getCount()); assertArrayEquals(new char[] {1, 1, 2, 0}, dirField.getAsChars()); final TIFFField transformField = list.get(1); assertEquals(GeoTIFFTagSet.TAG_MODEL_TRANSFORMATION, transformField.getTag()); assertEquals(TIFFField.TIFF_DOUBLE, transformField.getType()); assertEquals(16, transformField.getCount()); final double[] expected = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; assertEquals(true, Arrays.equals(expected, transformField.getAsDoubles())); }
@Test public void testThreeGeoTIFFShortTags() { metadata.addGeoShortParam(2300, 4576); metadata.addGeoShortParam(2400, 12); metadata.addGeoShortParam(2401, 3456); final List<TIFFField> list = Utils.createGeoTIFFFields(metadata); assertNotNull(list); assertEquals(1, list.size()); final TIFFField dirField = list.get(0); assertEquals(GeoTIFFTagSet.TAG_GEO_KEY_DIRECTORY, dirField.getTag()); assertEquals(TIFFField.TIFF_SHORT, dirField.getType()); assertEquals(16, dirField.getCount()); final char[] expected = { 1, 1, 2, 3, 2300, 0, 1, 4576, 2400, 0, 1, 12, 2401, 0, 1, 3456 }; assertArrayEquals(expected, dirField.getAsChars()); }
/** * GeoKeyDirectoryTag: <br> * Tag = 34735 (87AF.H) <br> * Type = SHORT (2-byte unsigned short) <br> * N = variable, >= 4 <br> * Alias: ProjectionInfoTag, CoordSystemInfoTag <br> * Owner: SPOT Image, Inc. * * <p>This tag may be used to store the GeoKey Directory, which defines and references the * "GeoKeys", as described below. * * <p>The tag is an array of unsigned SHORT values, which are primarily grouped into blocks of 4. * The first 4 values are special, and contain GeoKey directory header information. The header * values consist of the following information, in order: * * <p><tt>Header={KeyDirectoryVersion, KeyRevision, MinorRevision, NumberOfKeys}</tt> * * <p>and as Keys: * * <p><tt>KeyEntry = { KeyID, TIFFTagLocation, Count, Value_Offset }</tt>^ * * <p>where * * <ul> * <li>"KeyID" gives the key-ID value of the Key (identical in function to TIFF tag ID, but * completely independent of TIFF tag-space), * <li>"TIFFTagLocation" indicates which TIFF tag contains the value(s) of the Key: if * TIFFTagLocation is 0, then the value is SHORT, and is contained in the "Value_Offset" * entry. Otherwise, the type (format) of the value is implied by the TIFF-Type of the tag * containing the value. * <li>"Count" indicates the number of values in this key. * <li>"Value_Offset" Value_Offset indicates the index- offset *into* the TagArray indicated by * TIFFTagLocation, if it is nonzero. If TIFFTagLocation=0, then Value_Offset contains the * actual (SHORT) value of the Key, and Count=1 is implied. Note that the offset is not a * byte-offset, but rather an index based on the natural data type of the specified tag * array. * </ul> */ private void setGeoKeyDirectoryTag() { TIFFField ff = this.tifdir.getField(GeoTiffTag.GeoKeyDirectoryTag); char[] ch = ff.getAsChars(); // resulting HashMap, containing the key and the array of values this.geoKeyDirectoryTag = new HashMap<Integer, int[]>(ff.getCount() / 4); // array of values. size is 4-1. int keydirversion, keyrevision, minorrevision, numberofkeys = -99; for (int i = 0; i < ch.length; i = i + 4) { int[] keys = new int[3]; keydirversion = ch[i]; keyrevision = ch[i + 1]; minorrevision = ch[i + 2]; numberofkeys = ch[i + 3]; keys[0] = keyrevision; keys[1] = minorrevision; keys[2] = numberofkeys; LOG.debug( "[" + i + "].KEY: " + keydirversion + " \t" + keyrevision + "\t" + minorrevision + "\t" + numberofkeys); this.geoKeyDirectoryTag.put(new Integer(keydirversion), keys); } this.hasGeoKeyDirectoryTag = true; }
/** * @return the bbox * @throws GeoTiffException */ public Envelope getBoundingBox() throws GeoTiffException { TIFFField modelPixelScaleTag = this.tifdir.getField(GeoTiffTag.ModelPixelScaleTag); double resx = modelPixelScaleTag.getAsDouble(0); double resy = modelPixelScaleTag.getAsDouble(1); TIFFField modelTiepointTag = this.tifdir.getField(GeoTiffTag.ModelTiepointTag); double val1 = 0.0; val1 = modelTiepointTag.getAsDouble(0); double val2 = 0.0; val2 = modelTiepointTag.getAsDouble(1); double val4 = 0.0; val4 = modelTiepointTag.getAsDouble(3); double val5 = 0.0; val5 = modelTiepointTag.getAsDouble(4); if ((resx == 0.0 || resy == 0.0) || (val1 == 0.0 && val2 == 0.0 && val4 == 0.0 && val5 == 0.0)) { throw new GeoTiffException("The image/coverage hasn't a bounding box"); // set the geoparams derived by geoTiffTags } // upper/left pixel double xOrigin = val4 - (val1 * resx); double yOrigin = val5 - (val2 * resy); // lower/right pixel double xRight = xOrigin + image.getWidth() * resx; double yBottom = yOrigin - image.getHeight() * resy; double xmin = xOrigin; double ymin = yBottom; double xmax = xRight; double ymax = yOrigin; Envelope envelope = geometryFactory.createEnvelope(xmin, ymin, xmax, ymax, null); return envelope; }
@Test public void testThreeGeoTIFFStringTags() { metadata.addGeoAscii(2300, "4576"); metadata.addGeoAscii(2400, "aaaaaaaa"); metadata.addGeoAscii(2401, "bbbb"); final List<TIFFField> list = Utils.createGeoTIFFFields(metadata); assertNotNull(list); assertEquals(2, list.size()); final TIFFField dirField = list.get(0); final TIFFField asciiField = list.get(1); assertEquals(GeoTIFFTagSet.TAG_GEO_KEY_DIRECTORY, dirField.getTag()); assertEquals(GeoTIFFTagSet.TAG_GEO_ASCII_PARAMS, asciiField.getTag()); assertEquals(TIFFField.TIFF_SHORT, dirField.getType()); assertEquals(TIFFField.TIFF_ASCII, asciiField.getType()); assertEquals(16, dirField.getCount()); assertEquals(3, asciiField.getCount()); final char[] expected = { 1, 1, 2, 3, 2300, GeoTIFFTagSet.TAG_GEO_ASCII_PARAMS, 5, 0, 2400, GeoTIFFTagSet.TAG_GEO_ASCII_PARAMS, 9, 5, 2401, GeoTIFFTagSet.TAG_GEO_ASCII_PARAMS, 5, 14 }; assertArrayEquals(expected, dirField.getAsChars()); assertEquals("4576|", asciiField.getAsString(0)); assertEquals("aaaaaaaa|", asciiField.getAsString(1)); assertEquals("bbbb|", asciiField.getAsString(2)); }