-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_gml.py
110 lines (108 loc) · 7.05 KB
/
generate_gml.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# -*- coding: utf-8 -*-
"""
"""
#TODO documentation
def genereteCadastreGMLFile(path, epsg, muniCode, plotNum, plotRef, centroid_xy, min_xy, max_xy, area, date, vertex_count, vertex_list):
# Writes the file itself (pretty much a file with a few variables that change)
with open(path, 'w+') as f:
f.write(u'<?xml version="1.0" encoding="utf-8"?>\n')
f.write(u'<!-- Archivo generado automaticamente por el plugin Export GML catastro de España de QGIS. -->\n'.encode('utf8', 'replace'))
f.write(u'<!-- Parcela Catastral de la D.G. del Catastro. -->\n')
f.write(u'<gml:FeatureCollection gml:id="ES.SDGC.CP" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:cp="urn:x-inspire:specification:gmlas:CadastralParcels:3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:x-inspire:specification:gmlas:CadastralParcels:3.0 http://inspire.ec.europa.eu/schemas/cp/3.0/CadastralParcels.xsd">\n')
f.write(u'<gml:featureMember>\n')
f.write(u'<cp:CadastralParcel gml:id="ES.SDGC.CP.' + plotRef + u'">\n')
f.write(u'<gml:boundedBy>\n')
f.write(u'<gml:Envelope srsName="urn:ogc:def:crs:EPSG::' + epsg + u'">\n')
f.write(u' <gml:lowerCorner>' + min_xy + u'</gml:lowerCorner>\n')
f.write(u' <gml:upperCorner>' + max_xy + u'</gml:upperCorner>\n')
f.write(u'</gml:Envelope>\n')
f.write(u'</gml:boundedBy>\n')
f.write(u'<cp:areaValue uom="m2">' + area + u'</cp:areaValue>\n')
f.write(u'<cp:beginLifespanVersion>' + date + u'T00:00:00</cp:beginLifespanVersion>\n')
f.write(u'<cp:endLifespanVersion xsi:nil="true" nilReason="other:unpopulated"></cp:endLifespanVersion>\n')
f.write(u'<cp:geometry>\n')
f.write(u'<gml:MultiSurface gml:id="MultiSurface_ES.SDGC.CP.' + plotRef + u'" srsName="urn:ogc:def:crs:EPSG::' + epsg + u'">\n')
f.write(u' <gml:surfaceMember>\n')
f.write(u' <gml:Surface gml:id="Surface_ES.SDGC.CP.' + plotRef + u'.1" srsName="urn:ogc:def:crs:EPSG::' + epsg + u'">\n')
f.write(u' <gml:patches>\n')
f.write(u' <gml:PolygonPatch>\n')
f.write(u' <gml:exterior>\n')
f.write(u' <gml:LinearRing>\n')
f.write(u' <gml:posList srsDimension="2" count="' + vertex_count + u'">' + vertex_list + u'</gml:posList>\n')
f.write(u' </gml:LinearRing>\n')
f.write(u' </gml:exterior>\n')
f.write(u' </gml:PolygonPatch>\n')
f.write(u' </gml:patches>\n')
f.write(u' </gml:Surface>\n')
f.write(u' </gml:surfaceMember>\n')
f.write(u'</gml:MultiSurface>\n')
f.write(u'</cp:geometry>\n')
f.write(u'<cp:inspireId xmlns:base="urn:x-inspire:specification:gmlas:BaseTypes:3.2">\n')
f.write(u'<base:Identifier>\n')
f.write(u' <base:localId>' + plotNum + u'</base:localId>\n')
f.write(u' <base:namespace>ES.LOCAL.CP</base:namespace>\n')
f.write(u'</base:Identifier>\n')
f.write(u'</cp:inspireId>\n')
f.write(u'<cp:label>05</cp:label>\n')
f.write(u'<cp:nationalCadastralReference>2</cp:nationalCadastralReference>\n')
f.write(u'<cp:referencePoint>\n')
f.write(u'<gml:Point gml:id="ReferencePoint_ES.SDGC.CP.' + plotRef + u'" srsName="urn:ogc:def:crs:EPSG::' + epsg + u'">\n')
f.write(u' <gml:pos>' + centroid_xy + u'</gml:pos>\n')
f.write(u'</gml:Point>\n')
f.write(u'</cp:referencePoint>\n')
f.write(u'<cp:validFrom xsi:nil="true" nilReason="other:unpopulated"></cp:validFrom>\n')
f.write(u'<cp:validTo xsi:nil="true" nilReason="other:unpopulated"></cp:validTo>\n')
f.write(u'<cp:zoning xlink:href="#ES.SDGC.CP.Z.' + muniCode + u'U"></cp:zoning>\n')
f.write(u'</cp:CadastralParcel>\n')
f.write(u'</gml:featureMember>\n')
f.write(u'<gml:featureMember>\n')
f.write(u'<cp:CadastralZoning gml:id="ES.SDGC.CP.Z.' + muniCode + u'U">\n')
f.write(u'<gml:boundedBy>\n')
f.write(u'<gml:Envelope srsName="urn:ogc:def:crs:EPSG::' + epsg + u'">\n')
f.write(u'<gml:lowerCorner>' + min_xy + u'</gml:lowerCorner>\n')
f.write(u'<gml:upperCorner>' + max_xy + u'</gml:upperCorner>\n')
f.write(u'</gml:Envelope>\n')
f.write(u'</gml:boundedBy>\n')
f.write(u'<cp:beginLifespanVersion>' + date + u'T00:00:00</cp:beginLifespanVersion>\n')
f.write(u'<cp:endLifespanVersion xsi:nil="true" nilReason="other:unpopulated"></cp:endLifespanVersion>\n')
f.write(u'<cp:estimatedAccuracy uom="m">0.60</cp:estimatedAccuracy>\n')
f.write(u'<cp:geometry>\n')
f.write(u'<gml:MultiSurface gml:id="MultiSurface_ES.SDGC.CP.Z.' + muniCode + u'U" srsName="urn:ogc:def:crs:EPSG::' + epsg + u'">\n')
f.write(u'<gml:surfaceMember>\n')
f.write(u'<gml:Surface gml:id="Surface_ES.SDGC.CP.Z.' + muniCode + u'U.1" srsName="urn:ogc:def:crs:EPSG::' + epsg + u'">\n')
f.write(u'<gml:patches>\n')
f.write(u'<gml:PolygonPatch>\n')
f.write(u'<gml:exterior>\n')
f.write(u'<gml:LinearRing>\n')
f.write(u'<gml:posList srsDimension="2" count="' + vertex_count + u'">' + vertex_list + u'</gml:posList>\n')
f.write(u'</gml:LinearRing>\n')
f.write(u'</gml:exterior>\n')
f.write(u'</gml:PolygonPatch>\n')
f.write(u'</gml:patches>\n')
f.write(u'</gml:Surface>\n')
f.write(u'</gml:surfaceMember>\n')
f.write(u'</gml:MultiSurface>\n')
f.write(u'</cp:geometry>\n')
f.write(u'<cp:inspireId xmlns:base="urn:x-inspire:specification:gmlas:BaseTypes:3.2">\n')
f.write(u'<base:Identifier>\n')
f.write(u'<base:localId>' + muniCode + u'U</base:localId>\n')
f.write(u'<base:namespace>ES.SDGC.CP.Z</base:namespace>\n')
f.write(u'</base:Identifier>\n')
f.write(u'</cp:inspireId>\n')
f.write(u'<cp:label>' + muniCode + u'U</cp:label>\n')
f.write(u'<cp:level codeSpace="urn:x-inspire:specification:gmlas:CadastralParcels:3.0/CadastralZoningLevelValue">1stOrder</cp:level>\n')
f.write(u'<cp:levelName>\n')
f.write(u'<gmd:LocalisedCharacterString locale="esp">MAPA</gmd:LocalisedCharacterString>\n')
f.write(u'</cp:levelName>\n')
f.write(u'<cp:nationalCadastalZoningReference>' + muniCode + u'U</cp:nationalCadastalZoningReference>\n')
f.write(u'<cp:originalMapScaleDenominator>1000</cp:originalMapScaleDenominator>\n')
f.write(u'<cp:referencePoint>\n')
f.write(u'<gml:Point gml:id="ReferencePoint_ES.SDGC.CP.Z.X' + muniCode + u'U" srsName="urn:ogc:def:crs:EPSG::' + epsg + u'"> \n')
f.write(u'<gml:pos>' + centroid_xy + u'</gml:pos>\n')
f.write(u'</gml:Point>\n')
f.write(u'</cp:referencePoint>\n')
f.write(u'<cp:validFrom xsi:nil="true" nilReason="unknown" />\n')
f.write(u'<cp:validTo xsi:nil="true" nilReason="unknown" />\n')
f.write(u'</cp:CadastralZoning>\n')
f.write(u'</gml:featureMember>\n')
f.write(u'</gml:FeatureCollection>\n')