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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229 | 1×
1×
1×
1×
1×
1×
1×
1×
1×
19×
19×
19×
19×
1×
1×
1×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
25×
117×
117×
117×
117×
33×
84×
25×
1×
13×
13×
13×
13×
1×
3×
3×
3×
3×
3×
3×
3×
3×
1×
7×
7×
7×
7×
7×
7×
7×
7×
1×
1×
1×
1×
| goog.provide('ol.format.GML2');
goog.require('goog.asserts');
goog.require('goog.dom.NodeType');
goog.require('ol.extent');
goog.require('ol.format.GMLBase');
goog.require('ol.format.XSD');
goog.require('ol.proj');
goog.require('ol.xml');
/**
* @classdesc
* Feature format for reading and writing data in the GML format,
* version 2.1.2.
*
* @constructor
* @param {olx.format.GMLOptions=} opt_options Optional configuration object.
* @extends {ol.format.GMLBase}
* @api
*/
ol.format.GML2 = function(opt_options) {
var options = /** @type {olx.format.GMLOptions} */
(opt_options ? opt_options : {});
goog.base(this, options);
this.FEATURE_COLLECTION_PARSERS[ol.format.GMLBase.GMLNS][
'featureMember'] =
ol.xml.makeArrayPusher(ol.format.GMLBase.prototype.readFeaturesInternal);
/**
* @inheritDoc
*/
this.schemaLocation = options.schemaLocation ?
options.schemaLocation : ol.format.GML2.schemaLocation_;
};
goog.inherits(ol.format.GML2, ol.format.GMLBase);
/**
* @const
* @type {string}
* @private
*/
ol.format.GML2.schemaLocation_ = ol.format.GMLBase.GMLNS +
' http://schemas.opengis.net/gml/2.1.2/feature.xsd';
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
* @return {Array.<number>|undefined} Flat coordinates.
*/
ol.format.GML2.prototype.readFlatCoordinates_ = function(node, objectStack) {
var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
var context = objectStack[0];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var containerSrs = context['srsName'];
var containerDimension = node.parentNode.getAttribute('srsDimension');
var axisOrientation = 'enu';
Eif (containerSrs) {
var proj = ol.proj.get(containerSrs);
axisOrientation = proj.getAxisOrientation();
}
var coords = s.split(/[\s,]+/);
// The "dimension" attribute is from the GML 3.0.1 spec.
var dim = 2;
Iif (node.getAttribute('srsDimension')) {
dim = ol.format.XSD.readNonNegativeIntegerString(
node.getAttribute('srsDimension'));
} else Iif (node.getAttribute('dimension')) {
dim = ol.format.XSD.readNonNegativeIntegerString(
node.getAttribute('dimension'));
} else Iif (containerDimension) {
dim = ol.format.XSD.readNonNegativeIntegerString(containerDimension);
}
var x, y, z;
var flatCoordinates = [];
for (var i = 0, ii = coords.length; i < ii; i += dim) {
x = parseFloat(coords[i]);
y = parseFloat(coords[i + 1]);
z = (dim === 3) ? parseFloat(coords[i + 2]) : 0;
if (axisOrientation.substr(0, 2) === 'en') {
flatCoordinates.push(x, y, z);
} else {
flatCoordinates.push(y, x, z);
}
}
return flatCoordinates;
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
* @return {ol.Extent|undefined} Envelope.
*/
ol.format.GML2.prototype.readBox_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'Box', 'localName should be Box');
var flatCoordinates = ol.xml.pushParseAndPop(
/** @type {Array.<number>} */ ([null]),
this.BOX_PARSERS_, node, objectStack, this);
return ol.extent.createOrUpdate(flatCoordinates[1][0],
flatCoordinates[1][1], flatCoordinates[1][3],
flatCoordinates[1][4]);
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
*/
ol.format.GML2.prototype.innerBoundaryIsParser_ =
function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'innerBoundaryIs',
'localName should be innerBoundaryIs');
var flatLinearRing = ol.xml.pushParseAndPop(
/** @type {Array.<number>|undefined} */ (undefined),
this.RING_PARSERS, node, objectStack, this);
Eif (flatLinearRing) {
var flatLinearRings = /** @type {Array.<Array.<number>>} */
(objectStack[objectStack.length - 1]);
goog.asserts.assert(goog.isArray(flatLinearRings),
'flatLinearRings should be an array');
goog.asserts.assert(flatLinearRings.length > 0,
'flatLinearRings should have an array length larger than 0');
flatLinearRings.push(flatLinearRing);
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
*/
ol.format.GML2.prototype.outerBoundaryIsParser_ =
function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'outerBoundaryIs',
'localName should be outerBoundaryIs');
var flatLinearRing = ol.xml.pushParseAndPop(
/** @type {Array.<number>|undefined} */ (undefined),
this.RING_PARSERS, node, objectStack, this);
Eif (flatLinearRing) {
var flatLinearRings = /** @type {Array.<Array.<number>>} */
(objectStack[objectStack.length - 1]);
goog.asserts.assert(goog.isArray(flatLinearRings),
'flatLinearRings should be an array');
goog.asserts.assert(flatLinearRings.length > 0,
'flatLinearRings should have an array length larger than 0');
flatLinearRings[0] = flatLinearRing;
}
};
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = Object({
'http://www.opengis.net/gml' : {
'coordinates': ol.xml.makeReplacer(
ol.format.GML2.prototype.readFlatCoordinates_)
}
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GML2.prototype.FLAT_LINEAR_RINGS_PARSERS_ = Object({
'http://www.opengis.net/gml' : {
'innerBoundaryIs': ol.format.GML2.prototype.innerBoundaryIsParser_,
'outerBoundaryIs': ol.format.GML2.prototype.outerBoundaryIsParser_
}
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GML2.prototype.BOX_PARSERS_ = Object({
'http://www.opengis.net/gml' : {
'coordinates': ol.xml.makeArrayPusher(
ol.format.GML2.prototype.readFlatCoordinates_)
}
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GML2.prototype.GEOMETRY_PARSERS_ = Object({
'http://www.opengis.net/gml' : {
'Point': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPoint),
'MultiPoint': ol.xml.makeReplacer(
ol.format.GMLBase.prototype.readMultiPoint),
'LineString': ol.xml.makeReplacer(
ol.format.GMLBase.prototype.readLineString),
'MultiLineString': ol.xml.makeReplacer(
ol.format.GMLBase.prototype.readMultiLineString),
'LinearRing' : ol.xml.makeReplacer(
ol.format.GMLBase.prototype.readLinearRing),
'Polygon': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPolygon),
'MultiPolygon': ol.xml.makeReplacer(
ol.format.GMLBase.prototype.readMultiPolygon),
'Box': ol.xml.makeReplacer(ol.format.GML2.prototype.readBox_)
}
});
|