OpenLayers OpenLayers

Changeset 4070

Show
Ignore:
Timestamp:
08/28/07 11:06:12 (1 year ago)
Author:
crschmidt
Message:

Write more tests for the GML Format. This has highlighted two bugs:

  • We don't parse multipoint or multilinestring correctly.
  • PostGIS doesn't export correct Polygon GML via as GML.

I'm about to start working on the first, and I'll report the latter
soon.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/tschaub/xml/tests/Format/test_GML.html

    r4043 r4070  
    3535        t.eq(data[0].geometry.getBounds().toBBOX(), "-1254041.389712,250906.951598,-634517.119991,762236.29408", "Reading 3d content returns geometry with correct bounds (no 0,0)"); 
    3636        t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Reading 3d content returns polygon geometry"); 
     37    }    
     38    function test_Format_GML_read_point_geom(t) { 
     39        t.plan(3); 
     40         
     41        var point = shell_start + geoms['point'] + shell_end; 
     42        var parser = new OpenLayers.Format.GML(); 
     43        data = parser.read(point); 
     44        t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Point", "Point GML returns correct classname"); 
     45        t.eq(data[0].geometry.x, 1, "x coord correct"); 
     46        t.eq(data[0].geometry.y, 2, "y coord correct"); 
    3747    }     
     48    function test_Format_GML_read_linestring_geom(t) { 
     49        t.plan(5); 
     50         
     51        var line = shell_start + geoms['linestring'] + shell_end; 
     52        var parser = new OpenLayers.Format.GML(); 
     53        data = parser.read(line); 
     54        t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.LineString", "LineString GML returns correct classname"); 
     55        t.eq(data[0].geometry.components[0].x, 1, "first x coord correct"); 
     56        t.eq(data[0].geometry.components[0].y, 2, "first y coord correct"); 
     57        t.eq(data[0].geometry.components[1].x, 4, "second x coord correct"); 
     58        t.eq(data[0].geometry.components[1].y, 5, "second y coord correct"); 
     59    }     
     60    function test_Format_GML_read_polygon_geom(t) { 
     61        t.plan(7); 
     62         
     63        var polygon = shell_start + geoms['polygon'] + shell_end; 
     64        var parser = new OpenLayers.Format.GML(); 
     65        data = parser.read(polygon); 
     66        t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Polygon GML returns correct classname"); 
     67        t.eq(data[0].geometry.components[0].components[0].x, 1, "first x coord correct"); 
     68        t.eq(data[0].geometry.components[0].components[0].y, 2, "first y coord correct"); 
     69        t.eq(data[0].geometry.components[0].components[1].x, 4, "second x coord correct"); 
     70        t.eq(data[0].geometry.components[0].components[1].y, 5, "second y coord correct"); 
     71        t.eq(data[0].geometry.components[0].components.length, 4, "coords length correct"); 
     72        t.eq(data[0].geometry.components.length, 1, "rings length correct"); 
     73    }    
     74    function test_Format_GML_read_multipoint_geom(t) { 
     75        t.plan(1); 
     76         
     77        var multipoint = shell_start + geoms['multipoint'] + shell_end; 
     78        var parser = new OpenLayers.Format.GML(); 
     79        data = parser.read(multipoint); 
     80        console.log(data); 
     81        t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.MultiPoint", "MultiPoint GML returns correct classname (GML was: " + multipoint + ")"); 
     82        /* t.eq(data[0].geometry.components[0].x, 1, "x coord correct"); 
     83        t.eq(data[0].geometry.components[0].y, 2, "y coord correct"); 
     84        t.eq(data[0].geometry.components.length, 2, "length correct"); 
     85        t.eq(data[0].geometry.components[1].x, 4, "x coord correct"); 
     86        t.eq(data[0].geometry.components[1].y, 5, "y coord correct"); 
     87        */ 
     88    }     
     89    function test_Format_GML_read_multilinestring_geom(t) { 
     90        t.plan(1); 
     91         
     92        var multilinestring = shell_start + geoms['multipoint'] + shell_end; 
     93        var parser = new OpenLayers.Format.GML(); 
     94        data = parser.read(multilinestring); 
     95        t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.MultiLineString", "MultiLineString GML returns correct classname (GML was: " + multilinestring + ")"); 
     96        /* t.eq(data[0].geometry.components[0].x, 1, "x coord correct"); 
     97        t.eq(data[0].geometry.components[0].y, 2, "y coord correct"); 
     98        t.eq(data[0].geometry.components.length, 2, "length correct"); 
     99        t.eq(data[0].geometry.components[1].x, 4, "x coord correct"); 
     100        t.eq(data[0].geometry.components[1].y, 5, "y coord correct"); 
     101        */ 
     102    }     
     103    /* 
     104    function test_Format_GML_read_polygon_with_holes_geom(t) { 
     105        t.plan(5); 
     106         
     107        var polygon_with_holes = shell_start + geoms['polygon_with_holes'] + shell_end; 
     108        console.log(polygon_with_holes); 
     109        var parser = new OpenLayers.Format.GML(); 
     110        data = parser.read(polygon_with_holes); 
     111        console.log(data[0].geometry); 
     112        t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Polygon GML returns correct classname"); 
     113        t.eq(data[0].geometry.components[0].components[0].x, 1, "first x coord correct"); 
     114        t.eq(data[0].geometry.components[0].components[0].y, 2, "first y coord correct"); 
     115        t.eq(data[0].geometry.components[0].components[1].x, 4, "second x coord correct"); 
     116        t.eq(data[0].geometry.components[0].components[1].y, 5, "second y coord correct"); 
     117        t.eq(data[0].geometry.components[0].components.length, 4, "coords length correct"); 
     118        t.eq(data[0].geometry.components[1].components[0].x, 11, "first x coord correct"); 
     119        t.eq(data[0].geometry.components[1].components[0].y, 12, "first y coord correct"); 
     120        t.eq(data[0].geometry.components[1].components[1].x, 14, "second x coord correct"); 
     121        t.eq(data[0].geometry.components[1].components[1].y, 15, "second y coord correct"); 
     122        t.eq(data[0].geometry.components[1].components.length, 4, "coords length correct"); 
     123        t.eq(data[0].geometry.components.length, 2, "rings length correct"); 
     124    } */     
    38125    function test_Format_GML_read_attributes(t) { 
    39126        t.plan(1); 
    40127        var parser = new OpenLayers.Format.GML(); 
    41128        data = parser.read(test_content[0]); 
    42         console.log(data[0].attributes); 
    43129        t.eq(data[0].attributes['NAME'], "WY", "Simple Attribute data is read correctly."); 
    44130    }     
     
    70156 ' <gml:featureMember><fs:scribble fid="8">    <fs:geometry>        <gml:Point><gml:coordinates>-81.38671875,27.0703125</gml:coordinates></gml:Point>         </fs:geometry> ' + 
    71157 '        <fs:down>south</fs:down><fs:title>Florida</fs:title>        </fs:scribble></gml:featureMember>' +  
    72  '</wfs:FeatureCollection>'] 
     158 '</wfs:FeatureCollection>'  
     159 ] 
     160    
     161        var shell_start =  '<wfs:FeatureCollection' +  
     162 '   xmlns:fs="http://example.com/featureserver"' +  
     163 '   xmlns:wfs="http://www.opengis.net/wfs"' +  
     164 '   xmlns:gml="http://www.opengis.net/gml"' +  
     165 '   xmlns:ogc="http://www.opengis.net/ogc"' +  
     166 '   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +  
     167 '   xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengeospatial.net//wfs/1.0.0/WFS-basic.xsd">' +  
     168 '        ' +  
     169 '' +  
     170 '        <gml:featureMember>' +  
     171 '  \n<fs:scribble fid="221">' +  
     172 '        <fs:geometry>'; 
     173        var shell_end = '  </fs:geometry>  </fs:scribble></gml:featureMember>' +  
     174 '</wfs:FeatureCollection>'; 
     175 var geoms = { 
     176   'point':'<gml:Point><gml:coordinates>1,2,3</gml:coordinates></gml:Point>', 
     177   'linestring':'<gml:LineString><gml:coordinates>4,2,3 4,5,6</gml:coordinates></gml:LineString>', 
     178   'polygon':'<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1,2 4,5 3,6 1,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>', 
     179   //'polygon_with_holes':'<gml:Polygon><gml:outerBoundaryIs>1,2 4,5 3,6 1,2</gml:outerBoundaryIs><gml:innerBoundaryIs>11,12 14,15 13,16 11,12</gml:innerBoundaryIs></gml:Polygon>', 
     180   'multipoint':'<gml:MultiPoint><gml:Point><gml:coordinates>1,2,3</gml:coordinates></gml:Point><gml:Point><gml:coordinates>4,5,6</gml:coordinates></gml:Point></gml:MultiPoint>', 
     181   'multilinestring':'<gml:MultiLineString><gml:LineString><gml:coordinates>1,2,3 4,5,6</gml:coordinates></gml:LineString><gml:LineString><gml:coordinates>11,12,13 14,15,16</gml:coordinates></gml:LineString></gml:MultiLineString>' // , 
     182   // 'multipolygon_with_holes': '<gml:MultiPolygon><gml:Polygon><gml:outerBoundaryIs>1,2 4,5 3,6 1,2</gml:outerBoundaryIs><gml:innerBoundaryIs>11,12 14,15 13,16 11,12</gml:innerBoundaryIs></gml:Polygon><gml:Polygon><gml:outerBoundaryIs>101,102 104,105 103,106 101,102</gml:outerBoundaryIs><gml:innerBoundaryIs>111,112 114,115 113,116 111,112</gml:innerBoundaryIs></gml:Polygon></gml:MultiPolygon>' 
     183   } 
    73184        </script>  
    74185</head>