Created
September 16, 2020 18:42
-
-
Save ttomasz/0079278df7a51fef7052043b95f7a708 to your computer and use it in GitHub Desktop.
Przykład kodu w Python zdobywającego URL arkuszy Ortofotomapy z geoportal.gov.pl - wersja bardzo wstępna
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
certifi==2020.6.20 | |
chardet==3.0.4 | |
idna==2.10 | |
pyshp==2.1.2 | |
requests==2.24.0 | |
urllib3==1.25.10 |
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 re | |
import requests | |
import shapefile | |
shapefile_path = 'shapefiles/PL1992_5000_025' | |
wms_request_base_url = 'https://mapy.geoportal.gov.pl/wss/service/PZGIK/ORTO/WMS/SkorowidzeWgAktualnosci' | |
wms_request_parameters = { | |
'SERVICE': 'WMS', | |
'request': 'GetFeatureInfo', | |
'version': '1.3.0', | |
'layers': 'SkorowidzeOrtofotomapyStarsze,SkorowidzeOrtofotomapy2018,SkorowidzeOrtofotomapy2019,SkorowidzeOrtofotomapy2020', | |
'styles': '', | |
'crs': 'EPSG:2180', | |
'width': 1000, | |
'height': 1000, | |
'format': 'image/png', | |
'transparent': 'true', | |
'query_layers': 'SkorowidzeOrtofotomapyStarsze,SkorowidzeOrtofotomapy2018,SkorowidzeOrtofotomapy2019,SkorowidzeOrtofotomapy2020', | |
'i': 1, | |
'j': 1, | |
'INFO_FORMAT': 'text/html' | |
} | |
regexp = '{url:"(.+)",godlo:"(.+)", aktualnosc:"(.+)", wielkoscPiksela:"(.+)", ukladWspolrzednych:"(.+)", calyArkuszWyeplnionyTrescia:"(.+)", modulArchiwizacji:"(.+)", zrodloDanych:"(.+)", kolor:"(.+)", numerZgloszeniaPracy:"(.+)", aktualnoscRok:"(.+)"}' | |
compiled_regexp = re.compile(regexp, re.IGNORECASE) | |
attribute_names = [ | |
'url', | |
'godlo', | |
'aktualnosc', | |
'wielkoscPiksela', | |
'ukladWspolrzednych', | |
'calyArkuszWyeplnionyTrescia', | |
'modulArchiwizacji', | |
'zrodloDanych', | |
'kolor', | |
'numerZgloszeniaPracy', | |
'aktualnoscRok' | |
] | |
if __name__ == '__main__': | |
# open shape file | |
with shapefile.Reader(shapefile_path) as shp: | |
total_rows = shp.numRecords | |
# for each record in the shapefile (we are ignoring geometry here) | |
for row_num, row in enumerate(shp.iterRecords()): | |
# ----------------------------------------------------- | |
# remove before production use: | |
if row_num > 1: break # for testing, get first n rows | |
# ----------------------------------------------------- | |
# get row as dict so we have attribute names | |
r = row.as_dict() | |
# create bounding box | |
minx = min(r['x1'], r['x2'], r['x3'], r['x4']) | |
miny = min(r['y1'], r['y2'], r['y3'], r['y4']) | |
maxx = max(r['x1'], r['x2'], r['x3'], r['x4']) | |
maxy = max(r['y1'], r['y2'], r['y3'], r['y4']) | |
bbox = [minx, miny, maxx, maxy] | |
# create comma separated string representation of bbox that we will use for the HTTP request to WMS service | |
bbox_str = ','.join([str(el) for el in bbox]) | |
wms_request_parameters['bbox'] = bbox_str | |
print(f'{str(row_num+1).zfill(6)}/{total_rows}', '- godło:', r['godlo'], '- bbox:', bbox) | |
# make the HTTP request | |
response = requests.get(wms_request_base_url, params=wms_request_parameters) | |
if response.ok: | |
# construct dictionary with data parsed from http response using regular expressions | |
for matches in compiled_regexp.findall(response.text): | |
record = {name: value for name, value in zip(attribute_names, matches)} | |
print(record) |
Ok, już widzę. A w jaki sposób sprawdzić i określić jak są ustalane Tilerow i Tilecol? Czy jest sposób na przeliczenie tego z bbox?
Tile row i col to dla WMTS. To trzeba by poczytać jak to się wylicza, ale większość warstw masz też w WMS, w którym wystarczy ci bbox.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adresy usług są na stronie geoportalu: https://www.geoportal.gov.pl/uslugi/usluga-przegladania-wms
Ogólny opis jak się tworzy zapytania do WMS jest całkiem spoko na wiki: https://pl.wikipedia.org/wiki/Web_Map_Service
Najłatwiej to dodać warstwę w QGIS, odpalić panel z podglądem jakie requesty są wysyłane (f12) i skopiować.