| | 176 | /////////////////////////////////////////////////////////////// |
|---|
| | 177 | // tests the y x order of gml point |
|---|
| | 178 | ///////////////////////////////////////////////////////////// |
|---|
| | 179 | function test_Format_GML_read_point_geom_yx(t) { |
|---|
| | 180 | t.plan(3); |
|---|
| | 181 | |
|---|
| | 182 | var point = shell_start + geoms_yx['point'] + shell_end; |
|---|
| | 183 | var parser = new OpenLayers.Format.GML({'xy':false}); |
|---|
| | 184 | data = parser.read(point); |
|---|
| | 185 | t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Point", "Point GML returns correct classname"); |
|---|
| | 186 | t.eq(data[0].geometry.x, 1, "x coord correct"); |
|---|
| | 187 | t.eq(data[0].geometry.y, 2, "y coord correct"); |
|---|
| | 188 | } |
|---|
| | 189 | function test_Format_GML_read_linestring_geom_yx(t) { |
|---|
| | 190 | t.plan(5); |
|---|
| | 191 | |
|---|
| | 192 | var line = shell_start + geoms_yx['linestring'] + shell_end; |
|---|
| | 193 | var parser = new OpenLayers.Format.GML({'xy':false}); |
|---|
| | 194 | data = parser.read(line); |
|---|
| | 195 | t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.LineString", "LineString GML returns correct classname"); |
|---|
| | 196 | t.eq(data[0].geometry.components[0].x, 1, "first x coord correct"); |
|---|
| | 197 | t.eq(data[0].geometry.components[0].y, 2, "first y coord correct"); |
|---|
| | 198 | t.eq(data[0].geometry.components[1].x, 4, "second x coord correct"); |
|---|
| | 199 | t.eq(data[0].geometry.components[1].y, 5, "second y coord correct"); |
|---|
| | 200 | } |
|---|
| | 201 | function test_Format_GML_read_polygon_geom_yx(t) { |
|---|
| | 202 | t.plan(7); |
|---|
| | 203 | |
|---|
| | 204 | var polygon = shell_start + geoms_yx['polygon'] + shell_end; |
|---|
| | 205 | var parser = new OpenLayers.Format.GML({'xy':false}); |
|---|
| | 206 | data = parser.read(polygon); |
|---|
| | 207 | t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Polygon GML returns correct classname"); |
|---|
| | 208 | t.eq(data[0].geometry.components[0].components[0].x, 1, "first x coord correct"); |
|---|
| | 209 | t.eq(data[0].geometry.components[0].components[0].y, 2, "first y coord correct"); |
|---|
| | 210 | t.eq(data[0].geometry.components[0].components[1].x, 4, "second x coord correct"); |
|---|
| | 211 | t.eq(data[0].geometry.components[0].components[1].y, 5, "second y coord correct"); |
|---|
| | 212 | t.eq(data[0].geometry.components[0].components.length, 4, "coords length correct"); |
|---|
| | 213 | t.eq(data[0].geometry.components.length, 1, "rings length correct"); |
|---|
| | 214 | } |
|---|
| | 215 | function test_Format_GML_read_multipoint_geom_yx(t) { |
|---|
| | 216 | t.plan(6); |
|---|
| | 217 | |
|---|
| | 218 | var multipoint = shell_start + geoms_yx['multipoint'] + shell_end; |
|---|
| | 219 | var parser = new OpenLayers.Format.GML({'xy':false}); |
|---|
| | 220 | data = parser.read(multipoint); |
|---|
| | 221 | t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.MultiPoint", "MultiPoint GML returns correct classname"); |
|---|
| | 222 | t.eq(data[0].geometry.components[0].x, 1, "x coord correct"); |
|---|
| | 223 | t.eq(data[0].geometry.components[0].y, 2, "y coord correct"); |
|---|
| | 224 | t.eq(data[0].geometry.components.length, 2, "length correct"); |
|---|
| | 225 | t.eq(data[0].geometry.components[1].x, 4, "x coord correct"); |
|---|
| | 226 | t.eq(data[0].geometry.components[1].y, 5, "y coord correct"); |
|---|
| | 227 | } |
|---|
| | 228 | function test_Format_GML_read_multilinestring_geom_yx(t) { |
|---|
| | 229 | t.plan(6); |
|---|
| | 230 | |
|---|
| | 231 | var multilinestring = shell_start + geoms_yx['multilinestring'] + shell_end; |
|---|
| | 232 | var parser = new OpenLayers.Format.GML({'xy':false}); |
|---|
| | 233 | data = parser.read(multilinestring); |
|---|
| | 234 | t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.MultiLineString", "MultiLineString GML returns correct classname"); |
|---|
| | 235 | t.eq(data[0].geometry.components[0].components[0].x, 1, "x coord correct"); |
|---|
| | 236 | t.eq(data[0].geometry.components[0].components[0].y, 2, "y coord correct"); |
|---|
| | 237 | t.eq(data[0].geometry.components[0].components.length, 2, "length correct"); |
|---|
| | 238 | t.eq(data[0].geometry.components[0].components[1].x, 4, "x coord correct"); |
|---|
| | 239 | t.eq(data[0].geometry.components[0].components[1].y, 5, "y coord correct"); |
|---|
| | 240 | |
|---|
| | 241 | } |
|---|
| | 242 | function test_Format_GML_read_polygon_with_holes_geom_yx(t) { |
|---|
| | 243 | t.plan(12); |
|---|
| | 244 | |
|---|
| | 245 | var polygon_with_holes = shell_start + geoms_yx['polygon_with_holes'] + shell_end; |
|---|
| | 246 | var parser = new OpenLayers.Format.GML({'xy':false}); |
|---|
| | 247 | data = parser.read(polygon_with_holes); |
|---|
| | 248 | t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Polygon GML returns correct classname"); |
|---|
| | 249 | t.eq(data[0].geometry.components[0].components[0].x, 1, "first x coord correct"); |
|---|
| | 250 | t.eq(data[0].geometry.components[0].components[0].y, 2, "first y coord correct"); |
|---|
| | 251 | t.eq(data[0].geometry.components[0].components[1].x, 4, "second x coord correct"); |
|---|
| | 252 | t.eq(data[0].geometry.components[0].components[1].y, 5, "second y coord correct"); |
|---|
| | 253 | t.eq(data[0].geometry.components[0].components.length, 4, "coords length correct"); |
|---|
| | 254 | t.eq(data[0].geometry.components[1].components[0].x, 11, "first x coord correct"); |
|---|
| | 255 | t.eq(data[0].geometry.components[1].components[0].y, 12, "first y coord correct"); |
|---|
| | 256 | t.eq(data[0].geometry.components[1].components[1].x, 14, "second x coord correct"); |
|---|
| | 257 | t.eq(data[0].geometry.components[1].components[1].y, 15, "second y coord correct"); |
|---|
| | 258 | t.eq(data[0].geometry.components[1].components.length, 4, "coords length correct"); |
|---|
| | 259 | t.eq(data[0].geometry.components.length, 2, "rings length correct"); |
|---|
| | 260 | } |
|---|
| | 261 | |
|---|
| | 262 | function test_Format_GML_read_envelope_geom_yx(t) { |
|---|
| | 263 | t.plan(13); |
|---|
| | 264 | |
|---|
| | 265 | var envelope = shell_start + geoms_yx['envelope'] + shell_end; |
|---|
| | 266 | var parser = new OpenLayers.Format.GML({'xy':false}); |
|---|
| | 267 | data = parser.read(envelope); |
|---|
| | 268 | t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Envelope GML returns correct classname"); |
|---|
| | 269 | t.eq(data[0].geometry.components[0].components[0].x, 0, "first x coord correct"); |
|---|
| | 270 | t.eq(data[0].geometry.components[0].components[0].y, 1, "first y coord correct"); |
|---|
| | 271 | t.eq(data[0].geometry.components[0].components[1].x, 20, "second x coord correct"); |
|---|
| | 272 | t.eq(data[0].geometry.components[0].components[1].y, 1, "second y coord correct"); |
|---|
| | 273 | t.eq(data[0].geometry.components[0].components[2].x, 20, "third x coord correct"); |
|---|
| | 274 | t.eq(data[0].geometry.components[0].components[2].y, 21, "third y coord correct"); |
|---|
| | 275 | t.eq(data[0].geometry.components[0].components[3].x, 0, "fouth x coord correct"); |
|---|
| | 276 | t.eq(data[0].geometry.components[0].components[3].y, 21, "fourth y coord correct"); |
|---|
| | 277 | t.eq(data[0].geometry.components[0].components[4].x, 0, "fifth x coord correct"); |
|---|
| | 278 | t.eq(data[0].geometry.components[0].components[4].y, 1, "fifth y coord correct"); |
|---|
| | 279 | t.eq(data[0].geometry.components[0].components.length, 5, "coords length correct"); |
|---|
| | 280 | t.eq(data[0].geometry.components.length, 1, "rings length correct"); |
|---|
| | 281 | } |
|---|
| | 282 | |
|---|
| | 283 | function test_Format_GML_write_geoms_yx(t) { |
|---|
| | 284 | t.plan(5); |
|---|
| | 285 | var parser = new OpenLayers.Format.GML({'xy':false}); |
|---|
| | 286 | |
|---|
| | 287 | var point_xy = shell_start + serialize_geoms['point'] + shell_end; |
|---|
| | 288 | var point = shell_start + serialize_geoms_yx['point'] + shell_end; |
|---|
| | 289 | data = parser.read(point); |
|---|
| | 290 | var output = parser.write(data); |
|---|
| | 291 | t.eq(output, point_xy, "Point geometry round trips correctly."); |
|---|
| | 292 | |
|---|
| | 293 | var linestring_xy = shell_start + serialize_geoms['linestring'] + shell_end; |
|---|
| | 294 | var linestring = shell_start + serialize_geoms_yx['linestring'] + shell_end; |
|---|
| | 295 | data = parser.read(linestring); |
|---|
| | 296 | var output = parser.write(data); |
|---|
| | 297 | t.eq(output, linestring_xy, "Line geometry round trips correctly."); |
|---|
| | 298 | |
|---|
| | 299 | var polygon_xy = shell_start + serialize_geoms['polygon'] + shell_end; |
|---|
| | 300 | var polygon = shell_start + serialize_geoms_yx['polygon'] + shell_end; |
|---|
| | 301 | data = parser.read(polygon); |
|---|
| | 302 | var output = parser.write(data); |
|---|
| | 303 | t.eq(output, polygon_xy, "Poly geometry round trips correctly."); |
|---|
| | 304 | |
|---|
| | 305 | var multipoint_xy = shell_start + serialize_geoms['multipoint'] + shell_end; |
|---|
| | 306 | var multipoint = shell_start + serialize_geoms_yx['multipoint'] + shell_end; |
|---|
| | 307 | data = parser.read(multipoint); |
|---|
| | 308 | var output = parser.write(data); |
|---|
| | 309 | t.eq(output, multipoint_xy, "MultiPoint geometry round trips correctly."); |
|---|
| | 310 | |
|---|
| | 311 | var multilinestring_xy = shell_start + serialize_geoms['multilinestring'] + shell_end; |
|---|
| | 312 | var multilinestring = shell_start + serialize_geoms_yx['multilinestring'] + shell_end; |
|---|
| | 313 | data = parser.read(multilinestring); |
|---|
| | 314 | var output = parser.write(data); |
|---|
| | 315 | t.eq(output, multilinestring_xy, "MultiLine geometry round trips correctly."); |
|---|
| | 316 | } |
|---|
| | 317 | |
|---|
| | 367 | |
|---|
| | 368 | |
|---|
| | 369 | // |
|---|
| | 370 | // The following data has the (x y) reordered to (y x), in 3 dimensions it goes from (x y z) to (y x z) |
|---|
| | 371 | // |
|---|
| | 372 | |
|---|
| | 373 | var serialize_geoms_yx = { |
|---|
| | 374 | 'point': '<gml:Point><gml:coordinates decimal="." cs="," ts=" ">2,1</gml:coordinates></gml:Point>', |
|---|
| | 375 | 'linestring': '<gml:LineString><gml:coordinates decimal="." cs="," ts=" ">2,1 5,4</gml:coordinates></gml:LineString>', |
|---|
| | 376 | 'polygon': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates decimal="." cs="," ts=" ">2,1 5,4 6,3 2,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>', |
|---|
| | 377 | 'multipoint': '<gml:MultiPoint><gml:pointMember><gml:Point><gml:coordinates decimal="." cs="," ts=" ">2,1</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates decimal="." cs="," ts=" ">5,4</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint>', |
|---|
| | 378 | 'multilinestring': '<gml:MultiLineString><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">2,1 5,4</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">12,11 15,14</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString>' |
|---|
| | 379 | }; |
|---|
| | 380 | var geoms_yx = { |
|---|
| | 381 | 'point': '<gml:Point><gml:coordinates>2,1,3</gml:coordinates></gml:Point>', |
|---|
| | 382 | 'linestring': '<gml:LineString><gml:coordinates>2,1,3 5,4,6</gml:coordinates></gml:LineString>', |
|---|
| | 383 | 'polygon': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,1 5,4 6,3 2,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>', |
|---|
| | 384 | 'polygon_with_holes': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,1 5,4 6,3 2,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>12,11 15,14 16,13 12,11</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon>', |
|---|
| | 385 | 'multipoint': '<gml:MultiPoint><gml:Point><gml:coordinates>2,1,3</gml:coordinates></gml:Point><gml:Point><gml:coordinates>5,4,6</gml:coordinates></gml:Point></gml:MultiPoint>', |
|---|
| | 386 | 'multilinestring': '<gml:MultiLineString><gml:LineString><gml:coordinates>2,1,3 5,4,6</gml:coordinates></gml:LineString><gml:LineString><gml:coordinates>12,11,13 15,14,16</gml:coordinates></gml:LineString></gml:MultiLineString>', |
|---|
| | 387 | 'envelope': '<gml:Envelope><gml:lowerCorner>1 0</gml:lowerCorner><gml:upperCorner>21 20</gml:upperCorner></gml:Envelope>' |
|---|
| | 388 | }; |
|---|
| | 389 | |
|---|