[OpenLayers-Dev] What is right format for WKT in OpenLayers (comma white space vs. comma)?

Noli Sicad nsicad at gmail.com
Thu Jun 9 05:41:45 EDT 2011


OK. I would want to debate about the standard.

What need a parser that would be able to parse the comma white space
from Spatialite query in order to render the feature in OpenLayers.

Now, how we are going to modify this example using  str.replace?

~~~~~~~~~~~~~
       function parseWKT() {
            var element = document.getElementById('wkt');


            ???

            var features = wkt.read(element.value);

          ????

            var bounds;
            if(features) {
                if(features.constructor != Array) {
                    features = [features];
                }
                for(var i=0; i<features.length; ++i) {
                    if (!bounds) {
                        bounds = features[i].geometry.getBounds();
                    } else {
                        bounds.extend(features[i].geometry.getBounds());
                    }

                }
                vectors.addFeatures(features);
                map.zoomToExtent(bounds);
                var plural = (features.length > 1) ? 's' : '';
                element.value = 'Feature' + plural + ' added'
            } else {
                element.value = 'Bad WKT';
            }
        }

~~~~~~~~~~

Any ideas?

Noli


On 6/9/11, Trond Michelsen <trondmm-openlayers at crusaders.no> wrote:
> On Thu, Jun 09, 2011 at 06:24:48PM +1000, Noli Sicad wrote:
>> I ask this question a few hours ago about why the comma white space
>> format of my LINESTRING would not work  in Openlayers WKT example and
>> I got the answer that my LINESTRING has wrong format i.e comma white
>> space format.
>
> Well, the official standard says:
> http://www.opengeospatial.org/standards/sfa
>
> <x>           ::= <signed numeric literal>
> <y>           ::= <signed numeric literal>
> <point>       ::= <x> <y>
> <left paren>  ::= (
> <right paren> ::= )
> <comma>       ::= ,
> <space>       ::= " "
> <linestring text> ::= <empty set> | <left paren> <point> {<comma> <point>}*
> <right paren>
>
> So, "space" is not explicitly mentioned to be allowed between the
> comma and the point, but it's not explicitly mentioned between the x
> and y values of the point either.
>
> However, the standard also says:
>
> <decimal point> ::= <period> | <comma>
>
> So, both "5.4" and "5,4" must be accepted. If you omit the space
> behind the comma, it'll be impossible to correctly parse a string like
> this:
>
> linestring(1,2 0,3,5 3,2)
>
> Should this be parsed as
>
> linestring(1.2 0.3, 5 3.2) or linestring(1.2 0, 3.5 3.2)?
>
> So basically, the standard is a bit ambigous. A space in a definition
> is optional or mandatory depending on where you find it.
>
> --
> Trond Michelsen
>


More information about the Dev mailing list