Q&A - Question

Load a TGIS_LayerJSON

Question
GiuC asked on December 08, 2016, keyword: Developer Kernel
Hello,

I was wondering if it was possible to load a TGIS_LayerJSON directly from a string, as I haven't found any methods that allow to do this. I noticed this is possible directly from a text file. Is that the only way? Would I previously need to save the JSON string to a file?

My context is a web api for which a post command with a geoJSON string in the body, so having a way to load it directly from the string would be useful.

Thanks in advance.
Answers
Artur Redzko (TatukGIS) replied November 10, 2016
Just assign the Path property with valid context. Examples :

lvjson := TGIS_LayerJSON.Create ;

// load from file
lvjson.Path := 'myfile.json' ;

// load from web
lvjson.Path := 'http://server.com/markers.geojson' ;

// load from string
lvjson.Path := '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"name":"Street"},"geometry":{"coordinates":[-74,40],"type":"Point"},"id":"1"}]}' ;

// load from stream
lvjson.Path := '' ;
lvjson.Stream := myStreamObj ;

lvjson.Open ;
GiuC replied November 10, 2016
Ah great, it's as simple as setting the Path property value to the GeoJSON string.

Thank you!
GiuC replied November 22, 2016
Btw, the "load from string" version works well with the DK-VCL (I use version 10.41), but doesn't seem to work with DK-NET. I tested it with 3 versions: 10.34, 10.49 and 11. The exception is "System.ArgumentException : Illegal characters in path".
Artur Redzko (TatukGIS) replied December 08, 2016
Thanks. Fixed.
If you would like to answer the question please Sign In.
*
*
Please review our recent Privacy Policy.
If you have any questions or requests, please contact us.
Rules
The Questions and Answers (Q & A) is intended to provide a means of communication between TatukGIS customers.
 
  1. Licensed users (with active maintenance play) of TatukGIS products may contribute to the Q & A content. Read-only access is available to anyone.
  2. Keep the content positive and professional.
  3. Be courteous to others by posting information when a question or issue asked on the Q & A is answered or resolved by other means (such as with help from TatukGIS technical support). Offer others at least a hint how the posted question was answered or the issue was resolved.
  4. The Q & A is not a replacement for TatukGIS technical support. TatukGIS team may or may not regularly follow or contribute content.