📄 dtedframecache.java
字号:
* @param ullat upper latitude, in decimal degrees * @param ullon left longitude, in decimal degrees * @param lrlat lower latitude, in decimal degrees * @param lrlon right longitude, in decimal degrees * @param dtedLevel the DTED level (0, 1, 2) to be used, which * describes the geographicsal spacing between the posts. */ public short[][] getElevations(float ullat, float ullon, float lrlat, float lrlon, int dtedLevel) { return getElevations(ullat, ullon, lrlat, lrlon, dtedLevel, null); } /** * Return the two-dimensional matrix of elevation posts (heights) * representing coverage of a given geographical rectangle. The * matrix represents coverage in an Equal Arc projection. Doesn't * handle projections which cross the dateline - You must handle * that yourself by making two inquiries. * <P> * This method is slightly different that the one above, because * it includes a input variable DTEDFrame. There is an inherent * problem in the algorithm if some of the DTED frames are * missing. It's too difficult to calculate the size of the return * array if you don't know that any frames are available. So, you * should always use the method above, which calls this method * with a null refFrame. If some of the DTED frames are missing, * then this method is called recursively, with a frame to use for * calculating post spacings at the right time. * * @param ullat upper latitude, in decimal degrees * @param ullon left longitude, in decimal degrees * @param lrlat lower latitude, in decimal degrees * @param lrlon right longitude, in decimal degrees * @param dtedLevel the DTED level (0, 1, 2) to be used, which * describes the geographicsal spacing between the posts. * @param refFrame DTEDFrame used to calculate measurements. * @return array of elevations, in meters. Spacing depends on the * DTED level. */ protected short[][] getElevations(float ullat, float ullon, float lrlat, float lrlon, int dtedLevel, DTEDFrame refFrame) { float upper = ullat; float lower = lrlat; float right = lrlon; float left = ullon; // Since matrix indexes depend on these being in the right // order, we'll double check and flip values, just to make // sure lower is lower, and higher is higher. if (ullon > lrlon) { if (ullon > 0 && lrlon < 0) { Debug.error("DTEDFrameCache: getElevations: Stradling dateline not handled!"); return null; } right = ullon; left = lrlon; } if (lrlat > ullat) { upper = lrlat; lower = ullat; } // These are the limits of the lat/lons per frame searched float upperlat = 0; float upperlon = 0; float lowerlat = 0; float lowerlon = 0; int xSize = (int) (Math.ceil(right) - Math.floor(left)); int ySize = (int) (Math.ceil(upper) - Math.floor(lower)); // System.out.println("Going with size = " + xSize + "x" + // ySize); int[] xLengths = new int[xSize]; int[] yLengths = new int[ySize]; short[][][][] es = new short[xSize][ySize][][]; int x, y; DTEDFrame frame = null; boolean needCalc = false; // Let's march through the frames, bottom to top, left to // right. for (x = 0; x < xSize; x++) { if (x == 0) lowerlon = left; else lowerlon = (float) Math.floor(left) + (float) x; if (x == xSize - 1) upperlon = right; else upperlon = (float) Math.floor(left) + (float) (x + 1); for (y = 0; y < ySize; y++) { if (y == 0) lowerlat = lower; else lowerlat = (float) Math.floor(lower) + (float) y; if (y == ySize - 1) upperlat = upper; else upperlat = (float) Math.floor(lower) + (float) (y + 1); DTEDFrame thisFrame = get(lowerlat, lowerlon, dtedLevel); if (thisFrame != null) { // System.out.println("Getting elev for " + // upperlat + ", " + // lowerlon + ", " + // lowerlat+ ", " + upperlon); es[x][y] = thisFrame.getElevations(upperlat, lowerlon, lowerlat, upperlon); xLengths[x] = es[x][y].length; yLengths[y] = es[x][y][0].length; frame = thisFrame; } else { if (refFrame != null) { Debug.output("DTEDFrameCache: Missing frames, going to use reference frame"); // calculate these lengths, since the refFrame // was set... int[] indexes = refFrame.getIndexesFromLatLons(upperlat, lowerlon, lowerlat, upperlon); xLengths[x] = indexes[2] - indexes[0] + 1; yLengths[y] = indexes[3] - indexes[1] + 1; } else { if (frame != null) { // Well, we have a frame to do // calculations on, and we know we need // to do at least one calculation, so // might as well go and do this right... return getElevations(ullat, ullon, lrlat, lrlon, dtedLevel, frame); } else { needCalc = true; } } } } } // refFrame == null, and all the empty frames were found // before the good ones... if (needCalc == true && frame != null) return getElevations(ullat, ullon, lrlat, lrlon, dtedLevel, frame); int xLength = 0; int yLength = 0; // Need to figure out how big the returned matrix is! This // only works if all the frames come back.... for (x = 0; x < xLengths.length; x++) xLength += xLengths[x]; for (y = 0; y < yLengths.length; y++) yLength += yLengths[y]; // System.out.println("Creating a matrix: " + xLength + "x" + // yLength); short[][] matrix = new short[xLength][yLength]; // Now copy all the little matrixes into the big matrix int xspacer = 0; // Through each little matrix in the x direction for (x = 0; x < es.length; x++) { int yspacer = 0; // Through each little matrix in the y direction for (y = 0; y < es[x].length; y++) { // Make sure the frame exists and is found... if (es[x][y] != null) { // Through each lon row in each little matrix for (int i = 0; i < es[x][y].length; i++) { System.arraycopy(es[x][y][i], 0, matrix[i + xspacer], yspacer, es[x][y][i].length); } // On the last one lon column, increase the spacer // for the // next little matrix above this one. yspacer += yLengths[y]; } else yspacer += xLengths[y]; } // On the last little matrix in the column, increase the // xspacer for the little matrixes in the next column. xspacer += xLengths[x]; } return matrix; } /** * PropertyConsumer method. */ public void setPropertyPrefix(String prefix) { propertyPrefix = prefix; } /** * PropertyConsumer method. */ public String getPropertyPrefix() { return propertyPrefix; } /** * PropertyConsumer method. */ public void setProperties(Properties props) { setProperties(null, props); } /** * PropertyConsumer method. */ public void setProperties(String prefix, Properties props) { setPropertyPrefix(prefix); prefix = PropUtils.getScopedPropertyPrefix(this); // Space-separated list of marker names for different // DTEDDirectoryHandlers Vector directoryHandlerList = PropUtils.parseSpacedMarkers(props.getProperty(prefix + DTEDDirectoryHandlerProperty)); for (Iterator it = directoryHandlerList.iterator(); it.hasNext();) { String handlerPrefix = (String) it.next(); DTEDDirectoryHandler handler = new DTEDDirectoryHandler(); handler.setProperties(prefix + handlerPrefix, props); addDTEDDirectoryHandler(handler); } resetCache(PropUtils.intFromProperties(props, prefix + DTEDFrameCacheSizeProperty, DEFAULT_CACHE_SIZE)); } /** * PropertyConsumer method. */ public Properties getProperties(Properties props) { if (props == null) { props = new Properties(); } String prefix = PropUtils.getScopedPropertyPrefix(this); props.put(prefix + DTEDFrameCacheSizeProperty, Integer.toString(getCacheSize())); // Directory handler properties... if (directories != null) { StringBuffer dhPrefixes = new StringBuffer(); for (Iterator it = directories.iterator(); it.hasNext();) { DTEDDirectoryHandler ddh = (DTEDDirectoryHandler) it.next(); String dhPrefix = ddh.getPropertyPrefix(); if (dhPrefix != null) { int index = dhPrefix.indexOf(prefix); if (index != -1) { dhPrefixes.append(dhPrefix.substring(index + prefix.length()) + " "); } ddh.getProperties(props); } } props.put(prefix + DTEDDirectoryHandlerProperty, dhPrefixes.toString()); } return props; } /** * PropertyConsumer method. */ public Properties getPropertyInfo(Properties props) { if (props == null) { props = new Properties(); } props.put(DTEDFrameCacheSizeProperty, "Size of the frame cache"); // Not sure how to handle setting up a DTEDDirectoryHandler // yet. return props; } public static void main(String[] args) { Debug.init(); if (args.length < 1) { Debug.output("DTEDFrameCache: Need a path/filename"); System.exit(0); } Debug.output("DTEDFrameCache: " + args[0]); DTEDFrameCache dfc = new DTEDFrameCache(10); // 35.965065 -121.198715 //35.998 36.002 lon -121.002 -120.998 float ullat = 37.002f; float ullon = -121.002f; float lrlat = 35.998f; float lrlon = -119.998f; // System.out.println("Getting elevations for " + // ullat + ", " + ullon + ", " + // lrlat + ", " + lrlon); short[][] e = dfc.getElevations(ullat, ullon, lrlat, lrlon, 0); if (e != null) { for (int i = e[0].length - 1; i >= 0; i--) { int col = 0; System.out.print("r" + i + "-"); for (int j = 0; j < e.length; j++) { System.out.print(e[j][i] + " "); col++; } System.out.println(" - " + col); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -