I'm brand new (as of a week ago) to the OSMnx package and a semester into learning Python / GIS, so feel free to assume shocking ignorance on my part.
My overall goal is to learn more about how to implement OSMnx to get OpenStreetMap (OSM) data on the city level. My secondary to create a bit of Python code that extracts OSM data that I can use as boundary data for Kernel Density Estimates in urban areas.
My first goal is to get a polygon shapefile of Amherst, MA and save it to my computer.
tag_bound = {"boundary":"administrative","admin_level":7,"area":True}
amherst_bound = ox.geometries.geometries_from_place(place_name,tag_bound, which_result=None, buffer_dist=None)
type(amherst_bound)
# Check to make sure it looks reasonable by plotting it. See https://geoffboeing.com/2016/11/osmnx-python-street-networks/
ox.project_gdf(amherst_bound).plot()
_ = amherst_bound.axis('off')
# Save the file
amherst_bound.save_gdf_shapefile(filename= r"C:\Users\afhal\Dropbox\Arboriculture\PythonGIS\finalproject\testshape.shp")
Two parts of the code have an error:
- Plotting Attribute Error
AttributeError Traceback (most recent call last) in () 29 type(amherst_bound) 30 ox.project_gdf(amherst_bound).plot() ---> 31 _ = amherst_bound.axis('off') 32 33 amherst_bound.save_gdf_shapefile(filename= r"C:\Users\afhal\Dropbox\Arboriculture\PythonGIS\finalproject\testshape.shp")
C:\Users\afhal.conda\envs\OpenStreetMap\lib\site-packages\pandas\core\generic.py in getattr(self, name) 5137 if self._info_axis._can_hold_identifiers_and_holds_name(name): 5138
return self[name] -> 5139 return object.getattribute(self, name) 5140 5141 def setattr(self, name: str, value) -> None:AttributeError: 'GeoDataFrame' object has no attribute 'axis'
(Still produces this, which looks weird: )
- Saving Attribute Error
AttributeError Traceback (most recent call last) in () 31 #_ = amherst_bound.axis('off') 32 ---> 33 amherst_bound.save_gdf_shapefile(filename= r"C:\Users\afhal\Dropbox\Arboriculture\PythonGIS\finalproject\testshape.shp") 34 35
C:\Users\afhal.conda\envs\OpenStreetMap\lib\site-packages\pandas\core\generic.py in getattr(self, name) 5137 if self._info_axis._can_hold_identifiers_and_holds_name(name): 5138
return self[name] -> 5139 return object.getattribute(self, name) 5140 5141 def setattr(self, name: str, value) -> None:AttributeError: 'GeoDataFrame' object has no attribute 'save_gdf_shapefile'
I keep seeing people using DiGraphs instead of gdb (OSMnx: Creating Custom Queries with Alternative Infrastructures and GeoPandas and OSMnx- plotting on map), but I'm not sure why that would be preferred.
Where am I going wrong with my plotting and saving?