Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made the correct joins #2

Merged
merged 1 commit into from Oct 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions GenerateShapes.py
Expand Up @@ -4,7 +4,32 @@
from multiprocessing import Process, Manager, Pool
from functools import partial

def make_shape(L,LinePlanningNumber):


if __name__ == "__main__":
print("Start loading data")
segments = pd.read_csv('JOPATILIXX.TMI', sep='|',usecols=['[DataOwnerCode]','[LinePlanningNumber]','[TimingLinkOrder]','[UserStopCodeBegin]','[UserStopCodeEnd]','[DisplayPublicLine]','[ProductFormulaType]'])
pointsOnSegments = pd.read_csv('POOLXXXXXX.TMI', sep='|',usecols=['[UserStopCodeBegin]','[UserStopCodeEnd]','[PointCode]','[DistanceSinceStartOfLink]'])
points = pd.read_csv('POINTXXXXX.TMI',sep='|',usecols=['[PointCode]','[LocationX_EW]','[LocationY_NS]'])
print("Finished loading data")

print("Joining the point on links on the segments")
joined_segments = pd.merge(segments, pointsOnSegments, how="inner", on=['[UserStopCodeBegin]','[UserStopCodeEnd]'])
print("Joining the points")
points_joined_segments = pd.merge(joined_segments,points,how="inner",on='[PointCode]')
print(points_joined_segments)

with Manager() as manager:
#Create a list to hold each route's shape to write them to file at the end:
line_shape_list = manager.list()
pool = Pool(processes = None)
func = partial(make_shape,line_shape_list)
pool.map(func, points_joined_segments['[LinePlanningNumber]'].unique(),1)
pool.close()
pool.join()

#Finally, write our collection of Features (one for each route) to file in
#geoJSON format, as a FeatureCollection:
with open('route_shapes.geojson', 'w') as outfile:
gj.dump(gj.FeatureCollection(line_shape_list._getvalue()), outfile)