#!/usr/bin/env python
# coding: utf-8
# ## Geopandas!
# This notebook is to highlight how easy it is to display shapefiles in a jupyter notebook
#
# Shapefiles have many files, but are still one of the most common GIS file format to be sent or requested
#
# Often we just want to display them, flicking back from python and GIS can be frustrating. That is one of the reasons why command line python in a GIS is so convient
#
# However sometimes we just want to show out data, perhaps in a presentation and then get on with the processing and geopandas in jupyter notebooks is perfect for that
#
# I came across this blog almost a year ago, and was blown away by how simple geopandas was
#
# https://agilescientific.com/blog/2017/8/10/x-lines-of-python-read-and-write-a-shapefile
#
#
# This notebook is all about viewing data. We will start by viewing 1 shapefile and then 2 as layers - as you would in a GIS
#
#
# Data used in this notebook is a sample adapted from
# https://data.gov.uk/dataset/d43263ba-6f09-458e-995e-69720909365f/crop-map-of-england-crome-2016-south-west
#
# and a layer I created myself as part of my geospatial python course
#
# http://www.acgeospatial.co.uk/training/
#
# #### Start by reading in a shapefile
# In[1]:
import geopandas as gpd
gdf = gpd.read_file('.../RPA_hexagons.shp')
print (gdf)
# ### 3 lines of code
#
# Some examples in org are here
#
# https://pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html#get-shapefile-feature-count
#
# geopandas seems easy to read for a beginner and it is fast
#
#
# What about viewing the data in the notebook.
#
# that is just one line of code
# In[3]:
get_ipython().run_line_magic('matplotlib', 'inline')
gdf.plot()
# ### What about colouring the data based on a field
#
# (look at the table in the first cell for the field names)
# In[4]:
gdf.plot(column='LUCODE', cmap=None)
# ### What about a legend?
#
# parse legend=True
# In[8]:
gdf.plot(column='LUCODE', cmap=None, legend=True)
# ### Legend is too big! Too many attributes?
#
# make the figure larger
#
# use figsize
# In[5]:
gdf.plot(column='LUCODE', cmap=None, legend=True, figsize=(20, 20))
# ### Add another shapefile into another geopandas dataframe
# In[7]:
gdf2 = gpd.read_file('.../Boundaries.shp')
print (gdf2)
# ### Plot them on each other and shade the new shapefile by the column 'id'
# In[11]:
import matplotlib.pyplot as plt
f, ax = plt.subplots(1)
gdf.plot(ax=ax)
gdf2.plot(ax=ax,column='id',cmap=None,)
plt.show()
# In[12]:
print (f)
# In[13]:
print (ax)
# In[ ]: