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 include more parameters. Try adding in conditionals that check for fields to return, or another conditional. All URL parameter arguments are added after a question mark ('?') in the query.

..................Content has been hidden....................

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