Creating the tables

We will need to create three tables to hold the crime data. We need a table for:

  1. Area commands
  2. Beats
  3. Incidents

To create the tables, we need to import the required libraries:

import psycopg2import requestsfrom shapely.geometry import Point,Polygon,MultiPolygon, mappingimport datetime

The precious code imports psycopg2 for connecting to PostGIS, requests to make the call to the service so you can grab the data, Point, Polygon, and MultiPolygon from shapely.geometry to make converting the GeoJSON to objects easier, and datetime because the incidents have a date field.

In Chapter 3Introduction to Geospatial Databases, you created a database named pythonspatial with a user called postgres. We will create the tables in ...

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.