Skip to content

Instantly share code, notes, and snippets.

@fpsampayo
Created February 15, 2018 11:40
Show Gist options
  • Save fpsampayo/6be7235efa9ac8b35ea2ceebec9d1dfe to your computer and use it in GitHub Desktop.
Save fpsampayo/6be7235efa9ac8b35ea2ceebec9d1dfe to your computer and use it in GitHub Desktop.
Catastro INSPIRE desde GDAL/OGR
from osgeo import gdal, ogr, osr

url = 'http://ovc.catastro.meh.es/INSPIRE/wfsCP.aspx?service=wfs&version=2&request=getfeature&STOREDQUERIE_ID=GetParcel&srsname=EPSG:4326&REFCAT=%s'

wfs_drv = ogr.GetDriverByName('WFS')
wfs_ds = wfs_drv.Open('WFS:' + url % refcat)

layer = wfs_ds.GetLayerByName('cp:CadastralParcel')
feat = layer.GetFeature(0)
geom = feat.GetGeometryRef()

# Realizamos transformación para invertir los ejes
source = osr.SpatialReference()
source.ImportFromProj4('+proj=latlong +datum=WGS84 +axis=neu +wktext')

target = osr.SpatialReference()
target.ImportFromProj4('+proj=latlong +datum=WGS84 +axis=enu +wktext')

transform = osr.CoordinateTransformation(source, target)

geom.Transform(transform)

# Obtenemos atributos o geometría
area = feat['areaValue']
geomJson = geom.ExportToJson()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment