添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Stack Exchange Network

Stack Exchange network consists of 181 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Visit Stack Exchange

Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.

Sign up to join this community

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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
    print((row.geometry).within(buddies_buf.geometry))

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...

When you are at the following line of your script:

print((row.geometry).within(buddies_buf.geometry))

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:

buddies_buf.geometry.contains(row.geometry)
                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
                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
        

Thanks for contributing an answer to Geographic Information Systems Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.