keplergl / kepler.gl

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
http://kepler.gl
MIT License
10.41k stars 1.74k forks source link

From GeoDataFrame to Trip geoJSON? #1682

Open shicos opened 2 years ago

shicos commented 2 years ago

Hello,

Thanks for this great project! Is there a way to convert a GeoDataFrame to a trip GeoJSON, as described here: https://docs.kepler.gl/docs/user-guides/c-types-of-layers/k-trip

{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "vendor": "A" }, "geometry": { "type": "LineString", "coordinates": [ [-74.20986, 40.81773, 0, 1564184363], [-74.20987, 40.81765, 0, 1564184396], [-74.20998, 40.81746, 0, 1564184409] ] } } ] }

I don't know of any way to add features like timestamp to shapely's LineString, so I'm not sure how to go from a GeoPandas to such a GeoJson.

Does anyone have an idea or a walkthrough for such a process?

Thanks in advance

nuKs commented 2 years ago

I've done it this way, though I can't manage to get it displayed.

tripsdict={
        "type": "FeatureCollection",
        "features": [
            (
                {
                  "id": trip.id,
                  "type": "Feature",
                  "properties": { },
                  "geometry": {
                    "type": "LineString",
                    "coordinates": [
                        [
                            (
                                point.geometry.x,  # lat
                                point.geometry.y,  # lon
                                0,  # alt
                                datetime.timestamp()*1e3  # timestamp in ms
                            ) for datetime, point in point_geodataframe.iterrows()
                        ]
                    ]
                  }
                }
            ) for point_geodataframe in trips
        ]
     }