📄 utmgridplugin.java
字号:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/plugin/UTMGridPlugIn.java,v $// $RCSfile: UTMGridPlugIn.java,v $// $Revision: 1.8.2.6 $// $Date: 2005/10/24 14:41:18 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.plugin;import java.awt.Color;import java.awt.Component;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Paint;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Iterator;import java.util.Properties;import java.util.Vector;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JPanel;import com.bbn.openmap.I18n;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.omGraphics.OMColorChooser;import com.bbn.openmap.omGraphics.OMGeometry;import com.bbn.openmap.omGraphics.OMGeometryList;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.OMLine;import com.bbn.openmap.omGraphics.OMText;import com.bbn.openmap.omGraphics.geom.BasicGeometry;import com.bbn.openmap.omGraphics.geom.PolygonGeometry;import com.bbn.openmap.omGraphics.geom.PolylineGeometry;import com.bbn.openmap.proj.Ellipsoid;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.proj.coords.MGRSPoint;import com.bbn.openmap.proj.coords.UTMPoint;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PaletteHelper;import com.bbn.openmap.util.PropUtils;import com.bbn.openmap.util.quadtree.QuadTree;/** * The UTMGridPlugIn renders UTM Zone areas, and renders a grid * marking equal-distance areas around the center of the current * projection. This distance grid only extends east-west for 500km in * both directions from the center of the current zone because that is * the extent of accuracy for those measurements - after that, you get * too far away from the central meridian for the current UTM zone. * <p> * * Currently, this plugin only draws 100km distance squares. Updates * on the way. The plugin has the following properties that may be * set: * <p> * * <pre> * * * # Turn zone area labels on when zoomed in closer than 1:33M (true * # is default) * showZones=true * showLabels=true * # Color for UTM Zone area boundaries * utmGridColor=hex AARRGGBB value * # Color for the distance area grid lines * distanceGridColor= hex AARRGGBB value * * </pre> */public class UTMGridPlugIn extends OMGraphicHandlerPlugIn { protected boolean UTM_DEBUG = false; protected boolean UTM_DEBUG_VERBOSE = false; public final static int INTERVAL_100K = 100000; public final static float DEFAULT_UTM_LABEL_CUTOFF_SCALE = 33000000; protected boolean showZones = true; protected boolean showLabels = true; protected float labelCutoffScale = DEFAULT_UTM_LABEL_CUTOFF_SCALE; protected boolean show100kGrid = false; /** * Resolution should be MRGS accuracy, 0 for none, 1-5 otherwise, * where 1 = 10000 meter grid, 5 is 1 meter grid. */ protected int distanceGridResolution = 0; protected Paint utmGridPaint = Color.black; protected Paint distanceGridPaint = Color.black; /** * Used to hold OMText UTM zone labels. */ protected QuadTree labelTree; /** * Used for UTM zone labels. */ protected OMGraphicList labelList; /** * The vertical list of OMLines used for UTM zones. */ protected OMGraphicList verticalList; /** * The horizontal list of OMLines used for UTM zones. */ protected OMGraphicList horizontalList; public final static String ShowLabelsProperty = "showLabels"; public final static String ShowZonesProperty = "showZones"; public final static String LabelCutoffScaleProperty = "labelCutoffScale"; public final static String Show100kGridProperty = "show100KmGrid"; public final static String UTMGridColorProperty = "utmGridColor"; public final static String DistanceGridColorProperty = "distanceGridColor"; public final static String DistanceGridResolutionProperty = "distanceGridResolution"; public UTMGridPlugIn() { UTM_DEBUG = Debug.debugging("utmgrid"); UTM_DEBUG_VERBOSE = Debug.debugging("utmgrid_verbose"); } protected OMGeometryList createUTMZoneVerticalLines() { OMGeometryList verticalList = new OMGeometryList(); float[] points = null; for (int lon = -180; lon < 180; lon += 6) { if (lon == 6) { points = new float[] { 56f, lon, -80f, lon }; } else if (lon > 6 && lon < 42) { points = new float[] { 72f, lon, -80f, lon }; } else { points = new float[] { 84f, lon, -80f, lon }; } verticalList.add(new PolylineGeometry.LL(points, OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_GREATCIRCLE)); } points = new float[] { 72f, 6f, 64f, 6f }; verticalList.add(new PolylineGeometry.LL(points, OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_GREATCIRCLE)); points = new float[] { 64f, 3f, 56f, 3f }; verticalList.add(new PolylineGeometry.LL(points, OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_GREATCIRCLE)); points = new float[] { 84f, 9f, 72f, 9f }; verticalList.add(new PolylineGeometry.LL(points, OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_GREATCIRCLE)); points = new float[] { 84f, 21f, 72f, 21f }; verticalList.add(new PolylineGeometry.LL(points, OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_GREATCIRCLE)); points = new float[] { 84f, 33f, 72f, 33f }; verticalList.add(new PolylineGeometry.LL(points, OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_GREATCIRCLE)); verticalList.setLinePaint(utmGridPaint); return verticalList; } protected OMGeometryList createUTMZoneHorizontalLines() { OMGeometryList horizontalList = new OMGeometryList(); float[] points = null; for (float lat = -80f; lat <= 72f; lat += 8f) { points = new float[] { lat, -180f, lat, -90f, lat, 0f, lat, 90f, lat, 180f }; horizontalList.add(new PolylineGeometry.LL(points, OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_RHUMB)); } points = new float[] { 84f, -180f, 84f, -90f, 84f, 0f, 84f, 90f, 84f, 180f }; horizontalList.add(new PolylineGeometry.LL(points, OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_RHUMB)); horizontalList.setLinePaint(utmGridPaint); return horizontalList; } protected QuadTree createUTMZoneLabels() { QuadTree labelTree = new QuadTree(); // Need to use MGRSPoint to get MGRS zone letters, the UTM // zone letters are N and S for the hemisphere, which isn't // very interesting. UTMPoint utm = new MGRSPoint(); LatLonPoint llp = new LatLonPoint(); float latitude; float longitude; for (int lat = -80; lat <= 72; lat += 8) { for (int lon = -180; lon < 180; lon += 6) { latitude = (float) lat; longitude = (float) lon; if (lat == 56 && lon == 6) { longitude = 3f; } else if (lat == 72 && (lon > 0 && lon < 42)) { continue; } llp.setLatLon(latitude, longitude); addLabel(llp, UTMPoint.LLtoUTM(llp, utm), labelTree); } } latitude = 72f; llp.setLatLon(latitude, 9f); addLabel(llp, UTMPoint.LLtoUTM(llp, utm), labelTree); llp.setLongitude(21f); addLabel(llp, UTMPoint.LLtoUTM(llp, utm), labelTree); llp.setLongitude(33f); addLabel(llp, UTMPoint.LLtoUTM(llp, utm), labelTree); return labelTree; } protected void addLabel(LatLonPoint llp, UTMPoint utm, QuadTree labelTree) { float latitude = llp.getLatitude(); float longitude = llp.getLongitude(); labelTree.put(latitude, longitude, new OMText(latitude, longitude, 2, -2, utm.zone_number + "" + utm.zone_letter, OMText.JUSTIFY_LEFT)); } /** * Called to create 100km distance grid lines. Was originally * designed to accept different gridLineInterval distances, but * has only been debugged and tested for 100000. * * @param utm the UTMPoint of the center of the area to create * lines for. */ protected OMGraphicList createEquiDistanceLines(UTMPoint utm, int gridLineInterval) { OMGraphicList list = new OMGraphicList(); // Used to calculate the endpoints of the horizontal lines. UTMPoint utm1 = new UTMPoint(utm); UTMPoint utm2 = new UTMPoint(utm); LatLonPoint point1 = new LatLonPoint(); LatLonPoint point2 = new LatLonPoint(); // Used to calculate the pieces of the vertical lines. UTMPoint utmp = new UTMPoint(utm); LatLonPoint llp = new LatLonPoint(); int i; OMLine line; BasicGeometry poly; float lat2; int endNorthing = (int) Math.floor(utm.northing / INTERVAL_100K) + 10; int startNorthing = (int) Math.floor(utm.northing / INTERVAL_100K) - 10; int numVertLines = 9; int numHorLines = endNorthing - startNorthing; float[][] vertPoints = new float[numVertLines][numHorLines * 2]; if (UTM_DEBUG_VERBOSE) { Debug.output("Array is [" + vertPoints.length + "][" + vertPoints[0].length + "]"); } int coordCount = 0; boolean doPolys = true; utm1.easting = INTERVAL_100K; utm2.easting = 9 * INTERVAL_100K; // Horizontal lines for (i = startNorthing; i < endNorthing; i++) { utm1.northing = (float) i * gridLineInterval; utm2.northing = utm1.northing; utmp.northing = utm1.northing; if (doPolys) { for (int j = 0; j < numVertLines; j++) { utmp.easting = (float) (j + 1) * gridLineInterval; llp = utmp.toLatLonPoint(Ellipsoid.WGS_84, llp); vertPoints[j][coordCount] = llp.getLatitude(); vertPoints[j][coordCount + 1] = llp.getLongitude(); if (UTM_DEBUG_VERBOSE) { Debug.output("for vline " + j + ", point " + i + ", easting: " + utmp.easting + ", northing: " + utmp.northing + ", lat:" + vertPoints[j][coordCount] + ", lon:" + vertPoints[j][coordCount + 1]); } } coordCount += 2; } point1 = utm1.toLatLonPoint(Ellipsoid.WGS_84, point1); point2 = utm2.toLatLonPoint(Ellipsoid.WGS_84, point2); lat2 = point1.getLatitude(); if (lat2 < 84f) { line = new OMLine(point1.getLatitude(), point1.getLongitude(), point2.getLatitude(), point2.getLongitude(), OMGraphic.LINETYPE_GREATCIRCLE); line.setLinePaint(distanceGridPaint); list.add(line); } } if (doPolys) { OMGeometryList polys = new OMGeometryList(); for (i = 0; i < vertPoints.length; i++) { if (UTM_DEBUG_VERBOSE) { for (int k = 0; k < vertPoints[i].length; k += 2) { System.out.println(" for poly " + i + ": lat = " + vertPoints[i][k] + ", lon = " + vertPoints[i][k + 1]); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -