Skip to content
Snippets Groups Projects
Commit 1af17c40 authored by Oosterhuis's avatar Oosterhuis
Browse files

finished exercise

parent 3630b8d8
Branches
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
Before you turn this problem in, make sure everything runs as expected. First, **restart the kernel** (in the menubar, select Kernel$\rightarrow$Restart) and then **run all cells** (in the menubar, select Cell$\rightarrow$Run All).
Make sure you fill in any place that says `YOUR CODE HERE` or "YOUR ANSWER HERE", as well as your name and collaborators below:
%% Cell type:code id: tags:
``` python
NAME = ""
COLLABORATORS = ""
```
%% Cell type:markdown id: tags:
---
%% Cell type:markdown id: tags:
# Part 3 - Python
Determine the percentage of water on some parcels at the campus. Can you help?
### Determine how much area **(m2 and percentage)** of the combined WUR parcels are covered by water by using the BGT WFS (typename = bgt:waterdeel) (40pts)
Wageningen University are specifically interested in parcels with "perceelnummer": ['10709', '10905', '10906', '10907', '10908', '10909', '11184', '11185', '11208', '11593']
Work with a project structure, either separate your script into sections using comments, or you may create and import functions from other .py files. You can create these sections/functions:
geocodePlacenameToCoordinate
reproject
downloadWFSToGeoDataFrame
calculatePercentageArea
makeWebmap or makeMap (for visualization you can choose to make a map with Folium or matplotlib)
Optional: getBoundingBox
### assign your answers to variables with the name answer_percent (a fraction of 1) and answer_m2
Go easy on webservices! There is no need to use for loops or while statements to call web services multiple times! Upload your documented and well structured Python scripts to a GitLab repository.
Hint: If you need some help how to make functions or how to import modules, have a look at the code in the Python refresher or in the cheat sheets mentioned in the Python refresher.
%% Cell type:code id: tags:
``` python
#import block
import json
from owslib.wfs import WebFeatureService
import geopandas as gpd
from geopy.geocoders import Nominatim
from pyproj import Proj, transform
```
%% Output
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-5276e2475496> in <module>
3 from owslib.wfs import WebFeatureService
4 import geopandas as gpd
----> 5 from geopy.geocoders import Nominatim
6 from pyproj import Proj, transform
ModuleNotFoundError: No module named 'geopy'
%% Cell type:markdown id: tags:
### Find the percentage and m2 of water features on WUR campus (40pts)
assign your answer to a variable named `answer_percent` and `answer_m2` respectively
%% Cell type:code id: tags:
``` python
# YOUR CODE HERE
bgtWfsUrl = 'https://geodata.nationaalgeoregister.nl/beta/bgt/wfs'
topographicalMapWFS = WebFeatureService(url=bgtWfsUrl, version='2.0.0')
topographicalMapWFS.identification.title
print(list(topographicalMapWFS.contents))
x, y = (173994.1578792833, 444133.60329471016)
xmin, xmax, ymin, ymax = x-450, x+350, y-300, y+350
responseRoads = topographicalMapWFS.getfeature(typename='bgt:waterdeel',
bbox=(xmin, ymin, xmax, ymax),
maxfeatures=100, outputFormat='json', startindex=0)
data = json.loads(responseRoads.read())
print(type(data))
print(data.keys())
roadsGDF = gpd.GeoDataFrame.from_features(data['features'])
roadsGDF.plot()
parcelsWFSUrl = 'https://geodata.nationaalgeoregister.nl/kadastralekaartv3/wfs'
parcelsWFS = WebFeatureService(url=parcelsWFSUrl, version='2.0.0')
print(list(parcelsWFS.contents))
responseParcels = parcelsWFS.getfeature(typename='kadastralekaartv3:perceel',
bbox=(xmin, ymin, xmax, ymax),
maxfeatures=100, outputFormat='json', startindex=0)
data = json.loads(responseParcels.read())
parcelsGDF = gpd.GeoDataFrame.from_features(data['features'])
parcelsGDF.plot()
campusParcelsGDF = parcelsGDF[parcelsGDF['perceelnummer'].isin(['10709', '10905', '10906', '10907', '10908', '10909', '11184', '11185', '11208', '11593'])]
campusParcelsGDF.plot()
waterIntersectionGDF = gpd.overlay(roadsGDF, campusParcelsGDF, how="intersection")
waterIntersectionGDF.plot()
answer_m2 = sum(waterIntersectionGDF.area)
answer_percent = answer_m2 / sum(campusParcelsGDF.area)
```
%% Output
['bgt:bak', 'bgt:begroeidterreindeel', 'bgt:bord', 'bgt:buurt', 'bgt:functioneelgebied', 'bgt:gebouwinstallatie', 'bgt:installatie', 'bgt:kast', 'bgt:kunstwerkdeel', 'bgt:mast', 'bgt:nummeraanduiding', 'bgt:onbegroeidterreindeel', 'bgt:ondersteunendwaterdeel', 'bgt:ondersteunendwegdeel', 'bgt:ongeclassificeerdobject', 'bgt:openbareruimtelabel', 'bgt:overbruggingsdeel', 'bgt:overigbouwwerk', 'bgt:overigescheiding', 'bgt:paal', 'bgt:pand', 'bgt:put', 'bgt:scheiding', 'bgt:sensor', 'bgt:spoor', 'bgt:straatmeubilair', 'bgt:tunneldeel', 'bgt:vegetatieobject', 'bgt:waterdeel', 'bgt:waterinrichtingselement', 'bgt:wegdeel', 'bgt:weginrichtingselement', 'bgt:wijk']
<class 'dict'>
dict_keys(['type', 'totalFeatures', 'features', 'crs'])
['kadastralekaartv3:annotatie', 'kadastralekaartv3:bebouwing', 'kadastralekaartv3:kadastralegrens', 'kadastralekaartv3:perceel']
%% Cell type:code id: tags:
``` python
assert type(answer_percent) == float
assert (answer_percent<1.0) == True
assert type(answer_m2) == float
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
### Now plot a map of the water features and the administrative parcels surrounding them (10pts)
%% Cell type:code id: tags:
``` python
#Plot the map
waterIntersectionGDF.plot()
```
%% Output
<matplotlib.axes._subplots.AxesSubplot at 0x7fee116c1780>
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment