public Way[] splitAtNodes(Way way,Node node1,Node node2,boolean createPolygons){
  Log.d("StorageDelegator","splitAtNodes way " + way.getOsmId() + " node1 "+ node1.getOsmId()+ " node2 "+ node2.getOsmId());
  dirty=true;
  undo.save(way);
  List<Node> nodes=way.getNodes();
  if (nodes.size() < 3) {
    return null;
  }
  List<Node> nodesForNewWay=new LinkedList<Node>();
  List<Node> nodesForOldWay1=new LinkedList<Node>();
  List<Node> nodesForOldWay2=new LinkedList<Node>();
  boolean found1=false;
  boolean found2=false;
  for (Iterator<Node> it=way.getRemovableNodes(); it.hasNext(); ) {
    Node wayNode=it.next();
    if (!found1 && wayNode.getOsmId() == node1.getOsmId()) {
      found1=true;
      nodesForNewWay.add(wayNode);
      if (!found2)       nodesForOldWay1.add(wayNode);
 else       nodesForOldWay2.add(wayNode);
    }
 else     if (!found2 && wayNode.getOsmId() == node2.getOsmId()) {
      found2=true;
      nodesForNewWay.add(wayNode);
      if (!found1)       nodesForOldWay1.add(wayNode);
 else       nodesForOldWay2.add(wayNode);
    }
 else     if ((found1 && !found2) || (!found1 && found2)) {
      nodesForNewWay.add(wayNode);
    }
 else     if (!found1 && !found2) {
      nodesForOldWay1.add(wayNode);
    }
 else     if (found1 && found2) {
      nodesForOldWay2.add(wayNode);
    }
  }
  Log.d("StorageDelegator","nodesForNewWay " + nodesForNewWay.size() + " oldNodes1 "+ nodesForOldWay1.size()+ " oldNodes2 "+ nodesForOldWay2.size());
  List<Node> oldNodes=way.getNodes();
  oldNodes.clear();
  if (nodesForOldWay1.size() == 0) {
    oldNodes.addAll(nodesForOldWay2);
  }
 else   if (nodesForOldWay2.size() == 0) {
    oldNodes.addAll(nodesForOldWay1);
  }
 else   if (nodesForOldWay1.get(0) == nodesForOldWay2.get(nodesForOldWay2.size() - 1)) {
    oldNodes.addAll(nodesForOldWay2);
    nodesForOldWay1.remove(0);
    oldNodes.addAll(nodesForOldWay1);
  }
 else {
    oldNodes.addAll(nodesForOldWay1);
    nodesForOldWay2.remove(0);
    oldNodes.addAll(nodesForOldWay2);
  }
  try {
    if (createPolygons && way.length() > 2) {
      way.addNode(way.getFirstNode());
    }
    way.updateState(OsmElement.STATE_MODIFIED);
    apiStorage.insertElementSafe(way);
    Way newWay=factory.createWayWithNewId();
    newWay.addTags(way.getTags());
    newWay.addNodes(nodesForNewWay,false);
    if (createPolygons && newWay.length() > 2) {
      newWay.addNode(newWay.getFirstNode());
    }
    insertElementUnsafe(newWay);
    if (way.hasParentRelations()) {
      ArrayList<Relation> relations=new ArrayList<Relation>(way.getParentRelations());
      dirty=true;
      for (      Relation r : relations) {
        Log.d("StorageDelegator","splitAtNode processing relation (#" + r.getOsmId() + "/"+ relations.size()+ ") "+ r.getDescription());
        RelationMember rm=r.getMember(way);
        undo.save(r);
        RelationMember newMember=new RelationMember(rm.getRole(),newWay);
        r.addMemberAfter(rm,newMember);
        newWay.addParentRelation(r);
        r.updateState(OsmElement.STATE_MODIFIED);
        apiStorage.insertElementSafe(r);
      }
    }
    recordImagery();
    Way[] result=new Way[2];
    result[0]=way;
    result[1]=newWay;
    return result;
  }
 catch (  StorageException e) {
    e.printStackTrace();
  }
  return null;
}

public Way [ ] splitAtNodes ( Way way , Node node1 , Node node2 , boolean createPolygons ) { Log . d ( "StorageDelegator" , "splitAtNodes way " + way . getOsmId ( ) + " node1 " + node1 . getOsmId ( ) + " node2 " + node2 . getOsmId ( ) ) ; dirty = true ; undo . save ( way ) ; List < Node > nodes = way . getNodes ( ) ; if ( nodes . size ( ) < 3 ) { return null ; } List < Node > nodesForNewWay = new LinkedList < Node > ( ) ; List < Node > nodesForOldWay1 = new LinkedList < Node > ( ) ; List < Node > nodesForOldWay2 = new LinkedList < Node > ( ) ; boolean found1 = false ; boolean found2 = false ; for ( Iterator < Node > it = way . getRemovableNodes ( ) ; it . hasNext ( ) ; ) { Node wayNode = it . next ( ) ; if ( ! found1 && wayNode . getOsmId ( ) == node1 . getOsmId ( ) ) { found1 = true ; nodesForNewWay . add ( wayNode ) ; if ( ! found2 ) nodesForOldWay1 . add ( wayNode ) ; else nodesForOldWay2 . add ( wayNode ) ; } else if ( ! found2 && wayNode . getOsmId ( ) == node2 . getOsmId ( ) ) { found2 = true ; nodesForNewWay . add ( wayNode ) ; if ( ! found1 ) nodesForOldWay1 . add ( wayNode ) ; else nodesForOldWay2 . add ( wayNode ) ; } else if ( ( found1 && ! found2 ) || ( ! found1 && found2 ) ) { nodesForNewWay . add ( wayNode ) ; } else if ( ! found1 && ! found2 ) { nodesForOldWay1 . add ( wayNode ) ; } else if ( found1 && found2 ) { nodesForOldWay2 . add ( wayNode ) ; } } Log . d ( "StorageDelegator" , "nodesForNewWay " + nodesForNewWay . size ( ) + " oldNodes1 " + nodesForOldWay1 . size ( ) + " oldNodes2 " + nodesForOldWay2 . size ( ) ) ; List < Node > oldNodes = way . getNodes ( ) ; oldNodes . clear ( ) ; if ( nodesForOldWay1 . size ( ) == 0 ) { oldNodes . addAll ( nodesForOldWay2 ) ; } else if ( nodesForOldWay2 . size ( ) == 0 ) { oldNodes . addAll ( nodesForOldWay1 ) ; } else if ( nodesForOldWay1 . get ( 0 ) == nodesForOldWay2 . get ( nodesForOldWay2 . size ( ) - 1 ) ) { oldNodes . addAll ( nodesForOldWay2 ) ; nodesForOldWay1 . remove ( 0 ) ; oldNodes . addAll ( nodesForOldWay1 ) ; } else { oldNodes . addAll ( nodesForOldWay1 ) ; nodesForOldWay2 . remove ( 0 ) ; oldNodes . addAll ( nodesForOldWay2 ) ; } try { if ( createPolygons && way . length ( ) > 2 ) { way . addNode ( way . getFirstNode ( ) ) ; } way . updateState ( OsmElement . STATE_MODIFIED ) ; apiStorage . insertElementSafe ( way ) ; Way newWay = factory . createWayWithNewId ( ) ; newWay . addTags ( way . getTags ( ) ) ; newWay . addNodes ( nodesForNewWay , false ) ; if ( createPolygons && newWay . length ( ) > 2 ) { newWay . addNode ( newWay . getFirstNode ( ) ) ; } insertElementUnsafe ( newWay ) ; if ( way . hasParentRelations ( ) ) { ArrayList < Relation > relations = new ArrayList < Relation > ( way . getParentRelations ( ) ) ; dirty = true ; for ( Relation r : relations ) { Log . d ( "StorageDelegator" , "splitAtNode processing relation (#" + r . getOsmId ( ) + "/" + relations . size ( ) + ") " + r . getDescription ( ) ) ; RelationMember rm = r . getMember ( way ) ; undo . save ( r ) ; RelationMember newMember = new RelationMember ( rm . getRole ( ) , newWay ) ; r . addMemberAfter ( rm , newMember ) ; newWay . addParentRelation ( r ) ; r . updateState ( OsmElement . STATE_MODIFIED ) ; apiStorage . insertElementSafe ( r ) ; } } recordImagery ( ) ; Way [ ] result = new Way [ 2 ] ; result [ 0 ] = way ; result [ 1 ] = newWay ; return result ; } catch ( StorageException e ) { e . printStackTrace ( ) ; } return null ; }
split a ( closed ) way at two points
