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

[Command] Join output from match step with output from extract step #101

Open
bkowshik opened this issue Feb 7, 2022 · 0 comments
Open

Comments

@bkowshik
Copy link

bkowshik commented Feb 7, 2022

First of all, thank you very much for the SharedStreets project & library. ❤️

In the match step, the same road geometries come up every time a feature in matched with the road geometry. But, ideally we would want to JOIN as mentioned in the blog below between the matches and the raw dataset.

Ref: https://sharedstreets.io/mobility-metrics-example-trip-volumes-and-street-data/

Step 6. Join the matched bike lanes to the scooter trip volumes

Currently, I had to something like this in Python but would be better done as a command in shst itself.

# Read all the exhaustive list of OSM features.
with open(directory / 'output-boundary.out.geojson') as f:
    extract_fc = json.load(f)


# Create a mapping for quick reference.
extract_fc_mapping = {}
for feature in extract_fc['features']:

    feature = json.loads(json.dumps(feature))

    # Initialize the number of features matched to zero.
    feature['properties']['match'] = 0
    
    extract_fc_mapping[feature['properties']['id']] = feature


# Read all the matches.
with open(directory / 'output-routes.matched.geojson') as f:
    match_fc = json.load(f)

len(match_fc['features'])


# Add the counts as an attribute.
for feature in match_fc['features']:

    geometry_id = feature['properties']['shstGeometryId']
    extract_fc_mapping[geometry_id]['properties']['match'] += 1


# Write the geojson back to a file.
with open(directory / 'final.geojson', 'w') as f:
    json.dump(geojson.FeatureCollection(list(extract_fc_mapping.values())), f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant