mie-lab / trackintel

trackintel is a framework for spatio-temporal analysis of movement trajectory and mobility data.
MIT License
198 stars 50 forks source link

ENH: Returns of generate_locations() function #251

Open HaojunCai opened 3 years ago

HaojunCai commented 3 years ago

For the returns stp_cls and loc_cls of generate_locations() function, I would like the possibility to have the coordinates of clustered locations (loc_cls) assigned to each stay point (stp_cls), so that I could further extract mobility features on the basis of stp_cls data. It could be achieved by stp_cls = stp_cls.join(loc_cls, on="location_id", lsuffix='user_id') and could be set by default False to avoid data redundancy.

hongyeehh commented 3 years ago

Hi Haojun,

Thanks for raising up this issue. Trackintel now does not provide the possibility to join the information of different data models as internal functions. For joining staypoint with location level information, I would recommend using:

stps.reset_index().merge(locs, left_on=["location_id", "user_id"], right_on=["id", "user_id"]).set_index("id"))

This line resets the index of the input staypoint, merge the two dataframes on location_id/id and user_id, and sets back the id column for the staypoint index.

We are now planning to include helper functions in trackintel to join staypoint + location and tripleg + trip. Thanks again for raising our awareness :).

henrymartin1 commented 3 years ago

@hong2223 Should we create an assignable issue for these helper functions where we collect what is needed and close this issue? (I would like to have a way to join location IDs to trips :-) )