Getting a district by ID

Passing the integer district ID will return only the requested representation of the district. The geometry is converted to GeoJSON format using shapely and the to_shape method from geoalchemy2.shape:

@app.route('/nba/api/v0.1/district/<int:district_id>', methods=['GET'])
def get_district(district_id):
district = session.query(District).get(district_id)
shp = to_shape(district.geom)
geojson = shapely.geometry.geo.mapping(shp)
data = [{"type": "Feature",
"properties":{"district":district.district,"id":district.id},
"geometry":{"type":"MultiPolygon",
"coordinates":[geojson['coordinates']]},
}]
return jsonify({"type": "FeatureCollection","features":data})
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset