0

The problem I am facing is following:

I have a geodandas dataframe, df_geometries, containing polygons and an id.

id  geometry_zone
A1  POLYGON ((119.82334 28.350468, 119.79008 28.350468, 122.85067 28.084328, 122.85067 44.851055, 119.92314 44.717983, 119.82334 28.350468))
A2  POLYGON ((138.79141 26.488018, 141.92247 26.261677, 141.73386 44.897156, 138.79141 44.897156, 138.79141 26.488018))
A3  POLYGON ((65.42207999999999 48.14785, 46.635708 51.165745, 46.597984 47.657444, 68.4777 44.0737, 65.42207999999999 48.14785))
A4  POLYGON ((152.14557 25.884441, 155.50298 26.18623, 155.20119 44.897156, 151.99467 44.93488, 152.14557 25.884441))
A5  POLYGON ((148.71272 25.658098, 152.07013 25.922165, 151.88152 44.897156, 148.90134 44.74626, 148.71272 25.658098))
A6  POLYGON ((145.58167 25.771269, 148.71272 25.46948, 148.8259 44.783985, 145.50621 44.783985, 145.58167 25.771269))
A7  POLYGON ((138.45189 47.61326, 141.84702 47.53781, 141.77158 65.456535, 138.45189 65.49426, 138.45189 47.61326))
A8  POLYGON ((141.92247 26.261677, 145.50621 25.884441, 145.39305 44.82171, 141.88475 44.897156, 141.92247 26.261677))
A9  POLYGON ((135.01904 47.53781, 138.33873 47.61326, 138.37645 65.456535, 134.98132 65.456535, 135.01904 47.53781))
A10 POLYGON ((135.62262 26.789808, 138.75368 26.41257, 138.64052 44.897156, 135.47173 44.897156, 135.62262 26.789808))
A11 POLYGON ((46.42057 66.59079, 46.396214 63.76565, 61.27691 63.76565, 61.37433 66.68821, 46.42057 66.59079))
A12 POLYGON ((128.79465 65.49426, 128.7192 47.61326, 134.98132 47.53781, 134.90587 65.456535, 134.86815 65.49426, 128.79465 65.49426))
A13 POLYGON ((132.567 27.12932, 135.62262 26.902979, 135.32083 44.897156, 132.52928 44.897156, 132.567 27.12932))
A14 POLYGON ((123.13609 65.456535, 122.9852 47.53781, 128.64375 47.61326, 128.64375 65.456535, 123.13609 65.456535))
A15 POLYGON ((129.37106 27.518784, 132.53145 27.285913, 132.46492 44.851055, 129.27126 44.817787, 129.37106 27.518784))
A16 POLYGON ((119.92959 47.61326, 122.90975 47.61326, 122.94748 65.456535, 120.19365 65.456535, 119.92959 47.61326))
A17 POLYGON ((126.01106 27.851458, 129.3378 27.518784, 129.20473 44.851055, 125.91126 44.851055, 126.01106 27.851458))
A18 POLYGON ((117.06259 47.688705, 119.92959 47.688705, 120.08048 65.456535, 117.06259 65.34336999999999, 117.06259 47.688705))
A19 POLYGON ((122.95047 28.084328, 125.91126 27.81819, 125.77819 44.88432, 122.95047 44.851055, 122.95047 28.084328))
A20 POLYGON ((114.29075 47.796272, 116.90591 47.66973, 117.07462 65.42749999999999, 114.248566 65.46968, 114.29075 47.796272))
A21 POLYGON ((110.83199 47.83845, 114.122025 47.66973, 114.07985 65.42749999999999, 110.66327 65.46968, 110.83199 47.83845))
A22 POLYGON ((117.29503 28.749674, 119.79008 28.350468, 119.82334 44.817787, 117.028885 44.817787, 117.29503 28.749674))
A23 POLYGON ((107.668495 47.83845, 110.70545 47.75409, 110.57891 65.46968, 107.668495 65.46968, 107.668495 47.83845))
A24 POLYGON ((113.65805 29.110546, 117.24335 28.773106, 116.990265 44.885853, 113.65805 44.885853, 113.65805 29.110546))
A25 POLYGON ((104.800255 47.83845, 107.541954 47.796272, 107.541954 65.46968, 104.800255 65.42749999999999, 104.800255 47.83845))
A26 POLYGON ((104.67371 44.885853, 104.7159 37.88398, 113.573685 37.71526, 113.573685 44.885853, 104.67371 44.885853))
A27 POLYGON ((101.84766 47.796272, 104.63154 47.75409, 104.63154 65.38531500000001, 101.7633 65.38531500000001, 101.84766 47.796272))
A28 POLYGON ((98.5998 47.75409, 101.7633 47.627552, 101.5524 65.46968, 98.64198 65.46968, 98.5998 47.75409))
A29 POLYGON ((46.32315 69.41593, 46.396214 66.931755, 61.34997 66.834335, 61.130783 69.58641, 46.32315 69.41593))
A30 POLYGON ((95.60502 47.796272, 98.431076 47.796272, 98.431076 65.38531500000001, 95.73156 65.42749999999999, 95.60502 47.796272))

I also have another geopandas dataframe, point_geometries containing points.

              itemId         calculated_geometry
0         77924041068  POINT (139.23960 44.00220)
1         77924041068  POINT (139.23960 44.00220)
2         77924041068  POINT (139.23960 44.00220)
3         77924041068  POINT (139.23960 44.00220)
4         77924041068  POINT (139.23960 44.00220)
...               ...                         ...
225496  9010115143180   POINT (80.24230 89.28000)
225497  9010115024502   POINT (87.93880 80.45960)
225498  9010115226067   POINT (90.89290 67.40300)
225499  9010115226067   POINT (93.88534 65.98715)
225500  9010455000938  POINT (148.24070 30.95850)

Now, all these points in point_geometriesare in theory (and in reality actually) supposed to be on the boundary of the polygons in df_geometries. However, measurement techniques being inaccurate, they can be measured to be within the polygon (which is ok) or outside the boundary.

This is where my problem arises. If I do:

df1 = gpd.sjoin(df_geometries,point_geometries, how="left", op='contains')

many of these points will not be considered as being contained by the polygons because sjoin does exactly what it is supposed to do.

Is there either a tolerance setting (which I haven't found) for sjoin or a way to "inflate" polygons?

I tried using buffer but I either do not know how to use it or it cannot be used in this context. What I did was:

df_geometries = df_geometries['geometry_zone'].buffer(0.2)

but it doesn't change anything.

5
  • 1
    How did you try buffer? Please post your buffer code. Jun 24, 2021 at 6:55
  • @Stefan. I just added the usage of buffer. Jun 24, 2021 at 7:11
  • How many polygons and how many points do you have? Have you tried other values for the how parameter? Jun 24, 2021 at 7:34
  • PS.: Since buffer(...) returns a GeoSeries, I think it should be: df_geometries["geometry_zone"] = df_geometries['geometry_zone'].buffer(0.2) Jun 24, 2021 at 7:36
  • @Stefan Of course! Thanks a lot. It work fine now. Post this as an answer and I'll mark it as accepted so it is no longer unanswered. Thanks again. Jun 24, 2021 at 7:44

1 Answer 1

2

Since buffer(...) returns a GeoSeries, it should be:

df_geometries["geometry_zone"] = df_geometries['geometry_zone'].buffer(0.2)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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