April 2018
Beginner to intermediate
440 pages
11h 36m
English
You have mapped data from tables, but now you will map the results of a geoprocessing task—buffer.
To code a buffer example, we must first create a point. The following code will do that for us:
from shapely.geometry import mappingp = Point([-106.578677,35.062485])pgeojson=mapping(p)player=GeoJSON(data=pgeojson)map.add_layer(player)
The previous code creates a point using Shapely. It then converts it to GeoJSON using shapely.geometry.mapping(). The next two lines allow us to display it on the map.
PostGIS allows you to send data to the database and get data back, none of which has to be in a table. For example, examine the following code:
cursor.execute("SELECT ST_AsGeoJSON(ST_Buffer(ST_GeomFromText('{}')::geography,1500));".format(p.wkt)) ...