Skip to content

Commit

Permalink
Complete way on encountering a power building
Browse files Browse the repository at this point in the history
  • Loading branch information
tsrivishnu committed Sep 1, 2016
1 parent c95bd13 commit 742613f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
21 changes: 14 additions & 7 deletions way_inference/infer_way.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
'3212195884', '3212195874', '3212195866', '3212195869', '3212195878',
'3212195882', '3212195889', '3212195895', '3212195893', '3212195896'
)
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
# 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

nodesWrapper = NodesWrapper(cur, bounds)
clustersWrapper = ClusterWrapper(cur, bounds)
waysWrapper = WaysWrapper(cur, bounds)

clusters = clustersWrapper.getClusters()

Expand All @@ -39,23 +40,24 @@

# Start processing with one of the farthest nodes
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

processed_nodes.append(processing_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:
nodes_around = nodesWrapper.get_closest_nodes_to(
processing_node,
Expand All @@ -73,6 +75,11 @@
print(closest_node)
processing_node = closest_node
processed_nodes.append(processing_node)

# if the node that is just processed in
if waysWrapper.is_node_in_any_polygon(processing_node):
is_complete = True

else:
print("\n*********** IS COMPLETE **************\n")
is_complete = True
Expand All @@ -81,5 +88,5 @@
for node_osmid in processed_nodes:
print("node(%s);" % node_osmid)

WaysWrapper(cur).save_to_database(processed_nodes)
waysWrapper.save_to_database(processed_nodes)
conn.commit()
23 changes: 22 additions & 1 deletion way_inference/ways_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
import json

class WaysWrapper:
bounds = []
cur = None

def __init__(self, sql_cur):
def __init__(self, sql_cur, bounds):
self.cur = sql_cur
self.bounds = bounds

def is_node_in_any_polygon(self, node_osmid):
query = '''
WITH node AS (
SELECT geom FROM point WHERE properties->>'osmid' = %s
)
SELECT powerline.id
FROM powerline, node
WHERE ST_Contains(ST_MakePolygon(powerline.geom), node.geom)
AND ST_IsClosed(powerline.geom)
LIMIT 1
'''
self.cur.execute(query, [str(node_osmid)])
powerline = self.cur.fetchone()
if powerline is not None:
return True
else:
return False

def save_to_database(self, nodes_osmids):
nodes = []
Expand Down

0 comments on commit 742613f

Please sign in to comment.