geocodec.java
来自「world wind java sdk 源码」· Java 代码 · 共 528 行 · 第 1/2 页
JAVA
528 行
Logging.logger().severe(message); throw new UnsupportedOperationException(message); } double[] xy = new double[2]; ModelTiePoint t = this.tiePoints.get(0); xy[0] = t.x + col * this.xScale; xy[1] = t.y - row * this.yScale; return xy; } /** * Gets the values of the given GeoKey as an array of ints. * <p/> * While this method handles the general case of multiple ints associated with a key, typically there will be only a * single value. * * @param key GeoKey value * @return Array of int values associated with the key, or null if the key was not found. * @throws IllegalArgumentException Thrown if the key does not embody integer values. */ public int[] getGeoKeyAsInts(int key) throws IllegalArgumentException { int[] vals = null; GeoKeyEntry entry; if (this.geoKeys != null && (entry = this.geoKeys.get(key)) != null) { if (entry.array != this.shortParams) { String message = Logging.getMessage("GeoCodec.NotIntegerKey", key); Logging.logger().severe(message); throw new UnsupportedOperationException(message); } vals = new int[entry.count]; for (int i = 0; i < vals.length; i++) { vals[i] = 0xffff & (int) this.shortParams[entry.offset + i]; } } return vals; } /** * Gets the values of the given GeoKey as an array of doubles. * <p/> * While this method handles the general case of multiple doubles associated with a key, typically there will be * only a single value. * * @param key GeoKey value. * @return Array of double values associated with the key, or null if the key was not found. * @throws IllegalArgumentException Thrown if the key does not embody double values. */ public double[] getGeoKeyAsDoubles(int key) throws IllegalArgumentException { double[] vals = null; GeoKeyEntry entry; if (this.geoKeys != null && (entry = this.geoKeys.get(key)) != null) { if (entry.array != this.doubleParams) { String message = Logging.getMessage("GeoCodec.NotDoubleKey", key); Logging.logger().severe(message); throw new UnsupportedOperationException(message); } vals = new double[entry.count]; System.arraycopy(this.doubleParams, entry.offset, vals, 0, entry.count); } return vals; } /** * Gets the values of the given GeoKey as a String. * * @param key GeoKey value. * @return String associated with the key, or null of key was not found. * @throws IllegalArgumentException Thrown if the key does not embody ASCII characters. */ public String getGeoKeyAsString(int key) throws IllegalArgumentException { String str = null; GeoKeyEntry entry; if (this.geoKeys != null && (entry = this.geoKeys.get(key)) != null) { if (entry.array != this.asciiParams) { String message = Logging.getMessage("GeoCodec.NotAsciiKey", key); Logging.logger().severe(message); throw new UnsupportedOperationException(message); } str = new String(this.asciiParams, entry.offset, entry.count); } return str; } /* * Gets an array of the raw GeoKey tags. Returns null if no keys were decoded. * */ public int[] getGeoKeys() { if (this.geoKeys == null || this.geoKeys.size() == 0) return null; Set<Integer> keys = this.geoKeys.keySet(); int[] keyVals = new int[keys.size()]; int i = 0; for (Integer key : keys) { keyVals[i++] = key; } return keyVals; } /* * Returns true if the given key is a GeoKey in this file; false otherwise. */ public boolean hasGeoKey(int key) { return (this.geoKeys != null && this.geoKeys.get(key) != null); } // // Package visibility. Not generally intended for use by end users. // void setGeokeys(short[] keys) { // Decode the geokey entries into our internal management structure. Recall that the keys are organized as // entries of 4 shorts, where the first 4-tuple contains versioning and the number of geokeys to follow. // The remaining entries look very much like regular Tiff tags. if (keys != null && keys.length > 4) { this.shortParams = new short[keys.length]; System.arraycopy(keys, 0, this.shortParams, 0, keys.length); int numKeys = keys[3]; this.geoKeys = new HashMap<Integer, GeoKeyEntry>(); for (int i = 4; i < numKeys * 4; i += 4) { int tag = 0x0000ffff & keys[i]; int tagLoc = 0x0000ffff & keys[i + 1]; if (tagLoc == 0) { // value is in the 4th field of this entry... this.geoKeys.put(tag, new GeoKeyEntry(tag, 1, i + 3, this.shortParams)); } else { // in this case, one or more values are given relative to one of the params arrays... Object sourceArray = null; if (tagLoc == TiffTags.GEO_KEY_DIRECTORY) sourceArray = this.shortParams; else if (tagLoc == TiffTags.GEO_DOUBLE_PARAMS) sourceArray = this.doubleParams; else if (tagLoc == TiffTags.GEO_ASCII_PARAMS) sourceArray = this.asciiParams; if (sourceArray != null) this.geoKeys.put(tag, new GeoKeyEntry(tag, 0x0000ffff & keys[i + 2], 0x0000ffff & keys[i + 3], sourceArray)); } } } } // // Package visibility. Not generally intended for use by end users. // void setDoubleParams(double[] params) { this.doubleParams = new double[params.length]; System.arraycopy(params, 0, this.doubleParams, 0, params.length); } // // Package visibility. Not generally intended for use by end users. // void setAsciiParams(byte[] params) { this.asciiParams = new byte[params.length]; System.arraycopy(params, 0, this.asciiParams, 0, params.length); } private HashMap<Integer, GeoKeyEntry> geoKeys = null; // Collection of ModelTiePoints. private Vector<ModelTiePoint> tiePoints = new Vector<ModelTiePoint>(1); // ModelPixelScale values... private double xScale; private double yScale; private double zScale; private Matrix modelTransform; // the ModelTransformation matrix private short[] shortParams; // raw short parameters array private double[] doubleParams; // raw double parameters array private byte[] asciiParams; // raw ascii parameters array /* * A class to bundle up ModelTiePoints. From the Geotiff spec, a ModelTiePoint is a 6-tuple that is an * association of the pixel <i,j,k> to the model coordinate <x,y,z>. * */ public class ModelTiePoint { public double i, j, k, x, y, z; public ModelTiePoint(double i, double j, double k, double x, double y, double z) { this.i = i; this.j = j; this.k = k; this.x = x; this.y = y; this.z = z; } public double getRow() { return this.j; } public double getColumn() { return this.i; } public double getX() { return this.x; } public double getY() { return this.y; } } /* * A little class that we use to manage GeoKeys. */ private class GeoKeyEntry { int tag; int count; int offset; Object array; // a reference to one of the short/double/asciiParams arrays GeoKeyEntry(int tag, int count, int offset, Object array) { this.tag = tag; this.count = count; this.offset = offset; this.array = array; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?