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.

Error when joinned two GeoDataFrame

See original GitHub issue

Hy everyone,

I have this first gdf:

| DATA     | OCCUR           | geometry
2005-01-01 | PROPERTY CRIMES | POINT (-38.5554 -3.73784)
2005-01-01 | PROPERTY CRIMES | POINT (-38.5606 -3.83914)
2005-01-01 | PROPERTY CRIMES | POINT (-38.5778 -3.72623)
2005-01-01 | PROPERTY CRIMES | POINT (-38.501 -3.795)
2005-01-01 | PROPERTY CRIMES | POINT (-38.4813 -3.72222)

And this second:

BAIRRO          | VAL_M2_RES | geometry
PASSARE         | 2424.77    | POLYGON ((-38.539819067859945 -3.7955371068432...
CAIS DO PORTO   | 2627.39    | POLYGON ((-38.479334495231086 -3.7209126986722...
CIDADE 2000     | 2437.00    | POLYGON ((-38.467647506862534 -3.7496832300526...
ALTO DA BALANCA | 1784.38    | POLYGON ((-38.51716445420212 -3.76997951516616...
BARRA DO CEARA  | 1551.97    | POLYGON ((-38.56887758295916 -3.70168935573553...

Then I try merge, this command:

merged_gdf = gpd.sjoin(calls_gdf, regions_gdf, how="inner", op="intersects")

But not working. Show me this error:


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-19-879197754ba3> in <module>()
----> 1 merged_gdf = gpd.sjoin(calls_gdf, regions_gdf, how="inner", op="intersects")
      2 #calls_gdf["BAIRRO"][0] = "TESTE"

C:\ProgramData\Anaconda3\lib\site-packages\geopandas\tools\sjoin.py in sjoin(left_df, right_df, how, op, lsuffix, rsuffix)
     65 
     66     # insert the bounds in the rtree spatial index
---> 67     right_df_bounds = right_df.geometry.apply(lambda x: x.bounds)
     68     stream = ((i, b, None) for i, b in enumerate(right_df_bounds))
     69     tree_idx = rtree.index.Index(stream)

C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds)
   2353             else:
   2354                 values = self.asobject
-> 2355                 mapped = lib.map_infer(values, f, convert=convert_dtype)
   2356 
   2357         if len(mapped) and isinstance(mapped[0], Series):

pandas\_libs\src\inference.pyx in pandas._libs.lib.map_infer (pandas\_libs\lib.c:66645)()

C:\ProgramData\Anaconda3\lib\site-packages\geopandas\tools\sjoin.py in <lambda>(x)
     65 
     66     # insert the bounds in the rtree spatial index
---> 67     right_df_bounds = right_df.geometry.apply(lambda x: x.bounds)
     68     stream = ((i, b, None) for i, b in enumerate(right_df_bounds))
     69     tree_idx = rtree.index.Index(stream)

AttributeError: 'str' object has no attribute 'bounds'

Can you help me?

Thanks.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jorisvandenbosschecommented, Oct 18, 2017

I think you can also use shapely.wkt.loads for this:

In [59]: import shapely.wkt

In [60]: shapely.wkt.loads("POINT (-38.5554 -3.73784)")
Out[60]: <shapely.geometry.point.Point at 0x7efd31c60518>

In [61]: print(shapely.wkt.loads("POINT (-38.5554 -3.73784)"))
POINT (-38.5554 -3.73784)

In [62]: s = pd.Series(["POINT (-38.5554 -3.73784)", "POINT (-38.5554 -3.73784)"])

In [64]: s.apply(shapely.wkt.loads)
Out[64]: 
0    POINT (-38.5554 -3.73784)
1    POINT (-38.5554 -3.73784)
dtype: object

Maybe it would be good to have some utility function for this in geopandas (or at least add an example to the docs)

1reaction
jorisvandenbosschecommented, Oct 17, 2017

It seems that your geometry column does not consist of shapely geometry objects, but of strings. Can you show the output of type(regions_gdf.geometry[0]) (and the same for the other dataframe) ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

'left_df' should be GeoDataFrame, got <class 'geopandas. ...
GeoPandas Spatial Join Error: 'left_df' should be GeoDataFrame, got <class 'geopandas.geoseries.GeoSeries' ; 8580848.223) 1 ; 8588489.910) 2 ...
Read more >
How can i use sjoin to merge two GeoDataFrames without ...
I am attempting to complete a spatial join between two GeodataFrames but this error comes up: ValueError: You are trying to merge on...
Read more >
Spatial Joins
A spatial join uses binary predicates such as intersects and crosses to combine two GeoDataFrames based on the spatial relationship between their geometries ......
Read more >
Why does spatial join on geodataframes return empty result?
I have two geodataframes that I want to perform a spatial join on; one is points, one is polygons. They are both dtype:...
Read more >
geopandas/geopandas - Gitter
hi, i'm trying to join two geodataframes, and i'm getting this rather long key error. i have two geodataframes, with two geometry columns,...
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