Changeset 30633 in osm
- Timestamp:
- 2014-09-14T21:45:48+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/download_along
- Files:
-
- 3 added
- 2 edited
-
GPL-v2.0.txt (added)
-
GPL-v3.0.txt (added)
-
README (added)
-
src/org/openstreetmap/josm/plugin/download_along/DownloadAlong.java (modified) (2 diffs)
-
src/org/openstreetmap/josm/plugin/download_along/DownloadAlongWayAction.java (modified) (3 diffs)
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 public DownloadAlong(PluginInformation info) {11 super(info);12 MainMenu.add(Main.main.menu.moreToolsMenu, new DownloadAlongWayAction());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 private static final String PREF_DOWNLOAD_ALONG_WAY_DISTANCE = "downloadAlongWay.distance";30 private static final String PREF_DOWNLOAD_ALONG_WAY_AREA = "downloadAlongWay.area";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 private static final String PREF_DOWNLOAD_ALONG_WAY_OSM = "downloadAlongWay.download.osm";33 private static final String PREF_DOWNLOAD_ALONG_WAY_GPS = "downloadAlongWay.download.gps";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 public DownloadAlongWayAction() {36 super(tr("Download along..."), "download_along", tr("Download OSM data along the selected ways."),37 Shortcut.registerShortcut("tools:download_along", tr("Tool: {0}", tr("Download Along")),38 KeyEvent.VK_D, Shortcut.ALT_SHIFT), true);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 @Override42 public void actionPerformed(ActionEvent e) {42 @Override 43 public void actionPerformed(ActionEvent e) { 43 44 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(Main.main.getCurrentDataSet().getSelected(), Way.class); 44 45 45 if (selectedWays.isEmpty()) {46 JOptionPane.showMessageDialog(Main.parent, tr("Please select 1 or more ways to download along"));47 return;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 final DownloadAlongPanel panel = new DownloadAlongPanel(51 PREF_DOWNLOAD_ALONG_WAY_OSM, PREF_DOWNLOAD_ALONG_WAY_GPS,52 PREF_DOWNLOAD_ALONG_WAY_DISTANCE, PREF_DOWNLOAD_ALONG_WAY_AREA, null);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 if (0 != panel.showInDownloadDialog(tr("Download from OSM along selected ways"), HelpUtil.ht("/Tools/DownloadAlong"))) {55 return;56 }55 if (0 != panel.showInDownloadDialog(tr("Download from OSM along selected ways"), HelpUtil.ht("/Tools/DownloadAlong"))) { 56 return; 57 } 57 58 58 /*59 * Find the average latitude for the data we're contemplating, so we60 * can know how many metres per degree of longitude we have.61 */62 double latsum = 0;63 int latcnt = 0;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 for (Way way : selectedWays) {66 for (Node n : way.getNodes()) {67 latsum += n.getCoor().lat();68 latcnt++;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 double avglat = latsum / latcnt;73 double scale = Math.cos(Math.toRadians(avglat));73 double avglat = latsum / latcnt; 74 double scale = Math.cos(Math.toRadians(avglat)); 74 75 75 /*76 * Compute buffer zone extents and maximum bounding box size. Note77 * that the maximum we ever offer is a bbox area of 0.002, while the78 * API theoretically supports 0.25, but as soon as you touch any79 * built-up area, that kind of bounding box will download forever80 * and then stop because it has more than 50k nodes.81 */82 double buffer_dist = panel.getDistance();83 double buffer_y = buffer_dist / 100000.0;84 double buffer_x = buffer_y / scale;85 double max_area = panel.getArea() / 10000.0 / scale;86 Area a = new Area();87 Rectangle2D r = new Rectangle2D.Double();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 * Collect the combined area of all gpx points plus buffer zones91 * around them. We ignore points that lie closer to the previous92 * point than the given buffer size because otherwise this operation93 * takes ages.94 */95 LatLon previous = null;96 for (Way way : selectedWays) {97 for (Node p : way.getNodes()) {98 LatLon c = p.getCoor();99 ArrayList<LatLon> intermediateNodes = new ArrayList<LatLon>();100 if (previous != null && c.greatCircleDistance(previous) > buffer_dist) {101 Double d = c.greatCircleDistance(previous) / buffer_dist;102 int nbNodes = d.intValue();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 previous.lon()));106 for (int i = 1; i < nbNodes; i++) {107 intermediateNodes.add(new LatLon(previous.lat()108 + (i * (c.lat() - previous.lat()) / (nbNodes + 1)), previous.lon()109 + (i * (c.lon() - previous.lon()) / (nbNodes + 1))));110 System.out.println(tr(" adding {0} {1}", previous.lat()111 + (i * (c.lat() - previous.lat()) / (nbNodes + 1)), previous.lon()112 + (i * (c.lon() - previous.lon()) / (nbNodes + 1))));113 }114 }115 intermediateNodes.add(c);116 for (LatLon d : intermediateNodes) {117 if (previous == null || d.greatCircleDistance(previous) > buffer_dist) {118 // we add a buffer around the point.119 r.setRect(d.lon() - buffer_x, d.lat() - buffer_y, 2 * buffer_x, 2 * buffer_y);120 a.add(new Area(r));121 previous = d;122 }123 }124 previous = c;125 }126 }127 128 confirmAndDownloadAreas(a, max_area, panel.isDownloadOsmData(), panel.isDownloadGpxData(),129 tr("Download from OSM along selected ways"), NullProgressMonitor.INSTANCE);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 @Override133 protected void updateEnabledState() {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 @Override142 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {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.
