Skip to content

Commit

Permalink
Merge pull request #10 from brelsford/automatically_rezero
Browse files Browse the repository at this point in the history
do analysis on rescaled coordinates.
  • Loading branch information
brelsford committed Jun 30, 2015
2 parents b0dc8af + b80f644 commit 8899774
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 5 additions & 3 deletions my_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ def __ne__(self, other):
def __hash__(self):
return hash(self.nodes)

def geoJSON(self):
def geoJSON(self,rezero):
return {
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [list([n.x, n.y]) for n in self.nodes]
"coordinates": [list([n.x+rezero[0], n.y+rezero[1]]) for n in self.nodes]
},
"properties": {
"road": str(self.road).lower(),
Expand Down Expand Up @@ -238,6 +238,7 @@ def __init__(self, G=None, name="S0"):
self.name = name
self.cleaned = False
self.roads_update = True
self.rezero_vector = np.array([0,0])

if G is None:
self.G = nx.Graph()
Expand Down Expand Up @@ -283,6 +284,7 @@ def copy(self):
nx_copy = self.G.copy()
copy = MyGraph(nx_copy)
copy.name = self.name
copy.rezero_vector = self.rezero_vector

# outerface is a side effect of the creation of inner_facelist
# so we operate on that in order to not CALL inner_facelist for every
Expand Down Expand Up @@ -310,7 +312,7 @@ def inner_facelist(self):

def myedges_geoJSON(self):
return json.dumps({"type": "FeatureCollection",
"features": [e.geoJSON() for e in self.myedges()]})
"features": [e.geoJSON(self.rezero_vector) for e in self.myedges()]})


############################
Expand Down
16 changes: 12 additions & 4 deletions my_graph_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,18 +928,26 @@ def import_and_setup(filename, threshold=1, component=None,
# check that threshold is a float

sf = shapefile.Reader(filename)
myG = graphFromShapes(sf.shapes(), name, rezero)
myG1 = graphFromShapes(sf.shapes(), name, rezero)

print("shape file loaded")

myG = myG.clean_up_geometry(threshold, byblock)
myG1 = myG1.clean_up_geometry(threshold, byblock)

print("geometery cleaned up")

xmin = min([n.x for n in myG1.G.nodes()])
ymin = min([n.y for n in myG1.G.nodes()])

rezero_vector = np.array([xmin, ymin])

myG2 = rescale_mygraph(myG1, rezero=rezero_vector)
myG2.rezero_vector = rezero_vector

if component is None:
return myG
return myG2
else:
return myG.connected_components()[component]
return myG2.connected_components()[component]


def rescale_mygraph(myG, rezero=np.array([0, 0]), rescale=np.array([1, 1])):
Expand Down

0 comments on commit 8899774

Please sign in to comment.