@Test public void TestOverlappingRegion() { String[] names = _builder.findBorderCrossing(new Coordinate[] { new Coordinate(101.5,101.5), new Coordinate(102.5,101.5) }); Assert.assertEquals(2, names.length); String[] names2 = _builder.findBorderCrossing(new Coordinate[] { new Coordinate(101.5,101.5), new Coordinate(101.75,101.5) }); Assert.assertEquals(1, names2.length); }
public String[] findBorderCrossing(Coordinate[] coords) { ArrayList<CountryBordersPolygon> countries = new ArrayList<>(); boolean hasInternational = false; boolean overlap = false; int lsLen = coords.length; if(lsLen > 1) { for(int i=0; i<lsLen; i++) { Coordinate c = coords[i]; if(!Double.isNaN(c.x) && !Double.isNaN(c.y)) { CountryBordersPolygon[] cnts = cbReader.getCandidateCountry(c); for (CountryBordersPolygon cbp : cnts) { if (!countries.contains(cbp)) { countries.add(cbp); } } if(cnts.length == 0) hasInternational = true; } } } if(countries.size() > 1) { ArrayList<CountryBordersPolygon> temp = new ArrayList<>(); for(int i=0; i<lsLen; i++) { Coordinate c = coords[i]; if(!Double.isNaN(c.x) && !Double.isNaN(c.y)) { boolean found = false; int countriesFound = 0; for(CountryBordersPolygon cbp : countries) { if (cbp.inArea(c)) { found = true; countriesFound++; if(!temp.contains(cbp)) { temp.add(cbp); } } } if(countriesFound > 1) { overlap = true; } if(!found) { hasInternational = true; } } } countries = temp; } if(countries.size() > 1 && overlap) { boolean crosses = false; LineString ls = gf.createLineString(coords); for (CountryBordersPolygon cp : countries) { if (cp.crossesBoundary(ls)) { crosses = true; break; } } if(!crosses) { CountryBordersPolygon cp = countries.get(0); countries.clear(); countries.add(cp); } } ArrayList<String> names = new ArrayList<>(); for(int i=0; i<countries.size(); i++) { if (!names.contains(countries.get(i).getName())) names.add(countries.get(i).getName()); } if(hasInternational && !countries.isEmpty()) { names.add(CountryBordersReader.INTERNATIONAL_NAME); } return names.toArray(new String[names.size()]); }
BordersGraphStorageBuilder extends AbstractGraphStorageBuilder { public String[] findBorderCrossing(Coordinate[] coords) { ArrayList<CountryBordersPolygon> countries = new ArrayList<>(); boolean hasInternational = false; boolean overlap = false; int lsLen = coords.length; if(lsLen > 1) { for(int i=0; i<lsLen; i++) { Coordinate c = coords[i]; if(!Double.isNaN(c.x) && !Double.isNaN(c.y)) { CountryBordersPolygon[] cnts = cbReader.getCandidateCountry(c); for (CountryBordersPolygon cbp : cnts) { if (!countries.contains(cbp)) { countries.add(cbp); } } if(cnts.length == 0) hasInternational = true; } } } if(countries.size() > 1) { ArrayList<CountryBordersPolygon> temp = new ArrayList<>(); for(int i=0; i<lsLen; i++) { Coordinate c = coords[i]; if(!Double.isNaN(c.x) && !Double.isNaN(c.y)) { boolean found = false; int countriesFound = 0; for(CountryBordersPolygon cbp : countries) { if (cbp.inArea(c)) { found = true; countriesFound++; if(!temp.contains(cbp)) { temp.add(cbp); } } } if(countriesFound > 1) { overlap = true; } if(!found) { hasInternational = true; } } } countries = temp; } if(countries.size() > 1 && overlap) { boolean crosses = false; LineString ls = gf.createLineString(coords); for (CountryBordersPolygon cp : countries) { if (cp.crossesBoundary(ls)) { crosses = true; break; } } if(!crosses) { CountryBordersPolygon cp = countries.get(0); countries.clear(); countries.add(cp); } } ArrayList<String> names = new ArrayList<>(); for(int i=0; i<countries.size(); i++) { if (!names.contains(countries.get(i).getName())) names.add(countries.get(i).getName()); } if(hasInternational && !countries.isEmpty()) { names.add(CountryBordersReader.INTERNATIONAL_NAME); } return names.toArray(new String[names.size()]); } }
BordersGraphStorageBuilder extends AbstractGraphStorageBuilder { public String[] findBorderCrossing(Coordinate[] coords) { ArrayList<CountryBordersPolygon> countries = new ArrayList<>(); boolean hasInternational = false; boolean overlap = false; int lsLen = coords.length; if(lsLen > 1) { for(int i=0; i<lsLen; i++) { Coordinate c = coords[i]; if(!Double.isNaN(c.x) && !Double.isNaN(c.y)) { CountryBordersPolygon[] cnts = cbReader.getCandidateCountry(c); for (CountryBordersPolygon cbp : cnts) { if (!countries.contains(cbp)) { countries.add(cbp); } } if(cnts.length == 0) hasInternational = true; } } } if(countries.size() > 1) { ArrayList<CountryBordersPolygon> temp = new ArrayList<>(); for(int i=0; i<lsLen; i++) { Coordinate c = coords[i]; if(!Double.isNaN(c.x) && !Double.isNaN(c.y)) { boolean found = false; int countriesFound = 0; for(CountryBordersPolygon cbp : countries) { if (cbp.inArea(c)) { found = true; countriesFound++; if(!temp.contains(cbp)) { temp.add(cbp); } } } if(countriesFound > 1) { overlap = true; } if(!found) { hasInternational = true; } } } countries = temp; } if(countries.size() > 1 && overlap) { boolean crosses = false; LineString ls = gf.createLineString(coords); for (CountryBordersPolygon cp : countries) { if (cp.crossesBoundary(ls)) { crosses = true; break; } } if(!crosses) { CountryBordersPolygon cp = countries.get(0); countries.clear(); countries.add(cp); } } ArrayList<String> names = new ArrayList<>(); for(int i=0; i<countries.size(); i++) { if (!names.contains(countries.get(i).getName())) names.add(countries.get(i).getName()); } if(hasInternational && !countries.isEmpty()) { names.add(CountryBordersReader.INTERNATIONAL_NAME); } return names.toArray(new String[names.size()]); } BordersGraphStorageBuilder(); }
BordersGraphStorageBuilder extends AbstractGraphStorageBuilder { public String[] findBorderCrossing(Coordinate[] coords) { ArrayList<CountryBordersPolygon> countries = new ArrayList<>(); boolean hasInternational = false; boolean overlap = false; int lsLen = coords.length; if(lsLen > 1) { for(int i=0; i<lsLen; i++) { Coordinate c = coords[i]; if(!Double.isNaN(c.x) && !Double.isNaN(c.y)) { CountryBordersPolygon[] cnts = cbReader.getCandidateCountry(c); for (CountryBordersPolygon cbp : cnts) { if (!countries.contains(cbp)) { countries.add(cbp); } } if(cnts.length == 0) hasInternational = true; } } } if(countries.size() > 1) { ArrayList<CountryBordersPolygon> temp = new ArrayList<>(); for(int i=0; i<lsLen; i++) { Coordinate c = coords[i]; if(!Double.isNaN(c.x) && !Double.isNaN(c.y)) { boolean found = false; int countriesFound = 0; for(CountryBordersPolygon cbp : countries) { if (cbp.inArea(c)) { found = true; countriesFound++; if(!temp.contains(cbp)) { temp.add(cbp); } } } if(countriesFound > 1) { overlap = true; } if(!found) { hasInternational = true; } } } countries = temp; } if(countries.size() > 1 && overlap) { boolean crosses = false; LineString ls = gf.createLineString(coords); for (CountryBordersPolygon cp : countries) { if (cp.crossesBoundary(ls)) { crosses = true; break; } } if(!crosses) { CountryBordersPolygon cp = countries.get(0); countries.clear(); countries.add(cp); } } ArrayList<String> names = new ArrayList<>(); for(int i=0; i<countries.size(); i++) { if (!names.contains(countries.get(i).getName())) names.add(countries.get(i).getName()); } if(hasInternational && !countries.isEmpty()) { names.add(CountryBordersReader.INTERNATIONAL_NAME); } return names.toArray(new String[names.size()]); } BordersGraphStorageBuilder(); @Override GraphExtension init(GraphHopper graphhopper); void setBordersBuilder(CountryBordersReader cbr); @Override void processWay(ReaderWay way); @Override void processWay(ReaderWay way, Coordinate[] coords, HashMap<Integer, HashMap<String,String>> nodeTags); @Override void processEdge(ReaderWay way, EdgeIteratorState edge); @Override String getName(); String[] findBorderCrossing(Coordinate[] coords); CountryBordersReader getCbReader(); }
BordersGraphStorageBuilder extends AbstractGraphStorageBuilder { public String[] findBorderCrossing(Coordinate[] coords) { ArrayList<CountryBordersPolygon> countries = new ArrayList<>(); boolean hasInternational = false; boolean overlap = false; int lsLen = coords.length; if(lsLen > 1) { for(int i=0; i<lsLen; i++) { Coordinate c = coords[i]; if(!Double.isNaN(c.x) && !Double.isNaN(c.y)) { CountryBordersPolygon[] cnts = cbReader.getCandidateCountry(c); for (CountryBordersPolygon cbp : cnts) { if (!countries.contains(cbp)) { countries.add(cbp); } } if(cnts.length == 0) hasInternational = true; } } } if(countries.size() > 1) { ArrayList<CountryBordersPolygon> temp = new ArrayList<>(); for(int i=0; i<lsLen; i++) { Coordinate c = coords[i]; if(!Double.isNaN(c.x) && !Double.isNaN(c.y)) { boolean found = false; int countriesFound = 0; for(CountryBordersPolygon cbp : countries) { if (cbp.inArea(c)) { found = true; countriesFound++; if(!temp.contains(cbp)) { temp.add(cbp); } } } if(countriesFound > 1) { overlap = true; } if(!found) { hasInternational = true; } } } countries = temp; } if(countries.size() > 1 && overlap) { boolean crosses = false; LineString ls = gf.createLineString(coords); for (CountryBordersPolygon cp : countries) { if (cp.crossesBoundary(ls)) { crosses = true; break; } } if(!crosses) { CountryBordersPolygon cp = countries.get(0); countries.clear(); countries.add(cp); } } ArrayList<String> names = new ArrayList<>(); for(int i=0; i<countries.size(); i++) { if (!names.contains(countries.get(i).getName())) names.add(countries.get(i).getName()); } if(hasInternational && !countries.isEmpty()) { names.add(CountryBordersReader.INTERNATIONAL_NAME); } return names.toArray(new String[names.size()]); } BordersGraphStorageBuilder(); @Override GraphExtension init(GraphHopper graphhopper); void setBordersBuilder(CountryBordersReader cbr); @Override void processWay(ReaderWay way); @Override void processWay(ReaderWay way, Coordinate[] coords, HashMap<Integer, HashMap<String,String>> nodeTags); @Override void processEdge(ReaderWay way, EdgeIteratorState edge); @Override String getName(); String[] findBorderCrossing(Coordinate[] coords); CountryBordersReader getCbReader(); static final String BUILDER_NAME; }