Changeset 30633 in osm for applications
- Timestamp:
- 2014-09-14T21:45:48+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/download_along
- Files:
-
- 3 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/download_along/src/org/openstreetmap/josm/plugin/download_along/DownloadAlong.java
r29778 r30633 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugin.download_along; 2 3 … … 8 9 public class DownloadAlong extends Plugin { 9 10 10 11 12 13 11 public DownloadAlong(PluginInformation info) { 12 super(info); 13 MainMenu.add(Main.main.menu.moreToolsMenu, new DownloadAlongWayAction()); 14 } 14 15 } -
applications/editors/josm/plugins/download_along/src/org/openstreetmap/josm/plugin/download_along/DownloadAlongWayAction.java
r29778 r30633 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugin.download_along; 2 3 … … 27 28 class DownloadAlongWayAction extends DownloadAlongAction { 28 29 29 30 30 private static final String PREF_DOWNLOAD_ALONG_WAY_DISTANCE = "downloadAlongWay.distance"; 31 private static final String PREF_DOWNLOAD_ALONG_WAY_AREA = "downloadAlongWay.area"; 31 32 32 33 33 private static final String PREF_DOWNLOAD_ALONG_WAY_OSM = "downloadAlongWay.download.osm"; 34 private static final String PREF_DOWNLOAD_ALONG_WAY_GPS = "downloadAlongWay.download.gps"; 34 35 35 36 37 38 39 36 public DownloadAlongWayAction() { 37 super(tr("Download along..."), "download_along", tr("Download OSM data along the selected ways."), 38 Shortcut.registerShortcut("tools:download_along", tr("Tool: {0}", tr("Download Along")), 39 KeyEvent.VK_D, Shortcut.ALT_SHIFT), true); 40 } 40 41 41 42 42 @Override 43 public void actionPerformed(ActionEvent e) { 43 44 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(Main.main.getCurrentDataSet().getSelected(), Way.class); 44 45 45 46 47 48 46 if (selectedWays.isEmpty()) { 47 JOptionPane.showMessageDialog(Main.parent, tr("Please select 1 or more ways to download along")); 48 return; 49 } 49 50 50 51 52 51 final DownloadAlongPanel panel = new DownloadAlongPanel( 52 PREF_DOWNLOAD_ALONG_WAY_OSM, PREF_DOWNLOAD_ALONG_WAY_GPS, 53 PREF_DOWNLOAD_ALONG_WAY_DISTANCE, PREF_DOWNLOAD_ALONG_WAY_AREA, null); 53 54 54 55 56 55 if (0 != panel.showInDownloadDialog(tr("Download from OSM along selected ways"), HelpUtil.ht("/Tools/DownloadAlong"))) { 56 return; 57 } 57 58 58 59 60 61 62 63 59 /* 60 * Find the average latitude for the data we're contemplating, so we 61 * can know how many metres per degree of longitude we have. 62 */ 63 double latsum = 0; 64 int latcnt = 0; 64 65 65 66 67 68 69 70 66 for (Way way : selectedWays) { 67 for (Node n : way.getNodes()) { 68 latsum += n.getCoor().lat(); 69 latcnt++; 70 } 71 } 71 72 72 73 73 double avglat = latsum / latcnt; 74 double scale = Math.cos(Math.toRadians(avglat)); 74 75 75 76 77 78 79 80 81 82 83 84 85 86 87 76 /* 77 * Compute buffer zone extents and maximum bounding box size. Note 78 * that the maximum we ever offer is a bbox area of 0.002, while the 79 * API theoretically supports 0.25, but as soon as you touch any 80 * built-up area, that kind of bounding box will download forever 81 * and then stop because it has more than 50k nodes. 82 */ 83 double buffer_dist = panel.getDistance(); 84 double buffer_y = buffer_dist / 100000.0; 85 double buffer_x = buffer_y / scale; 86 double max_area = panel.getArea() / 10000.0 / scale; 87 Area a = new Area(); 88 Rectangle2D r = new Rectangle2D.Double(); 88 89 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 System.out.println(tr("{0} intermediate nodes to download.", nbNodes));104 System.out.println(tr("between {0} {1} and {2} {3}", c.lat(), c.lon(), previous.lat(),105 106 107 108 109 110 System.out.println(tr(" adding {0} {1}", previous.lat()111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 90 /* 91 * Collect the combined area of all gpx points plus buffer zones 92 * around them. We ignore points that lie closer to the previous 93 * point than the given buffer size because otherwise this operation 94 * takes ages. 95 */ 96 LatLon previous = null; 97 for (Way way : selectedWays) { 98 for (Node p : way.getNodes()) { 99 LatLon c = p.getCoor(); 100 ArrayList<LatLon> intermediateNodes = new ArrayList<LatLon>(); 101 if (previous != null && c.greatCircleDistance(previous) > buffer_dist) { 102 Double d = c.greatCircleDistance(previous) / buffer_dist; 103 int nbNodes = d.intValue(); 104 Main.info(tr("{0} intermediate nodes to download.", nbNodes)); 105 Main.info(tr("between {0} {1} and {2} {3}", c.lat(), c.lon(), previous.lat(), 106 previous.lon())); 107 for (int i = 1; i < nbNodes; i++) { 108 intermediateNodes.add(new LatLon(previous.lat() 109 + (i * (c.lat() - previous.lat()) / (nbNodes + 1)), previous.lon() 110 + (i * (c.lon() - previous.lon()) / (nbNodes + 1)))); 111 Main.info(tr(" adding {0} {1}", previous.lat() 112 + (i * (c.lat() - previous.lat()) / (nbNodes + 1)), previous.lon() 113 + (i * (c.lon() - previous.lon()) / (nbNodes + 1)))); 114 } 115 } 116 intermediateNodes.add(c); 117 for (LatLon d : intermediateNodes) { 118 if (previous == null || d.greatCircleDistance(previous) > buffer_dist) { 119 // we add a buffer around the point. 120 r.setRect(d.lon() - buffer_x, d.lat() - buffer_y, 2 * buffer_x, 2 * buffer_y); 121 a.add(new Area(r)); 122 previous = d; 123 } 124 } 125 previous = c; 126 } 127 } 128 129 confirmAndDownloadAreas(a, max_area, panel.isDownloadOsmData(), panel.isDownloadGpxData(), 130 tr("Download from OSM along selected ways"), NullProgressMonitor.INSTANCE); 131 } 131 132 132 133 133 @Override 134 protected void updateEnabledState() { 134 135 if (getCurrentDataSet() == null) { 135 136 setEnabled(false); … … 137 138 updateEnabledState(getCurrentDataSet().getSelected()); 138 139 } 139 140 } 140 141 141 142 142 @Override 143 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 143 144 setEnabled(Utils.exists(selection, OsmPrimitive.wayPredicate)); 144 145 } 145 146 }
Note:
See TracChangeset
for help on using the changeset viewer.