title: Plotting polygons from SQL type geo column in Python
body: <p>I have an Sqlite database with a table that includes a geo column. When I add this table into QGIS as a layer, it shows a map of Chicago with polygons as shown below. I think, the polygon points are stored in the column named geo.</p>
  <p><a href="https://i.stack.imgur.com/ZZvh2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZZvh2.png" alt="enter image description here" /></a></p>
  <p>I am trying to plot the same in Python to be able to add more things on top of this layout using Matplotlib. To begin with, I could load the table named &quot;Zone&quot; in Python using the following (that I wrote):</p>
  <pre><code>import sqlite3  # Package for SQLite
  ### BEGIN DEFINING A READER FUNCTION ###
  def Conditional_Sqdb_reader(Sqdb,Tablename,Columns,Condition):
      conn = sqlite3.connect(Sqdb) # Connects the file to Python
      print(&quot;\nConnected to %s.\n&quot;%(Sqdb))
      conn.execute('pragma foreign_keys = off') # Allows making changes into the SQLite file
      print(&quot;SQLite Foreign_keys are unlocked...\n&quot;)
      c = conn.cursor() # Assigns c as the cursor
      print(&quot;Importing columns: %s \nin table %s from %s.\n&quot;%(Columns,Tablename,Sqdb))
      c.execute('''SELECT {columns} 
                   FROM {table}
                   {condition}'''.format(table=Tablename,
                                         columns=Columns,
                                        condition=Condition)) # Selects the table to read/fetch
      Sql_headers = [description[0] for description in c.description]
      Sql_columns = c.fetchall() # Reads the table and saves into the memory as Sql_rows
      print(&quot;Importing completed...\n&quot;)
      conn.commit() # Commits all the changes made
      conn.execute('pragma foreign_keys = on') # Locks the SQLite file
      print(&quot;SQLite Foreign_keys are locked...\n&quot;)
      conn.close() # Closes the SQLite file
      print(&quot;Disconnected from %s.\n&quot;%(Sqdb))
      return Sql_headers,Sql_columns
  ### END DEFINING A READER FUNCTION ###
  
  Sqdb = '/mypath/myfile.sqlite'
  Tablename = &quot;Zone&quot; # Change this with your desired table to play with
  Columns = &quot;&quot;&quot;*&quot;&quot;&quot; # Changes this with your desired columns to import
  Condition = ''    # Add your condition and leave blank if no condition
  
  headings,data = Conditional_Sqdb_reader(Sqdb,Tablename,Columns,Condition)
  </code></pre>
  <p>The data on the table is stored in &quot;data&quot; as a list. So, <code>data[0][-1]</code> yields the geo of the polygon of the first row, which looks something like: <code>b'\x00\x01$i\x00\x00@\xd9\x94\x8b\xd6&lt;\x1bAb\xda7\xb6]\xb1QA\xf0\xf7\x8b\x19UC\x1bA\x9c\xde\xc5\r\xc3\xb1QA|\x03\x00\x00\x00\x01\x00\x00\x00\x06\x00\x00\x00Hlw\xef-C\x1bA\x9c\xde\xc5\r\xc3\xb1QA\xf0\xf7\x8b\x19UC\x1bAv\xc0u)^\xb1QA\xbcw\xd4\x88\xf1&lt;\x1bAb\xda7\xb6]\xb1QA\xa5\xdc}n\xd7&lt;\x1bA\x84.\xe1r\xbe\xb1QA@\xd9\x94\x8b\xd6&lt;\x1bA\xce\x8eT\xef\xc1\xb1QAHlw\xef-C\x1bA\x9c\xde\xc5\r\xc3\xb1QA\xfe'</code> I do not know how to decode this and convert to a meaningful series of points, but that is what it is and QGIS apparently can do it with no hassle. How can I plot all these polygons in Python while being able to add other things within the Matplotlib world later on?</p>