April 2018
Beginner to intermediate
440 pages
11h 36m
English
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})