Changeset 26662 in osm for applications
- Timestamp:
- 2011-09-17T14:03:03+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/build.xml
r26644 r26662 30 30 <project name="utilsplugin2" default="dist" basedir="."> 31 31 <!-- enter the SVN commit message --> 32 <property name="commit.message" value="Utilsplugin2: select all inside (testing)"/>32 <property name="commit.message" value="Utilsplugin2: select all inside multipolygon added"/> 33 33 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 34 34 <property name="plugin.main.version" value="4395"/> … … 245 245 </java> 246 246 </target> 247 248 249 <target name="profilejosm" depends="install"> 250 <nbprofiledirect> 251 </nbprofiledirect> 252 <java jar="${josm}" fork="true"> 253 <arg line="e:/test.osm"/> 254 <jvmarg value="${profiler.info.jvmargs.agent}"/> 255 </java> 256 </target> 247 257 </project> -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/OpenPageAction.java
r26639 r26662 44 44 45 45 public OpenPageAction() { 46 super(tr("Open custom URL"), "openurl", tr("Opens specified URL browser"), 47 Shortcut.registerShortcut("tools:openaddress", tr("Tool: {0}", tr("Open custom URL")), 48 KeyEvent.VK_BACK_SLASH, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true); 46 super(tr("Open custom URL"), "openurl", 47 tr("Opens specified URL browser"), 48 Shortcut.registerShortcut("tools:openurl", tr("Tool: {0}", tr("Open custom URL")), 49 KeyEvent.VK_BACK_SLASH, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true); 49 50 putValue("help", ht("/Action/OpenPage")); 50 51 } -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/NodeWayUtils.java
r26644 r26662 2 2 package utilsplugin2.selection; 3 3 4 import org.openstreetmap.josm.data.osm.Relation; 5 import java.util.ArrayList; 4 6 import java.util.Iterator; 5 7 import java.util.Collection; … … 7 9 import java.util.List; 8 10 import java.util.Set; 11 9 12 import javax.swing.JOptionPane; 10 13 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.data.coor.EastNorth; 11 15 import org.openstreetmap.josm.data.osm.BBox; 12 16 import org.openstreetmap.josm.data.osm.DataSet; … … 266 270 267 271 272 static void addAllInsideMultipolygon(DataSet data, Relation rel, Set<Way> newWays, Set<Node> newNodes) { 273 if (!rel.isMultipolygon()) return; 274 BBox box = rel.getBBox(); 275 Set<Way> usedWays = OsmPrimitive.getFilteredSet(rel.getMemberPrimitives(), Way.class); 276 List<EastNorth> polyPoints = new ArrayList<EastNorth>(10000); 277 278 for (Way way: usedWays) { 279 List<Node> polyNodes = way.getNodes(); 280 // converts all points to EastNorth 281 for (Node n: polyNodes) polyPoints.add(n.getEastNorth()); 282 } 283 284 285 List<Node> searchNodes = data.searchNodes(box); 286 Set<Node> newestNodes = new HashSet<Node>(); 287 Set<Way> newestWays = new HashSet<Way>(); 288 for (Node n : searchNodes) { 289 //if (Geometry.nodeInsidePolygon(n, polyNodes)) { 290 if (NodeWayUtils.isPointInsidePolygon(n.getEastNorth(), polyPoints)>0) { 291 newestNodes.add(n); 292 } 293 } 294 295 List<Way> searchWays = data.searchWays(box); 296 for (Way w : searchWays) { 297 if (newestNodes.containsAll(w.getNodes())) { 298 newestWays.add(w); 299 } 300 } 301 for (Way w : newestWays) { 302 newestNodes.removeAll(w.getNodes()); 303 // do not select nodes of already selected ways 304 } 305 306 newNodes.addAll(newestNodes); 307 newWays.addAll(newestWays); 308 } 268 309 269 310 static void addAllInsideWay(DataSet data, Way way, Set<Way> newWays, Set<Node> newNodes) { … … 271 312 BBox box = way.getBBox(); 272 313 List<Node> polyNodes = way.getNodes(); 314 List<EastNorth> polyPoints = new ArrayList<EastNorth>(polyNodes.size()); 315 316 // converts all points to EastNorth 317 for (Node n: polyNodes) polyPoints.add(n.getEastNorth()); 318 273 319 List<Node> searchNodes = data.searchNodes(box); 274 320 Set<Node> newestNodes = new HashSet<Node>(); 275 321 Set<Way> newestWays = new HashSet<Way>(); 276 322 for (Node n : searchNodes) { 277 if (Geometry.nodeInsidePolygon(n, polyNodes)) { 323 //if (Geometry.nodeInsidePolygon(n, polyNodes)) { 324 if (NodeWayUtils.isPointInsidePolygon(n.getEastNorth(), polyPoints)>0) { 278 325 newestNodes.add(n); 279 326 } … … 294 341 newWays.addAll(newestWays); 295 342 } 343 344 /** 345 * @return 0 = not inside polygon, 1 = strictly inside, 2 = near edge, 3 = near vertex 346 */ 347 public static int isPointInsidePolygon(EastNorth point, List<EastNorth> polygonPoints) { 348 int n=polygonPoints.size(); 349 EastNorth oldPoint = polygonPoints.get(n-1); 350 double n1,n2,n3,e1,e2,e3,d; 351 int interCount=0; 352 353 for (EastNorth curPoint : polygonPoints) { 354 n1 = curPoint.north(); n2 = oldPoint.north(); n3 = point.north(); 355 e1 = curPoint.east(); e2 = oldPoint.east(); e3 = point.east(); 356 357 if (Math.abs(n1-n3)<1e-5 && Math.abs(e1-e3)<1e-5) return 3; // vertex 358 if (Math.abs(n2-n3)<1e-5 && Math.abs(e2-e3)<1e-5) return 3; // vertex 359 360 // looking at oldPoint-curPoint segment 361 if ( n1 > n2) { 362 if (n1 > n3 && n3 >= n2) { 363 n1-=n3; n2-=n3; e1-=e3; e2-=e3; 364 d = e1*n2 - n1*e2; 365 if (d<-1e-5) { 366 interCount++; // there is OX intersecthion at e = (e1n2-e2n1)/(n2-n1) >=0 367 } else if (d<=1e-5) return 2; // boundary detected 368 } 369 } else if (n1 == n2) { 370 if (n1 == n3) { 371 e1-=e3; e2-=e3; 372 if ((e1 <=0 && e2 >= 0) || (e1 >=0 && e2 <= 0)) return 2;// boundary detected 373 } 374 } else { 375 if (n1 <= n3 && n3 < n2) { 376 n1-=n3; n2-=n3; e1-=e3; e2-=e3; 377 d = e1*n2 - n1*e2; 378 if (d>1e-5) { 379 interCount++; // there is OX intersecthion at e = (e1n2-e2n1)/(n2-n1) >=0 380 } else if (d>=-1e-5) return 2; // boundary detected 381 } 382 } 383 oldPoint = curPoint; 384 } 385 // System.out.printf("Intersected intercount %d %s\n",interCount, point.toString()); 386 if (interCount%2 == 1) return 1; else return 0; 387 } 388 296 389 } -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/SelectAllInsideAction.java
r26646 r26662 31 31 32 32 public void actionPerformed(ActionEvent e) { 33 long t=System.currentTimeMillis(); 33 34 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 34 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class);35 Set<Way> activeWays = new HashSet<Way>();36 37 35 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(getCurrentDataSet().getSelected(), Way.class); 36 Set<Relation> selectedRels = OsmPrimitive.getFilteredSet(getCurrentDataSet().getSelected(), Relation.class); 37 38 38 for (Way w: selectedWays) { 39 39 if (!w.isClosed()) selectedWays.remove(w); 40 40 } 41 for (Relation r: selectedRels) { 42 if (!r.isMultipolygon()) selectedRels.remove(r); 43 } 41 44 45 Set<Way> newWays = new HashSet<Way>(); 46 Set<Node> newNodes = new HashSet<Node>(); 42 47 // select ways attached to already selected ways 43 48 if (!selectedWays.isEmpty()) { 44 Set<Way> newWays = new HashSet<Way>();45 Set<Node> newNodes = new HashSet<Node>();46 49 for (Way w: selectedWays) { 47 50 NodeWayUtils.addAllInsideWay(getCurrentDataSet(),w,newWays,newNodes); 48 51 } 52 } 53 if (!selectedRels.isEmpty()) { 54 for (Relation r: selectedRels) { 55 NodeWayUtils.addAllInsideMultipolygon(getCurrentDataSet(),r,newWays,newNodes); 56 } 57 } 58 if (!newWays.isEmpty() || !newNodes.isEmpty()) { 49 59 getCurrentDataSet().addSelected(newWays); 50 60 getCurrentDataSet().addSelected(newNodes); 51 return; 52 } else { 53 JOptionPane.showMessageDialog(Main.parent, 54 tr("Please select some closed ways to find all primitives inside them!"), 61 } else{ 62 JOptionPane.showMessageDialog(Main.parent, 63 tr("Nothing found. Please select some closed ways or multipolygons to find all primitives inside them!"), 55 64 tr("Warning"), JOptionPane.WARNING_MESSAGE); 56 65 }
Note:
See TracChangeset
for help on using the changeset viewer.