Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a partial GML object with the geometry type polygon. The GML version must be 3+ since the coordinates are wrapped in the gml:posList tag:

<gml:Polygon srsName="EPSG:25832" xmlns:gml="http://www.opengis.net/gml">  
     <gml:exterior>  
         <gml:LinearRing srsName="EPSG:25832">  
             <gml:posList>
                 N points where N is an even integer.
             </gml:posList>  
         </gml:LinearRing>  
     </gml:exterior> 
</gml:Polygon>

I am using OpenLayers 2.10 and I am trying to convert the GML object into an OpenLayers feature using the OpenLayers.Format.GML class.

When executing the parseFeature method, which later calls the parseGeometry.linestring I encounter this comment:

/**
* Two coordinate variations to consider:
* 1) <gml:posList dimension="d">x0 y0 z0 x1 y1 z1</gml:posList>
* 2) <gml:coordinates>x0, y0, z0 x1, y1, z1</gml:coordinates>
*/

And this line of code which assumes the dimension attribute to be present:

var dim = parseInt(nodeList[0].getAttribute("dimension")); 

In OpenLayers.Format.GML.v3 the same line of code looks like this:

var dim = parseInt(node.getAttribute("dimension")) || 2;

The problematic difference for me is the || 2 part which assumes that a missing dimension means 2 dimensional - which is what I want. Then why not use the v3 edition, but the OpenLayers.Format.GML.v3 does not implement the parseFeature method.

I am recieving GML features from various services and I do not control them.

What is the best approach to handle this problem?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

After a quick glance it looks like the v2 and v3 JS files derive from base (definitely makes sense too) which offers a read method. Try checking that out.

See: http://github.com/openlayers/openlayers/blob/2.x/lib/OpenLayers/Format/GML/Base.js#L151

If that is not complete or does not meet your needs you can just modify the source. Given the generous licensing and the nature of JavaScript you could just add it in yourself or better yet create a pull request for that change.

See: http://github.com/openlayers/openlayers/blob/2.x/lib/OpenLayers/Format/GML.js#L348

If you feel the need to hack something messy together you can also add that attribute to the nodes:

setMissingDefaults = function(node){ /* magic stuff */ }
OpenLayers.Format.GML.parseFeature(setMissingDefaults(node));
share|improve this answer
1  
I cannot use the read method, since I don't have the rest of the GML document - it needs the featureMember(s) tag. I could fix it my self, but I am more curious to whether there is a reason for not including the default dimension in the GML.js file. Thanks for your reply! –  Chau Oct 19 '10 at 8:43
    
The standards documents don't make much sense with respect to posList. Old v3 docs define a dimension property as "...the number of entries in the list" while the new version has a count property instead which "specifies the number of direct positions in the list". After reading this all the examples of this tag however have a dimension="2" or 3. My best guess is that srsDimension is supposed to be used on the posList or up the hierarchy instead of dimension on the posList but nobody cared enough to change. Hope somebody else can chime in with some better info and background on it. –  Dandy Oct 19 '10 at 15:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.