With the tables in place, we need to grab the data and populate them. The following code will grab the area commands and insert them into our table:
url='http://coagisweb.cabq.gov/arcgis/rest/services/public/adminboundaries/MapServer/8/query'params={"where":"1=1","outFields":"*","outSR":"4326","f":"json"}r=requests.get(url,params=params)data=r.json()for acmd in data['features']: polys=[] for ring in acmd['geometry']['rings']: polys.append(Polygon(ring)) p=MultiPolygon(polys) name=acmd['attributes']['Area_Command'] cursor.execute("INSERT INTO areacommand (name, geom) VALUES ('{}', ST_GeomFromText('{}'))".format(name, p.wkt)) connection.commit()
The previous code uses requests to query the URL passing parameters. The ...