Last active
March 17, 2024 14:58
-
-
Save pigreco/86589dddf5a59b3a7650267d5af237bd to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
""" | |
/*************************************************************************** | |
WMS Catasto Agenzia delle Entrate CC BY 4.0 | |
------------------- | |
copyright : (C) 2020 by Giulio Fattori | |
email : [email protected] | |
***************************************************************************/ | |
""" | |
from qgis.core import * | |
from qgis.gui import * | |
import requests | |
@qgsfunction(args='auto', group='Custom') | |
def get_parcel_info2(xx, yy, EPSG, feature, parent): | |
""" | |
<h1>WMS Catasto Agenzia delle Entrate CC BY 4.0:</h1><br> | |
La funzione, tramite una richiesta GetFeatureInfo, restituisce le informazioni utili sulla particella che ricade sotto il pixel di mio interesse: | |
<h2>Esempio:</h2> | |
<ul> | |
<li>get_parcel_info(355461.5,4222490.7,'EPSG:3045') -> 'IT.AGE.PLA.G273_0033A0.673'</li> | |
<li>get_parcel_info("fieldX", "fieldY",'EPSG:3045') -> 'IT.AGE.PLA.G273_0033A0.673'</li> | |
<li>get_parcel_info("fieldX", "fieldY",@project_crs) -> 'IT.AGE.PLA.G273_0033A0.673'</li> | |
</ul> | |
<h2>NB: le coordinate X e Y devono essere espresse nel EPSG utilizzato (gli EPSG disponibili sono:6706,4258,25832/3/4,3044/5/6)</h2> | |
""" | |
req = "https://wms.cartografia.agenziaentrate.gov.it/inspire/wms/ows01.php?REQUEST=GetFeatureInfo&SERVICE=WMS&SRS="+EPSG+"&STYLES=&VERSION=1.1&FORMAT=image/png&BBOX="+str(xx-1)+","+str(yy-1)+","+str(xx+1)+","+str(yy+1)+"&HEIGHT=9&WIDTH=9&LAYERS=CP.CadastralParcel&QUERY_LAYERS=CP.CadastralParcel&INFO_FORMAT=text/html&X=5&Y=5" | |
r = requests.get(req, auth=('user', 'pass')) | |
a = r.text.partition("InspireId localId</th><td>")[2] | |
b = a.partition("</td>")[0] | |
return b |
Si potrebbe usare un'unica regex fatta così:
codice: regexp_matches( "catasto" ,'^(.+).(.+).(.+).(.{4})(.)(.+).(.+)')[3]
sezione: regexp_matches( "catasto" ,'^(.+).(.+).(.+).(.{4})(.)(.+).(.+)')[4]
foglio: regexp_matches( "catasto" ,'^(.+).(.+).(.+).(.{4})(.)(.+).(.+)')[5]
particella: regexp_matches( "catasto" ,'^(.+).(.+).(.+).(.{4})(.)(.+).(.+)')[6]
quasi, suggerirei così:
regexp_matches( "catasto" ,'^(.+)\\.(.+)\\.(.+)\\.(.+)_(.+)\\.(.+)$')[x]
con x
che varia da 0 a 5
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
### Si potrebbe usare un'unica regex fatta così:
codice: regexp_matches( "catasto" ,'^(.+)\.(.+)\.(.+)\.(.{4})(.)(.+)\.(.+)')[3]
sezione: regexp_matches( "catasto" ,'^(.+)\.(.+)\.(.+)\.(.{4})(.)(.+)\.(.+)')[4]
foglio: regexp_matches( "catasto" ,'^(.+)\.(.+)\.(.+)\.(.{4})(.)(.+)\.(.+)')[5]
particella: regexp_matches( "catasto" ,'^(.+)\.(.+)\.(.+)\.(.{4})(.)(.+)\.(.+)')[6]