@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)); }
@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)); }
/** @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 testThreeGeoTIFFTagsWithOneDoubleAndOneString() { metadata.addGeoShortParam(2300, 4576); metadata.addGeoDoubleParam(2400, 4.5); metadata.addGeoAscii(2401, "dlkjfg"); final List<TIFFField> list = Utils.createGeoTIFFFields(metadata); assertNotNull(list); assertEquals(3, list.size()); final TIFFField dirField = list.get(0); final TIFFField doubleField = list.get(1); final TIFFField asciiField = list.get(2); assertEquals(GeoTIFFTagSet.TAG_GEO_KEY_DIRECTORY, dirField.getTag()); assertEquals(GeoTIFFTagSet.TAG_GEO_DOUBLE_PARAMS, doubleField.getTag()); assertEquals(GeoTIFFTagSet.TAG_GEO_ASCII_PARAMS, asciiField.getTag()); assertEquals(TIFFField.TIFF_SHORT, dirField.getType()); assertEquals(TIFFField.TIFF_DOUBLE, doubleField.getType()); assertEquals(TIFFField.TIFF_ASCII, asciiField.getType()); assertEquals(16, dirField.getCount()); assertEquals(1, doubleField.getCount()); assertEquals(1, asciiField.getCount()); final char[] expected = { 1, 1, 2, 3, 2300, 0, 1, 4576, 2400, GeoTIFFTagSet.TAG_GEO_DOUBLE_PARAMS, 1, 0, 2401, GeoTIFFTagSet.TAG_GEO_ASCII_PARAMS, 7, 0 }; assertArrayEquals(expected, dirField.getAsChars()); assertEquals(true, Arrays.equals(new double[] {4.5}, doubleField.getAsDoubles())); assertEquals("dlkjfg|", asciiField.getAsString(0)); }