Skip to content

Commit

Permalink
Merge branch 'master' into no_circles
Browse files Browse the repository at this point in the history
  • Loading branch information
bifbof committed Oct 18, 2023
2 parents 8de386e + e04d079 commit 54e7b2e
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions trackintel/io/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import geopandas as gpd
import pandas as pd
from geopandas.geodataframe import GeoDataFrame
from shapely import wkt
from trackintel.io.from_geopandas import (
read_locations_gpd,
read_positionfixes_gpd,
Expand Down Expand Up @@ -195,10 +194,7 @@ def read_triplegs_csv(*args, columns=None, tz=None, index_col=None, geom_col="ge
short="tpls",
)
def write_triplegs_csv(triplegs, filename, *args, **kwargs):
geo_col_name = triplegs.geometry.name
df = pd.DataFrame(triplegs, copy=True)
df[geo_col_name] = triplegs.geometry.apply(wkt.dumps)
df.to_csv(filename, index=True, *args, **kwargs)
pd.DataFrame.to_csv(triplegs.to_wkt(rounding_precision=-1, trim=False), filename, index=True, *args, **kwargs)


@_index_warning_default_none
Expand Down Expand Up @@ -269,10 +265,7 @@ def read_staypoints_csv(*args, columns=None, tz=None, index_col=None, geom_col="
short="sp",
)
def write_staypoints_csv(staypoints, filename, *args, **kwargs):
geo_col_name = staypoints.geometry.name
df = pd.DataFrame(staypoints, copy=True)
df[geo_col_name] = staypoints.geometry.apply(wkt.dumps)
df.to_csv(filename, index=True, *args, **kwargs)
pd.DataFrame.to_csv(staypoints.to_wkt(rounding_precision=-1, trim=False), filename, index=True, *args, **kwargs)


@_index_warning_default_none
Expand Down Expand Up @@ -337,11 +330,7 @@ def read_locations_csv(*args, columns=None, index_col=None, crs=None, **kwargs):
short="locs",
)
def write_locations_csv(locations, filename, *args, **kwargs):
df = pd.DataFrame(locations, copy=True)
df["center"] = locations["center"].apply(wkt.dumps)
if "extent" in df.columns:
df["extent"] = locations["extent"].apply(wkt.dumps)
df.to_csv(filename, index=True, *args, **kwargs)
pd.DataFrame.to_csv(locations.to_wkt(rounding_precision=-1, trim=False), filename, index=True, *args, **kwargs)


@_index_warning_default_none
Expand Down Expand Up @@ -422,12 +411,10 @@ def read_trips_csv(*args, columns=None, tz=None, index_col=None, geom_col=None,
_shared_docs["write_csv"], first_arg="\ntrips : (Geo)DataFrame (as trackintel trips)\n", long="trips", short="trips"
)
def write_trips_csv(trips, filename, *args, **kwargs):
df = trips.copy()
if isinstance(df, GeoDataFrame):
geom_col_name = df.geometry.name
df[geom_col_name] = df[geom_col_name].to_wkt()
if isinstance(trips, GeoDataFrame):
trips = trips.to_wkt(rounding_precision=-1, trim=False)
# static call necessary as TripsDataFrame has a to_csv method as well.
pd.DataFrame.to_csv(df, filename, index=True, *args, **kwargs)
pd.DataFrame.to_csv(trips, filename, index=True, *args, **kwargs)


@_index_warning_default_none
Expand Down

0 comments on commit 54e7b2e

Please sign in to comment.