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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
|
<html>
<head>
<script src="../../OLLoader.js"></script>
<script type="text/javascript">
function test_read(t) {
t.plan(1);
var data = readXML("FeatureCollection");
var format = new OpenLayers.Format.WFST({
featureNS: "http://www.openplans.org/topp",
featureType: "states"
});
var features = format.read(data);
t.eq(features.length, 1, "number of features read from FeatureCollection is correct");
}
function test_write(t) {
var format = new OpenLayers.Format.WFST({
featureNS: "http://www.openplans.org/topp",
featureType: "states",
featurePrefix: "topp",
geometryName: "the_geom"
});
var feature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(1,2),
{foo: "bar"}
);
var insertFeature = feature.clone();
// null value does not show up in insert
insertFeature.attributes.nul = null;
insertFeature.state = OpenLayers.State.INSERT;
var updateFeature = feature.clone();
// undefined value means don't create a Property element
updateFeature.attributes.unwritten = undefined;
// null value gets Property element with no Value
updateFeature.attributes.nul = null;
updateFeature.fid = "fid.42";
updateFeature.state = OpenLayers.State.UPDATE;
var deleteFeature = feature.clone();
deleteFeature.state = OpenLayers.State.DELETE;
deleteFeature.fid = "fid.37";
t.plan(8);
var snippets = {
"GetFeature": {handle: "handle_g", maxFeatures: 1, outputFormat: 'json'},
"Transaction": {handle: "handle_t"},
"Insert": {feature: insertFeature, options: {handle: "handle_i"}},
"Update": {feature: updateFeature, options: {handle: "handle_u"}},
"Delete": {feature: deleteFeature, options: {handle: "handle_d"}}
}
var arg;
for(var snippet in snippets) {
arg = snippets[snippet]
var expected = readXML(snippet);
var got = format.writers["wfs"][snippet].apply(format, [arg]);
t.xml_eq(got, expected, snippet + " request created correctly");
}
updateFeature.modified = {geometry: updateFeature.geometry.clone()};
updateFeature.geometry = new OpenLayers.Geometry.Point(2,3);
var expected = readXML("UpdateModified");
var got = format.writers["wfs"]["Update"].apply(format, [{feature: updateFeature}]);
t.xml_eq(got, expected, "Update request for feature with modified geometry created correctly");
updateFeature.modified.attributes = {foo: "bar"};
updateFeature.attributes.foo = "baz";
delete updateFeature.modified.geometry;
var expected = readXML("UpdateModifiedNoGeometry");
var got = format.writers["wfs"]["Update"].apply(format, [{feature: updateFeature}]);
t.xml_eq(got, expected, "Update request for feature with no modified geometry but modified attributes created correctly");
// test for a feature that originally had a null geometry and a null value for the attribute
updateFeature.modified = {attributes: {foo: null, nul: "nul"}, geometry: null};
updateFeature.attributes.foo = "bar";
updateFeature.geometry = new OpenLayers.Geometry.Point(2,3);
var expected = readXML("UpdateModified");
var got = format.writers["wfs"]["Update"].apply(format, [{feature: updateFeature}]);
t.xml_eq(got, expected, "Update request for feature with modified geometry created correctly even if original geometry was null");
}
function test_writeNative(t) {
t.plan(1);
var format = new OpenLayers.Format.WFST({
featureNS: "http://www.openplans.org/topp",
featureType: "states",
version: "1.1.0",
featurePrefix: "topp",
geometryName: null
});
var output = format.write(null, {nativeElements: [
{
vendorId: "ORACLE",
safeToIgnore: true,
value: "ALTER SESSION ENABLE PARALLEL DML"
}, {
vendorId: "ORACLE",
safeToIgnore: false,
value: "Another native line goes here"
}]
});
var expected = '<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><wfs:Native vendorId="ORACLE" safeToIgnore="true">ALTER SESSION ENABLE PARALLEL DML</wfs:Native><wfs:Native vendorId="ORACLE" safeToIgnore="false">Another native line goes here</wfs:Native></wfs:Transaction>';
t.xml_eq(output, expected, "Native elements written out correctly");
}
function test_write_no_geometry(t) {
var format = new OpenLayers.Format.WFST({
featureNS: "http://www.openplans.org/topp",
featureType: "states",
featurePrefix: "topp",
geometryName: null
});
var feature = new OpenLayers.Feature.Vector(null, {foo: "bar"});
feature.state = OpenLayers.State.UPDATE;
feature.fid = "fid.36";
t.plan(1);
var snippets = {
"UpdateNoGeometry": {feature: feature}
}
var arg;
for(var snippet in snippets) {
arg = snippets[snippet]
var expected = readXML(snippet);
var got = format.writers["wfs"]["Update"].apply(format, [arg]);
t.xml_eq(got, expected, snippet + " request without geometry created correctly");
}
}
function test_setFilterProperty(t) {
t.plan(2);
var format = new OpenLayers.Format.WFST({
geometryName: "foo"
});
var filter = new OpenLayers.Filter.Logical({
type: OpenLayers.Filter.Logical.AND,
filters: [new OpenLayers.Filter.Spatial({
type: OpenLayers.Filter.Spatial.BBOX,
value: new OpenLayers.Bounds(1,2,3,4)
}), new OpenLayers.Filter.Spatial({
type: OpenLayers.Filter.Spatial.DWITHIN,
property: "bar",
value: new OpenLayers.Geometry.Point(1,2),
distance: 10
})]
});
format.setFilterProperty(filter);
t.eq(filter.filters[0].property, "foo", "property set if not set on filter");
t.eq(filter.filters[1].property, "bar", "property not set if set on filter");
}
function test_update_null_geometry(t) {
var format = new OpenLayers.Format.WFST({
featureNS: "http://www.openplans.org/topp",
featureType: "states",
featurePrefix: "topp",
geometryName: "the_geom"
});
var feature = new OpenLayers.Feature.Vector(null, {foo: "bar"});
feature.state = OpenLayers.State.UPDATE;
feature.fid = "fid.36";
t.plan(1);
var snippets = {
"UpdateNullGeometry": {feature: feature}
};
var arg;
for (var snippet in snippets) {
arg = snippets[snippet]
var expected = readXML(snippet);
var got = format.writers["wfs"]["Update"].apply(format, [arg]);
t.xml_eq(got, expected, snippet + " request with null geometry created correctly");
}
}
function test_write_multiple(t) {
var format = new OpenLayers.Format.WFST({
featureNS: "http://www.openplans.org/topp",
featureType: ["states", "cities"],
featurePrefix: "topp",
geometryName: "the_geom"
});
t.plan(1);
var snippets = {
"GetFeatureMultiple": {}
}
var arg;
for(var snippet in snippets) {
arg = snippets[snippet]
var expected = readXML(snippet);
var got = format.writers["wfs"]["GetFeature"].apply(format, [arg]);
t.xml_eq(got, expected, snippet + " request created correctly with multiple typenames");
}
}
function test_write_multi(t) {
t.plan(2);
var format = new OpenLayers.Format.WFST({
featureNS: "http://www.openplans.org/topp",
featureType: "states",
featurePrefix: "topp",
geometryName: "the_geom"
});
var feature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(1,2),
{foo: "bar"}
);
var insertFeature = feature.clone();
// null value does not show up in insert
insertFeature.attributes.nul = null;
insertFeature.state = OpenLayers.State.INSERT;
var updateFeature = feature.clone();
// undefined value means don't create a Property element
updateFeature.attributes.unwritten = undefined;
// null value gets Property element with no Value
updateFeature.attributes.nul = null;
updateFeature.fid = "fid.42";
updateFeature.state = OpenLayers.State.UPDATE;
var features = [insertFeature, updateFeature];
var expected = readXML("TransactionMulti");
var geomTypes = OpenLayers.Util.extend({}, format.geometryTypes);
var got = format.writers["wfs"]["Transaction"].apply(format, [{
features: features,
options: {multi: true}}
]);
t.xml_eq(got, expected, "Transaction request with multi option created correctly");
t.eq(format.geometryTypes, geomTypes, "geometry types unchanged after write with multi option");
}
function readXML(id) {
var xml = document.getElementById(id).firstChild.nodeValue;
return new OpenLayers.Format.XML().read(xml).documentElement;
}
</script>
</head>
<body>
<div id="map" style="width:512px; height:256px"> </div>
<div id="FeatureCollection"><!--
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:gml="http://www.opengis.net/gml">
<gml:featureMember>
<topp:states fid="states.3">
<topp:the_geom>
<gml:MultiPolygon srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:polygonMember>
<gml:Polygon>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates decimal="." cs="," ts=" ">-75.70742,38.557476 -75.71106,38.649551 -75.724937,38.83017 -75.752922,39.141548 -75.761658,39.247753 -75.764664,39.295849 -75.772697,39.383007 -75.791435,39.723755 -75.775269,39.724442 -75.745934,39.774818 -75.695114,39.820347 -75.644341,39.838196 -75.583794,39.840008 -75.470345,39.826435 -75.42083,39.79887 -75.412117,39.789658 -75.428009,39.77813 -75.460754,39.763248 -75.475128,39.741718 -75.476334,39.719971 -75.489639,39.714745 -75.610725,39.612793 -75.562996,39.566723 -75.590187,39.463768 -75.515572,39.36694 -75.402481,39.257637 -75.397728,39.073036 -75.324852,39.012386 -75.307899,38.945911 -75.190941,38.80867 -75.083138,38.799812 -75.045998,38.44949 -75.068298,38.449963 -75.093094,38.450451 -75.350204,38.455208 -75.69915,38.463066 -75.70742,38.557476</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</gml:polygonMember>
</gml:MultiPolygon>
</topp:the_geom>
<topp:STATE_NAME>Delaware</topp:STATE_NAME>
<topp:STATE_FIPS>10</topp:STATE_FIPS>
<topp:SUB_REGION>S Atl</topp:SUB_REGION>
<topp:STATE_ABBR>DE</topp:STATE_ABBR>
<topp:LAND_KM>5062.456</topp:LAND_KM>
<topp:WATER_KM>1385.022</topp:WATER_KM>
<topp:PERSONS>666168.0</topp:PERSONS>
<topp:FAMILIES>175867.0</topp:FAMILIES>
<topp:HOUSHOLD>247497.0</topp:HOUSHOLD>
<topp:MALE>322968.0</topp:MALE>
<topp:FEMALE>343200.0</topp:FEMALE>
<topp:WORKERS>247566.0</topp:WORKERS>
<topp:DRVALONE>258087.0</topp:DRVALONE>
<topp:CARPOOL>42968.0</topp:CARPOOL>
<topp:PUBTRANS>8069.0</topp:PUBTRANS>
<topp:EMPLOYED>335147.0</topp:EMPLOYED>
<topp:UNEMPLOY>13945.0</topp:UNEMPLOY>
<topp:SERVICE>87973.0</topp:SERVICE>
<topp:MANUAL>44140.0</topp:MANUAL>
<topp:P_MALE>0.485</topp:P_MALE>
<topp:P_FEMALE>0.515</topp:P_FEMALE>
<topp:SAMP_POP>102776.0</topp:SAMP_POP>
</topp:states>
</gml:featureMember>
</wfs:FeatureCollection>
--></div>
<div id="GetFeature"><!--
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" handle="handle_g" outputFormat="json" maxFeatures="1" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:Query typeName="topp:states" xmlns:topp="http://www.openplans.org/topp"/>
</wfs:GetFeature>
--></div>
<div id="GetFeatureMultiple"><!--
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:Query typeName="topp:states" xmlns:topp="http://www.openplans.org/topp"/>
<wfs:Query typeName="topp:cities" xmlns:topp="http://www.openplans.org/topp"/>
</wfs:GetFeature>
--></div>
<div id="Transaction"><!--
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0"/>
--></div>
<div id="TransactionMulti"><!--
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0">
<wfs:Insert>
<feature:states xmlns:feature="http://www.openplans.org/topp">
<feature:the_geom>
<gml:MultiPoint xmlns:gml="http://www.opengis.net/gml">
<gml:pointMember>
<gml:Point>
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
</gml:Point>
</gml:pointMember>
</gml:MultiPoint>
</feature:the_geom>
<feature:foo>bar</feature:foo>
</feature:states>
</wfs:Insert>
<wfs:Update xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
<wfs:Property>
<wfs:Name>the_geom</wfs:Name>
<wfs:Value>
<gml:MultiPoint xmlns:gml="http://www.opengis.net/gml">
<gml:pointMember>
<gml:Point>
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
</gml:Point>
</gml:pointMember>
</gml:MultiPoint>
</wfs:Value>
</wfs:Property>
<wfs:Property>
<wfs:Name>foo</wfs:Name>
<wfs:Value>bar</wfs:Value>
</wfs:Property>
<wfs:Property>
<wfs:Name>nul</wfs:Name>
</wfs:Property>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:FeatureId fid="fid.42"/>
</ogc:Filter>
</wfs:Update>
</wfs:Transaction>
--></div>
<div id="Insert"><!--
<wfs:Insert xmlns:wfs="http://www.opengis.net/wfs" handle="handle_i">
<feature:states xmlns:feature="http://www.openplans.org/topp">
<feature:the_geom>
<gml:Point xmlns:gml="http://www.opengis.net/gml">
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
</gml:Point>
</feature:the_geom>
<feature:foo>bar</feature:foo>
</feature:states>
</wfs:Insert>
--></div>
<div id="Update"><!--
<wfs:Update xmlns:wfs="http://www.opengis.net/wfs" handle="handle_u" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
<wfs:Property>
<wfs:Name>the_geom</wfs:Name>
<wfs:Value>
<gml:Point xmlns:gml="http://www.opengis.net/gml">
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
</gml:Point>
</wfs:Value>
</wfs:Property>
<wfs:Property>
<wfs:Name>foo</wfs:Name>
<wfs:Value>bar</wfs:Value>
</wfs:Property>
<wfs:Property>
<wfs:Name>nul</wfs:Name>
</wfs:Property>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:FeatureId fid="fid.42"/>
</ogc:Filter>
</wfs:Update>
--></div>
<div id="UpdateModified"><!--
<wfs:Update xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
<wfs:Property>
<wfs:Name>the_geom</wfs:Name>
<wfs:Value>
<gml:Point xmlns:gml="http://www.opengis.net/gml">
<gml:coordinates decimal="." cs="," ts=" ">2,3</gml:coordinates>
</gml:Point>
</wfs:Value>
</wfs:Property>
<wfs:Property>
<wfs:Name>foo</wfs:Name>
<wfs:Value>bar</wfs:Value>
</wfs:Property>
<wfs:Property>
<wfs:Name>nul</wfs:Name>
</wfs:Property>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:FeatureId fid="fid.42"/>
</ogc:Filter>
</wfs:Update>
--></div>
<div id="UpdateModifiedNoGeometry"><!--
<wfs:Update xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
<wfs:Property>
<wfs:Name>foo</wfs:Name>
<wfs:Value>baz</wfs:Value>
</wfs:Property>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:FeatureId fid="fid.42"/>
</ogc:Filter>
</wfs:Update>
--></div>
<div id="Delete"><!--
<wfs:Delete xmlns:wfs="http://www.opengis.net/wfs" handle="handle_d" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:FeatureId fid="fid.37"/>
</ogc:Filter>
</wfs:Delete>
--></div>
<div id="UpdateNoGeometry"><!--
<wfs:Update xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
<wfs:Property>
<wfs:Name>foo</wfs:Name>
<wfs:Value>bar</wfs:Value>
</wfs:Property>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:FeatureId fid="fid.36"/>
</ogc:Filter>
</wfs:Update>
--></div>
<div id="UpdateNullGeometry"><!--
<wfs:Update xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
<wfs:Property>
<wfs:Name>the_geom</wfs:Name>
</wfs:Property>
<wfs:Property>
<wfs:Name>foo</wfs:Name>
<wfs:Value>bar</wfs:Value>
</wfs:Property>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:FeatureId fid="fid.36"/>
</ogc:Filter>
</wfs:Update>
--></div>
</body>
</html>
|