TopDownTimeRatioGeneralizer does not support custom geometry column names
See original GitHub issueHi,
Unlike other generalization functions, TopDownTimeRatioGeneralizer returns an error message : AttributeError: The ‘Series’ object does not have a ‘geometry’ attribute. No matter that I use a trajectory or a trajectorycollection.
topDownGener=mpd.TopDownTimeRatioGeneralizer(collection).generalize(tolerance=0.0001)
`--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_39264/2560778543.py in <module> ----> 1 topDownGener=mpd.TopDownTimeRatioGeneralizer(collection).generalize(tolerance=0.0001)
~\anaconda3\envs\MovingPandas\lib\site-packages\movingpandas\trajectory_generalizer.py in generalize(self, tolerance) 42 return self._generalize_traj(self.traj, tolerance) 43 elif isinstance(self.traj, TrajectoryCollection): —> 44 return self._generalize_traj_collection(tolerance) 45 else: 46 raise TypeError
~\anaconda3\envs\MovingPandas\lib\site-packages\movingpandas\trajectory_generalizer.py in _generalize_traj_collection(self, tolerance) 49 generalized = [] 50 for traj in self.traj: —> 51 generalized.append(self._generalize_traj(traj, tolerance)) 52 result = copy(self.traj) 53 result.trajectories = generalized
~\anaconda3\envs\MovingPandas\lib\site-packages\movingpandas\trajectory_generalizer.py in _generalize_traj(self, traj, tolerance) 239 240 def _generalize_traj(self, traj, tolerance): –> 241 return Trajectory(self.td_tr(traj.df.copy(), tolerance), traj.id) 242 243 def td_tr(self, df, tolerance):
~\anaconda3\envs\MovingPandas\lib\site-packages\movingpandas\trajectory_generalizer.py in td_tr(self, df, tolerance) 252 dy = df.geometry.iloc[-1].y - df.geometry.iloc[0].y 253 –> 254 dists = df.apply( 255 lambda rec: self._dist_from_calced( 256 rec, df.index.min().to_pydatetime(), df.geometry.iloc[0], de, dx, dy
~\anaconda3\envs\MovingPandas\lib\site-packages\geopandas\geodataframe.py in apply(self, func, axis, raw, result_type, args, **kwargs) 1388 @doc(pd.DataFrame) 1389 def apply(self, func, axis=0, raw=False, result_type=None, args=(), **kwargs): -> 1390 result = super().apply( 1391 func, axis=axis, raw=raw, result_type=result_type, args=args, **kwargs 1392 )
~\anaconda3\envs\MovingPandas\lib\site-packages\pandas\core\frame.py in apply(self, func, axis, raw, result_type, args, **kwargs) 8831 kwargs=kwargs, 8832 ) -> 8833 return op.apply().finalize(self, method=“apply”) 8834 8835 def applymap(
~\anaconda3\envs\MovingPandas\lib\site-packages\pandas\core\apply.py in apply(self) 725 return self.apply_raw() 726 –> 727 return self.apply_standard() 728 729 def agg(self):
~\anaconda3\envs\MovingPandas\lib\site-packages\pandas\core\apply.py in apply_standard(self) 849 850 def apply_standard(self): –> 851 results, res_index = self.apply_series_generator() 852 853 # wrap results
~\anaconda3\envs\MovingPandas\lib\site-packages\pandas\core\apply.py in apply_series_generator(self) 865 for i, v in enumerate(series_gen): 866 # ignore SettingWithCopy here in case the user mutates –> 867 results[i] = self.f(v) 868 if isinstance(results[i], ABCSeries): 869 # If we have a view on v, we need to make a copy because
~\anaconda3\envs\MovingPandas\lib\site-packages\movingpandas\trajectory_generalizer.py in <lambda>(rec) 253 254 dists = df.apply( –> 255 lambda rec: self._dist_from_calced( 256 rec, df.index.min().to_pydatetime(), df.geometry.iloc[0], de, dx, dy 257 ),
~\anaconda3\envs\MovingPandas\lib\site-packages\movingpandas\trajectory_generalizer.py in _dist_from_calced(self, rec, start_t, start_geom, de, dx, dy) 276 di = (rec.name - start_t).total_seconds() 277 calced = Point(start_geom.x + dx * di / de, start_geom.y + dy * di / de) –> 278 return rec.geometry.distance(calced)
~\anaconda3\envs\MovingPandas\lib\site-packages\pandas\core\generic.py in getattr(self, name) 5581 ): 5582 return self[name] -> 5583 return object.getattribute(self, name) 5584 5585 def setattr(self, name: str, value) -> None:
AttributeError: ‘Series’ object has no attribute ‘geometry’`
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Try collection.trajectories[0].df
Oh, sure. The problem was with the Point geometry. After renaming it works without any issue.