2

I would like to read multiple features with ol.format.WKT. In the documentation, it says that the function readFeatures takes an array as parameter. I tried the following:

let wkt = new ol.format.WKT;
wkt.readFeatures(["POINT(-378147.31208516686 599021.3516006605)", "POINT(-378300.01500700554 599159.7386235767)"]);

But I get an error :

Uncaught Error: Unexpected `` at position 0 in ``
    at Tu (ol.js:659)
    at Ku.k.Gd (ol.js:655)
    at Ku.k.Ng (ol.js:655)
    at Ku.k.Qa (ol.js:562)
    at <anonymous>:1:5

Has anyone any clue ? I tried searching on the internet but no exemples are available for this specific method, and there are none either in the documentation...

EDIT The function doesn't takes an Array as parameter but a string or an Object (if I red well). What are the syntaxes to use those inputs ? I had no success so far with GEOMETRYCOLLECTION string (see below).

3

The doc is a bit misleading, as it means you can read a geometry collection or multi points. It does not mean you can read several distinct wkt in a single read. Moreover it says that the output is an array, not the input.

You can check the tests to get working examples (it is always a good resource to check when the doc doesn't suffice).

wkt = 'GEOMETRYCOLLECTION(POINT(1 2),POINT(3 4))';
features = format.readFeatures(wkt);

wkt = 'MULTIPOINT((10 40),(40 30),(20 20),(30 10))';
geom = format.readGeometry(wkt);

So an option would be to loop through your inputs and add the features to the vector layer

  • Ow yes lmy bad for the array input i'm still new to those docs. Thanks for the tests link but I tried their way with the GEOMETRYCOLLECTION. I just copy pasted the lines and all I get is a 1 entry array with type GeometryCollection as output... – Clement Jul 6 '18 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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