question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TopDownTimeRatioGeneralizer does not support custom geometry column names

See original GitHub issue

Hi,

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:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
anitagrasercommented, Mar 3, 2022

Try collection.trajectories[0].df

0reactions
kntrdzscommented, Mar 4, 2022

Oh, sure. The problem was with the Point geometry. After renaming it works without any issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

v0.10 · Discussion #226 · anitagraser/movingpandas - GitHub
New tutorial on local non-geographic coordinates; add name arg to direction and distance #212 speed and direction column names can now be customized....
Read more >
sf geometry column naming differences R - GIS Stack Exchange
I've just written this which I think will safely rename the geometry column by changing the names element and then setting the geometry...
Read more >
GeoDataFrame does not support multiple columns using the ...
I noticed that when I went type(column) for each column, they are all strings including numerical columns and the geometry column. Maybe ...
Read more >
How to change "column names" - ServiceNow Community
Hi,. you cannot change the name of any custom field in a table, not even through Background Script. There is a reason behind...
Read more >
geopandas.GeoDataFrame
A GeoDataFrame object is a pandas.DataFrame that has a column with geometry. In addition to the standard DataFrame constructor arguments, GeoDataFrame also ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found