Skip to content

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

Description

@bkowshik

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions