// check whether the model element is a point of interest and
// the poi is of type crossing, gate or stop_sign
if(!(element instanceof PointOfInterest))
continue;
PointOfInterest poi = (PointOfInterest) element;
if(!(poi.getDescription().equals("crossing") || poi.getDescription().equals("gate") || poi.getDescription().equals("stop_sign")) )
continue;
lat = poi.getLatitude();
lon = poi.getLongitude();
String poi_lat = Double.toString(lat);
String poi_long = Double.toString(lon);
double key_lat = Double.parseDouble(poi_lat.substring(0,(poi_lat.split("\\.")[0].length()) + 1 + MapSegmentationPrecission));
double key_lon = Double.parseDouble(poi_long.substring(0, (poi_long.split("\\.")[0].length()) + 1 + MapSegmentationPrecission));
// create a cluster around poi
double[] keys_lat = new double[(LatitudeDifference * 2) + 1];
keys_lat[0] = key_lat;
int index_lat = 1;
for (int i = 1; i < LatitudeDifference + 1; i++) {
keys_lat[index_lat] = key_lat- i / Math.pow(10, (MapSegmentationPrecission));
index_lat++;
keys_lat[index_lat] = key_lat+ i / Math.pow(10, (MapSegmentationPrecission));
index_lat++;
}
double[] keys_lon = new double[(LongitudeDifference * 2) + 1];
keys_lon[0] = key_lon;
int index_lon = 1;
for (int j = 1; j < LongitudeDifference + 1; j++) {
keys_lon[index_lon] = key_lon- j / Math.pow(10, (MapSegmentationPrecission));
index_lon++;
keys_lon[index_lon] = key_lon+ j / Math.pow(10, (MapSegmentationPrecission));
index_lon++;
}
// search for all ways in the cluster and calculate the distance for each edge to poi
for(double lati : keys_lat) {
for(double longi : keys_lon) {
String key1="";
String lat_key = Double.toString(lati);
String key2="";
String long_key = Double.toString(longi);
try{
key1 = lat_key.substring(0, lat_key.split("\\.")[0].length() + 1 + MapSegmentationPrecission);
} catch(Exception e) {
while(key1.length()< lat_key.split("\\.")[0].length() + 1 + MapSegmentationPrecission-1)
key1 =key1+"0";
}
try{
key2 = long_key.substring(0, long_key.split("\\.")[0].length() + 1 + MapSegmentationPrecission);
} catch(Exception e) {
while(key2.length()< long_key.split("\\.")[0].length() + 1 + MapSegmentationPrecission-1)
key2 =key2+"0";
}
key =key1+":" +key2;
if(clusteredWays.containsKey(key)) {
for(String wayId: clusteredWays.get(key)) {
WayModel way =(WayModel)modelElements.get(wayId);
if(way!=null) {
for(EdgeModel edge:way.getForwardEdges()) {
double dist = Line2D.ptSegDist(
edge.getFromNode().getLatitude(),
edge.getFromNode().getLongitude(),
edge.getToNode().getLatitude(),
edge.getToNode().getLongitude(),
lat,
lon
);
if(dist < min_dist) {
min_dist = dist;
min_edge = edge;
min_way = way;
}
}
}
}
}
}
}
if(min_dist > MinDistanceToPOI) {
continue;
}
// check whether start or end point of an edge is the poi
if(
min_edge.getFromNode().getLatitude() == poi.getLatitude()
&& min_edge.getFromNode().getLongitude() == poi.getLongitude()
) {
continue;
}
if(
min_edge.getToNode().getLatitude() == poi.getLatitude()
&& min_edge.getToNode().getLongitude() == poi.getLongitude()
) {
continue;
}
//create new Node on POI
NodeModel new_Node=new NodeModel(poi.getLatitude(),poi.getLongitude());
//create new Edges with remaining attributes
EdgeModel firstForwardEdge = (EdgeModel) min_edge.clone();
firstForwardEdge.setFromNode(min_edge.getFromNode());
firstForwardEdge.setToNode(new_Node);