I'm working on a python script whose goal is to detect if a point is out of a row of points (gps statement from an agricultural machine). To do this, my idea is to make a buffer around the 10 points around considered point (five before and five after). After that detect if my point is in the buffer. I'm stuck with 'GeoSeries' object has no attribute '_geom'

Here is my code for this part:

for i, row in src.iterrows():

    # Tague les points trop éloignés du rang en cours
    imin, imax = getMinMax(i, nl, 5) # Retourne les 5eme voisins avant et apres

    buddies = src.loc[imin:imax, 'geometry'].drop([i], axis=0) # DF des voisins de i avec uniquement la geometrie
    buddies_buf = buddies.buffer(ird*1.2) # Tampon avec un rayon egal a la distance inter rang + 20% 

    buddies_buf = buddies_buf.unary_union # Fusionne tous les tampons
    buddies_buf = gpd.GeoDataFrame(gpd.GeoSeries(buddies_buf)).rename(columns={0: 'geometry'}).set_geometry('geometry') # Formate le tampon en GDF
    buddies_buf.crs = crs_work # Attribut le crs


Somebody can help me?

I don't know if my idea is the best for this kind of detection, so if you have another best idea...


1 Answer 1


When you are at the following line of your script:


then row.geometry is a single shapely Point (row is a Series representing a single row, so row.geometry is the single geometry from that row), while buddies_buf.geometry is a GeoSeries.

So the within method you are calling is the shapely's Point.within, which can only work with other scalar shapely geometries, and does not recognize a GeoSeries (and it is here that the error is coming from).

The other way around, GeoSeries methods can work with both GeoSeries or shapely objects as argument. So you can invert the operation:

  • Ok it's good. But I don't understand why row.geometry and buddies_buf.geometrydoesn't give same kind of object.
    – Tim C.
    Jan 24, 2019 at 13:37
  • 4
    buddies_buf is a GeoDataFrame, and accessing the geometry column gives you a GeoSeries. row is an object Series and accessing the geometry element gives you a scalar Point.
    – joris
    Jan 24, 2019 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.