'Looping through a dataframe of polygons gives "ValueError: A LinearRing must have at least 3 coordinate tuples"
I have a dataframe of the neighborhoods of Chicago with their respective polygons
Neighborhood Polygons Polygons_tup
0 Grand Boulevard [[[-87.60670812560363, 41.81681377137387], [-8... [(-87.60670812560363, 41.81681377137387), (-87...
1 Printers Row [[[-87.62760697485339, 41.87437097785366], [-8... [(-87.62760697485339, 41.87437097785366), (-87...
2 United Center [[[-87.66706868914592, 41.88885187769542], [-8... [(-87.66706868914592, 41.88885187769542), (-87...
3 Sheffield & DePaul [[[-87.65833494805524, 41.921661442291786], [-... [(-87.65833494805524, 41.921661442291786), (-8...
4 Humboldt Park [[[-87.74059567509258, 41.88782316893226], [-8... [(-87.74059567509258, 41.88782316893226), (-87...
What I am trying to do is for any given latitude, longitude point, I want to loop through all of the polygons and see if the point is within one of these neighborhoods.
I tried using a for loop to loop through the data frame
def neighbor_finder(long,lat):
for index,row in df_new.iterrows():
poly = row['Polygons_tup']
polygon = Polygon(poly)
point = Point(lat, long)
if polygon.contains(point):
neighborhood = row['Neighborhood']
print(neighborhood)
I was expecting the name of the neighborhood to be printed out but when I ran
long = -87.723960
lat = 41.825320
neighbor_finder(long, lat)
Instead, I received an error
A LinearRing must have at least 3 coordinate tuples
Is there something wrong with my for loop?
Solution 1:[1]
The free() function does not change the value stored in your pointer variable, nor does it necessarily release the previously-allocated memory from valid use by your program.
It does, however, remove from you any guarantee that you have any right to it. Hence, using it after calling free is undefined behavior. (But will generally just get you an access violation and crash.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DĂșthomhas |
