Created
December 29, 2022 13:20
-
-
Save esgn/06db6f1bd423fc5eed493e02a17bf0a4 to your computer and use it in GitHub Desktop.
Download GPKG from WFS example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
try: | |
from osgeo import ogr, osr, gdal | |
except: | |
sys.exit('ERROR: cannot find GDAL/OGR modules') | |
# Set the driver (optional) | |
wfs_drv = ogr.GetDriverByName('WFS') | |
# Speeds up querying WFS capabilities for services with alot of layers | |
gdal.SetConfigOption('OGR_WFS_LOAD_MULTIPLE_LAYER_DEFN', 'NO') | |
# Set config for paging. Works on WFS 2.0 services and WFS 1.0 and 1.1 with some other services. | |
gdal.SetConfigOption('OGR_WFS_PAGING_ALLOWED', 'YES') | |
gdal.SetConfigOption('OGR_WFS_PAGE_SIZE', '1000') | |
# Open the webservice | |
url = 'https://wxs.ign.fr/ortho/geoportail/wfs?SERVICE=WFS' | |
wfs_ds = wfs_drv.Open('WFS:' + url) | |
if not wfs_ds: | |
sys.exit('ERROR: cannot open WFS datasource') | |
else: | |
pass | |
# Get a specific layer | |
layer = wfs_ds.GetLayerByName("ORTHOIMAGERY.ORTHOPHOTOS.GRAPHE-MOSAIQUAGE:graphe_bdortho") | |
dr = ogr.GetDriverByName( 'GPKG' ) | |
ds = dr.CreateDataSource( 'graphe_bdortho.gpkg' ) | |
ds.CopyLayer(layer, 'local_copy') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment