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

GeoDataFrame to MF-JSON #325

Merged
merged 6 commits into from
Jul 18, 2023
Merged

GeoDataFrame to MF-JSON #325

merged 6 commits into from
Jul 18, 2023

Conversation

GaspardMerten
Copy link
Contributor

Add gdf_to_mf_json Method

This pull request adds the gdf_to_mf_json method to the codebase. The gdf_to_mf_json method converts a GeoDataFrame to a dictionary compatible with the Moving Features JSON (MF-JSON) specification.

More precisely, the method transforms a GeoDataFrame made of Point geometries into a Feature Collection object. It can handle multiple trips with different timestamps. The name of the columns that should be considered temporal properties can also be provided in order to include them as such in the resulting dictionary.

Example

gdf = GeoDataFrame(...)

mf_json = gdf_to_mf_json(
    gdf=gdf,
    traj_id_property="trajectory_id",
    datetime_column="timestamp",
    temporal_properties=["speed", "acceleration"],
    temporal_properties_static_fields={
        "speed": {"uom": "m/s"},
        "acceleration": {"uom": "m/s^2"}
    },
)

@GaspardMerten
Copy link
Contributor Author

Some tests would be needed, but I prefer to wait for your opinions concerning which data I should use as a comparison for these tests.

@raybellwaves
Copy link
Collaborator

Mind sending some links to MF JSON? I'm curious what it is, why you would use it and what problems it solves. I'm mostly curious as I'm not familiar.

I don't see any reason why this shouldn't go in. Thanks for the PR

@GaspardMerten
Copy link
Contributor Author

Here is the description of the standard on the Open Geospatial Consortium website: https://docs.ogc.org/is/19-045r3/19-045r3.html

It is a relatively new standard which provides a unified approach to storing and transmitting data using an extended version of GeoJSON. This is quite useful in the case of having to distribute trajectories to users in a quickly usable format.

In fact, this package movingpandas already has a decoder (which appears to be a work in progress). This is described in this blog: https://anitagraser.com/2022/04/16/new-ogc-moving-features-json-support-in-movingpandas/

This means that with this additional GDF to MF-JSON encoder, the package will be able to encode/decode MF-JSON/GDF without much friction.

@anitagraser
Copy link
Collaborator

Thank you for this excellent contribution.

For Tests, it would be good to use some of the official samples. I think this may be the most up to date repo: https://github.com/opengeospatial/mf-json

@GaspardMerten
Copy link
Contributor Author

GaspardMerten commented Jul 5, 2023

I added a test which first loads the file already present in the test folder, and which then encodes it using the method proposed in this PR. I then verify that both the encoded and original json file are equivalent.

@codecov-commenter
Copy link

codecov-commenter commented Jul 5, 2023

Codecov Report

Patch coverage: 90.62% and project coverage change: -0.09 ⚠️

Comparison is base (b7fa5cc) 95.53% compared to head (98edc29) 95.44%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #325      +/-   ##
==========================================
- Coverage   95.53%   95.44%   -0.09%     
==========================================
  Files          33       33              
  Lines        3517     3580      +63     
==========================================
+ Hits         3360     3417      +57     
- Misses        157      163       +6     
Impacted Files Coverage Δ
movingpandas/io.py 91.57% <86.36%> (-4.50%) ⬇️
movingpandas/tests/test_io.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@anitagraser anitagraser added the enhancement New feature or request label Jul 9, 2023
from pandas import DataFrame

from movingpandas import Trajectory


def gdf_to_mf_json(
gdf: GeoDataFrame,
traj_id_property: str,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use "column" instead of "property" to make it clear that these are referring to columns of the GeoDataFrame

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@GaspardMerten
Copy link
Contributor Author

I solved the last failing GitHub action which was due to some comment lines being longer than 88 (following the default 120). This has now been solved.

@anitagraser anitagraser merged commit 0222c31 into movingpandas:main Jul 18, 2023
7 checks passed
@anitagraser
Copy link
Collaborator

Thank you again for this contribution.

@GaspardMerten
Copy link
Contributor Author

It is my pleasure to contribute to this excellent package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants