Advertisement
Kum_R

Geopint_polygon

Apr 15th, 2020
285
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import geopandas
  2. #bus stop dataset
  3. gdf = geopandas.GeoDataFrame(
  4.     bus, geometry=geopandas.points_from_xy(bus.stop_location_longitiude, bus.stop_location_latitiude))
  5.  
  6. #columns
  7. #stop_name  stop_location_longitiude    stop_location_latitiude     geometry
  8.  
  9. #Country polygon
  10. import geopandas as gpd
  11. data_poly = gpd.read_file("Country_community_file.geojson")
  12.  
  13. """Index(['Name', 'description', 'altitudeMode', 'CNAME_E', 'CNAME_A', 'OBJECTID',
  14.       'LABEL_E', 'LABEL_A', 'C_PREFIX_E', 'C_PREFIX_A', 'COMMUNITY_',
  15.       'COMMUNITY1', 'DGIS_ID', 'COMM_NUM', 'NDGIS_ID', 'SHAPE_AREA',
  16.       'SHAPE_LEN', 'geometry'],
  17.      dtype='object')"""
  18.  
  19. import geopandas as gpd
  20. joined_gdf = gpd.sjoin(gdf, data_poly, op='within')
  21.  
  22.  
  23. Error
  24. ---------------------------------------------------------------------------
  25. AttributeError                            Traceback (most recent call last)
  26. <ipython-input-49-145cab3e1349> in <module>
  27.       1 import geopandas as gpd
  28. ----> 2 joined_gdf = gpd.sjoin(gdf, data_poly, op='within')
  29.  
  30. /opt/anaconda3/lib/python3.7/site-packages/geopandas/tools/sjoin.py in sjoin(left_df, right_df, how, op, lsuffix, rsuffix)
  31.     134         # tree_idx_df == 'left'
  32.     135         idxmatch = right_df.geometry.apply(lambda x: x.bounds).apply(
  33. --> 136             lambda x: list(tree_idx.intersection(x)) if not x == () else []
  34.     137         )
  35.     138         idxmatch = idxmatch[idxmatch.apply(len) > 0]
  36.  
  37. /opt/anaconda3/lib/python3.7/site-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwds)
  38.    3846             else:
  39.    3847                 values = self.astype(object).values
  40. -> 3848                 mapped = lib.map_infer(values, f, convert=convert_dtype)
  41.    3849
  42.    3850         if len(mapped) and isinstance(mapped[0], Series):
  43.  
  44. pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()
  45.  
  46. /opt/anaconda3/lib/python3.7/site-packages/geopandas/tools/sjoin.py in <lambda>(x)
  47.     134         # tree_idx_df == 'left'
  48.     135         idxmatch = right_df.geometry.apply(lambda x: x.bounds).apply(
  49. --> 136             lambda x: list(tree_idx.intersection(x)) if not x == () else []
  50.     137         )
  51.     138         idxmatch = idxmatch[idxmatch.apply(len) > 0]
  52.  
  53. AttributeError: 'NoneType' object has no attribute 'intersection'
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement