-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccess_WFS_with_python
More file actions
73 lines (53 loc) · 2.09 KB
/
Copy pathaccess_WFS_with_python
File metadata and controls
73 lines (53 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 22 18:13:38 2021
@author: mlc
"""
#import fiona; # help(fiona.open)
#import shapely as st
#import matplotlib.pyplot as plt
#import numpy as np
#from matplotlib import interactive, style
import pandas as pd
import geopandas as geopd
import os
from time import process_time
from owslib.wfs import WebFeatureService # <-------------------------------------------------
# a instalação no conda tem erro: fazer pip install --force-reinstall pyproj
# também tive
import pyproj
from requests import Request
# test pyproj # https://stackoverflow.com/questions/55390492/runtimeerror-bno-arguments-in-initialization-list
pyproj.Proj("+init=epsg:3857")
#C:\Users\mlc\OneDrive - Universidade de Lisboa\Documents\geomatica-sigdr-2020-2021\Trabalho_avaliacao\InvFlorNacional
os.chdir("C:\\Users\\mlc\\OneDrive - Universidade de Lisboa\\Documents\\geomatica-sigdr-2020-2021\\Trabalho_avaliacao\\InvFlorNacional")
os.getcwd()
# URL for WFS backend
url = "http://si.icnf.pt/wfs/rnap"
url = "http://si.icnf.pt/wfs/ifn_2015"
# See details about this particular WFS
# -------------------------------------
# Initialize <-------------------------------------------- create connection
wfs = WebFeatureService(url=url)
# Service provider
print(wfs.identification.title)
# Get WFS version
print(wfs.version)
# Available methods
print([operation.name for operation in wfs.operations])
# Available data layers
print(list(wfs.contents))
# Print all metadata of all layers
for layer, meta in wfs.items():
print(meta.__dict__)
# Get data from WFS
# -----------------
# Fetch the last available layer (as an example) --> 'vaestoruutu:vaki2017_5km'
layer = list(wfs.contents)[-1]
# Specify the parameters for fetching the data
params = dict(service='WFS', version="1.0.0", request='GetFeature', typeName=layer, outputFormat='json')
# Parse the URL with parameters # <----------------------------- create request
q = Request('GET', url, params=params).prepare().url
# Read data from URL # <-------------------------------------- read data with geopandas
data = geopd.read_file(q)
data.columns