Skip to content

Commit

Permalink
Trajectory.is_latlon() update for GeoPandas 0.7 (#50)
Browse files Browse the repository at this point in the history
is_latlon compatibility with gpd 0.7
  • Loading branch information
martinfleis authored and anitagraser committed Jan 26, 2020
1 parent 01417e5 commit 4d656cb
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions movingpandas/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from shapely.affinity import translate
from shapely.geometry import Point, LineString
from fiona.crs import from_epsg
from datetime import datetime
from pandas import Grouper

Expand Down Expand Up @@ -87,7 +86,7 @@ def hvplot(self, *args, **kwargs):
"""
Generate an interactive plot using hvplot.
The following parameters are set by default: geo=True, tiles='OSM'.
The following parameters are set by default: geo=True, tiles='OSM'.
Parameters
----------
Expand All @@ -114,16 +113,16 @@ def is_valid(self):

def is_latlon(self):
"""
Return whether the trajectory CRS is WGS 84.
Return whether the trajectory CRS is geographic.
Returns
-------
bool
"""
if self.crs['init'] == from_epsg(4326)['init']:
return True
else:
return False
from pyproj import CRS

crs = CRS.from_user_input(self.crs)
return crs.is_geographic

def to_crs(self, crs):
"""
Expand Down Expand Up @@ -368,7 +367,7 @@ def get_segment_between(self, t1, t2):
if not segment.is_valid():
raise RuntimeError("Failed to extract valid trajectory segment between {} and {}".format(t1, t2))
return segment

def _compute_distance(self, row):
pt0 = row['prev_pt']
pt1 = row['geometry']
Expand All @@ -380,16 +379,16 @@ def _compute_distance(self, row):
dist_meters = measure_distance_spherical(pt0, pt1)
else: # The following distance will be in CRS units that might not be meters!
dist_meters = measure_distance_euclidean(pt0, pt1)
return dist_meters
return dist_meters

def _add_prev_pt(self, force=True):
"""
Create a shifted geometry column with previous positions.
"""
if 'prev_pt' not in self.df.columns or force:
# TODO: decide on default enforcement behavior
self.df = self.df.assign(prev_pt=self.df.geometry.shift())

def get_length(self):
"""
Return the length of the trajectory.
Expand Down Expand Up @@ -424,7 +423,7 @@ def get_direction(self):
return calculate_initial_compass_bearing(pt0, pt1)
else:
return azimuth(pt0, pt1)

def _compute_heading(self, row):
pt0 = row['prev_pt']
pt1 = row['geometry']
Expand Down Expand Up @@ -566,7 +565,7 @@ def intersection(self, feature, pointbased=False):
Trajectory segment intersecting with the feature
"""
return intersection(self, feature, pointbased)

def split_by_date(self, mode='day'):
"""
Split trajectory into subtrajectories using regular time intervals.
Expand Down

0 comments on commit 4d656cb

Please sign in to comment.