📄 utmgridplugin.java
字号:
poly = new PolylineGeometry.LL(vertPoints[i], OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_GREATCIRCLE); polys.add(poly); } polys.setLinePaint(distanceGridPaint); list.add(polys); } else { // This doesn't seem to calculate the right // lines, although it looks like it should. if (UTM_DEBUG) { Debug.output("Doing vertical lines"); } utm1.northing = startNorthing; utm2.northing = endNorthing; // Vertical lines for (i = 1; i <= 9; i++) { utm1.easting = i * 100000f; utm2.easting = i * 100000f; point1 = utm1.toLatLonPoint(Ellipsoid.WGS_84, point1); point2 = utm2.toLatLonPoint(Ellipsoid.WGS_84, point2); line = new OMLine(point1.getLatitude(), point1.getLongitude(), point2.getLatitude(), point2.getLongitude(), OMGraphic.LINETYPE_GREATCIRCLE); line.setLinePaint(distanceGridPaint); list.add(line); } } return list; } /** * Create a list of rectangles representing equal areas of MGRS * coordinates around a lat/lon location. The rectangles are laid * out on the MGRS grid, their size determined by the accuracy * limitation given, which reflects how many digits are provided * in a MGRS coordinate. Uses WGS 84 ellipsoid. * * @param llp the lat/lon point of concern. * @param accuracy the number of digits for northing and easting * values of a MGRS coordinate, which implicitly translates * to meters - 5 (1 meter) to 1 (10,000 meter). * @param numRects the number of rectangles in each direction from * the llp to create. */ protected OMGeometryList createMGRSRectangles(LatLonPoint llp, int accuracy, int numRects) { return createMGRSRectangles(llp, accuracy, numRects, Ellipsoid.WGS_84); } /** * Create a list of rectangles representing equal areas of MGRS * coordinates around a lat/lon location. The rectangles are laid * out on the MGRS grid, their size determined by the accuracy * limitation given, which reflects how many digits are provided * in a MGRS coordinate. * * @param llp the lat/lon point of concern. * @param accuracy the number of digits for northing and easting * values of a MGRS coordinate, which implicitly translates * to meters - 5 (1 meter) to 1 (10,000 meter). * @param numRects the number of rectangles in each direction from * the llp to create. * @param ellipsoid the ellipsoid to use. */ protected OMGeometryList createMGRSRectangles(LatLonPoint llp, int accuracy, int numRects, Ellipsoid ellipsoid) { MGRSPoint mgrs = new MGRSPoint(); mgrs.setAccuracy(accuracy); MGRSPoint.LLtoMGRS(llp, ellipsoid, mgrs); mgrs = new MGRSPoint(mgrs.getMGRS()); mgrs.setAccuracy(accuracy); float accuracyBonus = 100000f / (float) Math.pow(10, accuracy); OMGeometryList list = new OMGeometryList(); for (float i = -numRects * accuracyBonus; i < numRects * accuracyBonus; i += accuracyBonus) { for (float j = -numRects * accuracyBonus; j < numRects * accuracyBonus; j += accuracyBonus) { if (Debug.debugging("utmdistancegrid")) { System.out.print("."); } list.add(createMGRSRectangle(mgrs, i, j, accuracyBonus, ellipsoid)); } if (Debug.debugging("utmdistancegrid")) { System.out.println(""); } } return list; } /** * Create a polygon representing an equidistant area, at a meters * offset with a meters interval. * * @param mgrsBasePoint the center point of interest that has been * normalized for the units of the rectangle (meters, km, * etc). * @param voffset vertical offset in meters, normalized for units, * for entire polygon. * @param hoffset horizontal offset in meters, normalized for * units, for entire polygon. * @param interval edge length of rectangle polygon in meters, * normalized for units. * @param ellipsoid Ellipsoid for coordinate translation. */ protected OMGeometry createMGRSRectangle(MGRSPoint mgrsBasePoint, float voffset, float hoffset, float interval, Ellipsoid ellipsoid) { float[] llpoints = new float[10]; float easting = mgrsBasePoint.easting + hoffset; float northing = mgrsBasePoint.northing + voffset; int zone_number = mgrsBasePoint.zone_number; char zone_letter = mgrsBasePoint.zone_letter; LatLonPoint llp1 = new LatLonPoint(); MGRSPoint.MGRStoLL(ellipsoid, northing, easting, zone_number, zone_letter, llp1); llpoints[0] = llp1.getLatitude(); llpoints[1] = llp1.getLongitude(); llpoints[8] = llp1.getLatitude(); llpoints[9] = llp1.getLongitude(); MGRSPoint.MGRStoLL(ellipsoid, northing, easting + interval, zone_number, zone_letter, llp1); llpoints[2] = llp1.getLatitude(); llpoints[3] = llp1.getLongitude(); MGRSPoint.MGRStoLL(ellipsoid, northing + interval, easting + interval, zone_number, zone_letter, llp1); llpoints[4] = llp1.getLatitude(); llpoints[5] = llp1.getLongitude(); MGRSPoint.MGRStoLL(ellipsoid, northing + interval, easting, zone_number, zone_letter, llp1); llpoints[6] = llp1.getLatitude(); llpoints[7] = llp1.getLongitude(); MGRSPoint mgrs = new MGRSPoint(northing, easting, zone_number, zone_letter); mgrs.setAccuracy(mgrsBasePoint.getAccuracy()); MGRSPoint.MGRStoLL(mgrs, ellipsoid, llp1); String mgrsString = mgrs.getMGRS(); if (Debug.debugging("utmgriddetail")) Debug.output(" - assigning " + mgrsString + " to poly with " + mgrs.getAccuracy()); PolygonGeometry poly = new PolygonGeometry.LL(llpoints, OMGraphic.DECIMAL_DEGREES, (interval <= 1000 ? OMGraphic.LINETYPE_STRAIGHT : OMGraphic.LINETYPE_GREATCIRCLE)); poly.setAppObject(mgrsString); return poly; } /** * The getRectangle call is the main call into the PlugIn module. * The module is expected to fill the graphics list with objects * that are within the screen parameters passed. * * @param p projection of the screen, holding scale, center * coords, height, width. */ public OMGraphicList getRectangle(Projection p) { OMGraphicList list = getList(); if (verticalList == null) { verticalList = createUTMZoneVerticalLines(); horizontalList = createUTMZoneHorizontalLines(); labelTree = createUTMZoneLabels(); } list.clear(); if (showZones) { list.add(verticalList); list.add(horizontalList); } LatLonPoint center = p.getCenter(); UTMPoint utm = new UTMPoint(center); if (show100kGrid) { Debug.message("utmgrid", "Creating 100k distance lines..."); OMGraphicList hunKLines = createEquiDistanceLines(utm, 100000); list.add(hunKLines); } if (distanceGridResolution > 0) { Debug.message("utmgrid", "Creating distance lines..."); float decisionAid = 100000f / (float) Math.pow(10, distanceGridResolution); float dglc = 30f * decisionAid; // distance grid label // cutoff // Debug.output("Basing decision to display labels on " + // dglc); int numberBasedForScale = (int) (p.getScale() / (2 * decisionAid)); if (numberBasedForScale > 10) { numberBasedForScale = 10; } // Debug.output(numberBasedForScale + ""); OMGeometryList geoList = createMGRSRectangles(center, distanceGridResolution, numberBasedForScale); if (showLabels && p.getScale() <= dglc) { Debug.message("utmgrid", "Creating labels for distance lines ..."); OMGraphicList textList = new OMGraphicList(); LatLonPoint llp = new LatLonPoint(); Point point = new Point(); Iterator it = geoList.iterator(); while (it.hasNext()) { PolygonGeometry.LL pll = (PolygonGeometry.LL) it.next(); String labelString = (String) (pll).getAppObject(); if (labelString == null) { continue; } float[] ll = pll.getLatLonArray(); llp.setLatLon(ll[0], ll[1], true); p.forward(llp, point); double x = point.getX(); double y = point.getY(); int buffer = 20; // Lame attempt of testing whether the label is // on-screen if ((x > -buffer || x < p.getWidth() + buffer) && (y > -buffer || y < p.getHeight() + buffer)) { OMText label = new OMText(llp.getLatitude(), llp.getLongitude(), 4, -4, labelString, OMText.JUSTIFY_LEFT); label.setLinePaint(distanceGridPaint); textList.add(label); } } list.add(textList); } geoList.setLinePaint(distanceGridPaint); list.add(geoList); } if (labelList != null) { labelList.clear(); } else { labelList = new OMGraphicList(); } if (showLabels && p.getScale() <= labelCutoffScale) { Debug.message("utmgrid", "Creating labels for map..."); LatLonPoint ul = p.getUpperLeft(); LatLonPoint lr = p.getLowerRight(); Vector labels = labelTree.get(ul.getLatitude(), ul.getLongitude(), lr.getLatitude(), lr.getLongitude()); labelList.setTargets(labels); labelList.setLinePaint(getUTMGridPaint()); list.add(labelList); } Debug.message("utmgrid", "Generating OMGraphics..."); list.generate(p); Debug.message("utmgrid", "Done."); return list; } //end getRectangle public Component getGUI() { JPanel panel = new JPanel(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); panel.setLayout(gridbag); JCheckBox setZonesButton = new JCheckBox(i18n.get(UTMGridPlugIn.class, "setZonesButton", "Show UTM Zone Grid"), showZones); setZonesButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JCheckBox button = (JCheckBox) ae.getSource(); showZones = button.isSelected(); doPrepare(); } }); c.gridy = 0; c.anchor = GridBagConstraints.WEST; gridbag.setConstraints(setZonesButton, c); panel.add(setZonesButton); JCheckBox set100kGridButton = new JCheckBox(i18n.get(UTMGridPlugIn.class, "set100kGridButton", "Show 100Km Distance Grid"), show100kGrid); set100kGridButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JCheckBox button = (JCheckBox) ae.getSource(); show100kGrid = button.isSelected(); doPrepare(); } });
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -