Getting a district by name

In this case, the name of the district is the congressional district number. There is a name field, but it contains the name of the elected representative from that district:

@app.route('/nba/api/v0.1/district/<dist>', methods=['GET'])def get_district_name(dist):  districts = session.query(District).filter(District.district.like(dist+"%")).all()  data = [{"type": "Feature",   "properties":{"district":district.district,"id":district.id,   "representative":district.name},   "geometry":{"type":"MultiPolygon",   "coordinates":shapely.geometry.geo.mapping(to_shape(district.geom))["coordinates"]},  } for district in districts]  return jsonify({"type": "FeatureCollection","features":data})

All of these methods can be adjusted to ...

Get Mastering Geospatial Analysis with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.