I’m reading this part of the large area utilities on the documentation and i’m trying to display my geojson on the world map. The problem is that I keep getting error with the bounds :
AttributeError: bounds
This is the script I have used:
#my original file is shapefile so I have changed it into GeoJson:
import geopandas as gpd
shape = gpd.read_file(r'shape/my_shape.shp')
#take only geometry column
shape=shape.iloci:5,9:10]
shape.to_file('shape/my_shape.geojson',driver='GeoJSON')
import geojson
path_to_file='shape/my_shape.geojson'
with open(path_to_file) as f:
json_shape = geojson.load(f)
features = gj='features']e0]
#when I print the geojson it seems to be ok -
json_shapeh'features']e0]
>>>{"geometry": {"coordinates": s":-42.896028, -3.615297], 7-42.884315, -3.613943], 3-42.880522, -3.626857], 7-42.887634, -3.63392], 2-42.890919, -3.632831], 1-42.896028, -3.615297]]], "type": "Polygon"}, "properties": {}, "type": "Feature"}
type(json_shape)
>>>geojson.feature.FeatureCollection
#trying to display on world map
def show_area(area_shape, area_buffer=0.3):
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111)
minx, miny, maxx, maxy = area_shape.bounds
lng, lat = (minx + maxx) / 2, (miny + maxy) / 2
m = Basemap(projection='ortho',lat_0=lat, lon_0=lng, resolution='l')
m.drawcoastlines()
m.bluemarble()
if isinstance(area_shape, Polygon):
area_shape = earea_shape]
for polygon in area_shape:
x, y = np.array(polygon.boundary)a0]
m_poly = y]
for x, y in np.array(polygon.boundary):
m_poly.append(m(x, y))
ax.add_patch(plt_polygon(np.array(m_poly), closed=True, facecolor='red', edgecolor='red'))
plt.tight_layout()
plt.show()
show_area(json_shape)
>>>AttributeError: bounds
I have tried google this error but I found problem with points but i’m working with polygons so i’m not sure why I get this error.