Skip to content

Commit

Permalink
Ignore too close nodes during inference
Browse files Browse the repository at this point in the history
  • Loading branch information
tsrivishnu committed Aug 31, 2016
1 parent 1952ae4 commit 8bc9ba8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
25 changes: 14 additions & 11 deletions way_inference/infer_way.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
'3212195884', '3212195874', '3212195866', '3212195869', '3212195878',
'3212195882', '3212195889', '3212195895', '3212195893', '3212195896'
)
# bounds = [11.089153289794922, 4.593878359460639, 11.418743133544922, 4.759664350520704]
# bounds = [28.212890625, -1.8261677821806805, 33.486328125, 0.8349313860427184]
bounds = [15.496902465820312, -1.4843615162701949, 16.375808715820312, -1.0113763068489454] # the short line in the middle of africa
bounds = [10.39529800415039, 4.050234320898018, 10.50516128540039, 4.109221809610561] # parallel lines
# bounds = [15.496902465820312, -1.4843615162701949, 16.375808715820312, -1.0113763068489454] # the short line in the middle of africa
clusterWrapper = ClusterWrapper(cur, bounds)
clusters = clusterWrapper.getClusters()

Expand All @@ -39,33 +38,37 @@
processing_node = farthest_nodes[0]
processed_nodes = []
processed_nodes.append(processing_node)
ignored_nodes = [] # nodes are ignored if there are too close to a node

is_complete = False

while is_complete == False:
# print(processed_nodes)
# print "processing - ",
# print(processing_node)
# procesed nodes minus the all nodes
unprocessed_nodes = tuple(set(tuple(processed_nodes)) ^ set(nodes_osmids))

# unprocessed nodes minus the ignored node.
unprocessed_nodes = tuple(set(unprocessed_nodes) ^ set(tuple(ignored_nodes)))
closest_node = None

if len(unprocessed_nodes) > 0:
closest_nodes = NodesWrapper(cur, []).get_closest_nodes_to(
nodes_around = NodesWrapper(cur, []).get_closest_nodes_to(
processing_node,
unprocessed_nodes
)
print(closest_nodes)

ignored_nodes = ignored_nodes + nodes_around['too_close_node_osmids']
closest_node = nodes_around['closest_node_osmid']
else:
is_complete = True
continue

if len(closest_nodes) > 0:
closest_node = closest_nodes[0] # There are already ordered by distance

if closest_node is not None and len(closest_node) > 0:
if closest_node is not None:
print "Closest is - ",
print(closest_node[1])
processing_node = closest_node[1]
print(closest_node)
processing_node = closest_node
processed_nodes.append(processing_node)
else:
print("\n*********** IS COMPLETE **************\n")
Expand Down
26 changes: 20 additions & 6 deletions way_inference/nodes_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class NodesWrapper:
bounds = []
cur = None
closest_min_distance = 0.0004
closest_max_distance = 0.09

def __init__(self, sql_cursor, bounds):
self.bounds = bounds
Expand Down Expand Up @@ -29,19 +31,31 @@ def get_closest_nodes_to(self, for_node_osmid, among_osm_ids):
ST_Distance(
ST_GeomFromText(current_point.geom),
point.geom
)
) as distance
FROM point, current_point
WHERE ST_Distance(ST_GeomFromText(current_point.geom), point.geom) > 0.0004
AND ST_Distance(ST_GeomFromText(current_point.geom), point.geom) < 0.09
WHERE ST_Distance(ST_GeomFromText(current_point.geom), point.geom) < %s
AND properties->>'osmid' IN %s
ORDER BY ST_Distance(ST_GeomFromText(current_point.geom), point.geom) ASC
LIMIT 1
'''
self.cur.execute(fetch_closest_query, [
for_node_osmid,
among_osm_ids
self.closest_max_distance,
among_osm_ids,
])
return self.cur.fetchall()
closest_nodes = self.cur.fetchall()
result = {
'too_close_node_osmids': [],
'closest_node_osmid': None
}

for node in closest_nodes:
if (node[2] < self.closest_min_distance):
result['too_close_node_osmids'].append(node[1])
else:
result['closest_node_osmid'] = node[1]
break;
return result;


def get_farthest_nodes_among_nodes(self, among_osm_ids):
farthest_nodes_query = '''
Expand Down

0 comments on commit 8bc9ba8

Please sign in to comment.