Solved

how to create line string from json point array

  • 29 June 2017
  • 4 replies
  • 39 views

Badge +3

Hi team.

I extracted json from http caller. extracted json file attached. json.txt.

in this json there are array of points. the path of these points is. ucan see these points after "paths"

(text string)

routes{0}.routeOptions{0}.optionAttributes.spatialReference.geometry.paths{0}.array{0}.array{0} routes{0}.routeOptions{0}.optionAttributes.spatialReference.geometry.paths{0}.array{0}.array{1} routes{0}.routeOptions{0}.optionAttributes.spatialReference.geometry.paths{0}.array{0}.array{2} routes{0}.routeOptions{0}.optionAttributes.spatialReference.geometry.paths{0}.array{1}.array{0} routes{0}.routeOptions{0}.optionAttributes.spatialReference.geometry.paths{0}.array{1}.array{1} routes{0}.routeOptions{0}.optionAttributes.spatialReference.geometry.paths{0}.array{1}.array{2} routes{0}.routeOptions{0}.optionAttributes.spatialReference.geometry.paths{0}.array{2}.array{0} routes{0}.routeOptions{0}.optionAttributes.spatialReference.geometry.paths{0}.array{2}.array{1} routes{0}.routeOptions{0}.optionAttributes.spatialReference.geometry.paths{0}.array{2}.array{2}

here

array{0}.array{0} =x coordinate

array{0}.array{1} =y coordinate

array{0}.array{2} =z coordinate.

using xy cordinate value i want to create a line vertexes using point connector.

But i am not able to extract the array of coordinates from json .

Please help me. I have attached my fmw file.

icon

Best answer by david_r 29 June 2017, 13:09

View original

4 replies

Userlevel 5

Try the following JSON query in the JSONExtractor:

json["routes"][0]["routeOptions"][0]["optionAttributes"]["spatialReference"]["geometry"]

Then use a GeometryReplacer on the resulting JSON object with geometry type "ESRI JSON". I also suspect you'll want to use a GeometryRefiner and the ElevationToMeasureCopier (from the FME Hub) followed by a 2DForcer to move the Z-values to M-values on the resulting geometry. 

You can find the JSON query documentation for FME here:

http://docs.safe.com/fme/2017.0/html/FME_Desktop_Documentation/FME_Transformers/Transformers/jsonfragmenter.htm#JSON_Queries

I can also recommend this site where you can construct your JSON query string online while getting live results:

http://www.jsonquerytool.com/#/JavaScript

Userlevel 5

Try the following JSON query in the JSONExtractor:

json["routes"][0]["routeOptions"][0]["optionAttributes"]["spatialReference"]["geometry"]

Then use a GeometryReplacer on the resulting JSON object with geometry type "ESRI JSON". I also suspect you'll want to use a GeometryRefiner and the ElevationToMeasureCopier (from the FME Hub) followed by a 2DForcer to move the Z-values to M-values on the resulting geometry. 

You can find the JSON query documentation for FME here:

http://docs.safe.com/fme/2017.0/html/FME_Desktop_Documentation/FME_Transformers/Transformers/jsonfragmenter.htm#JSON_Queries

I can also recommend this site where you can construct your JSON query string online while getting live results:

http://www.jsonquerytool.com/#/JavaScript

Btw, thanks for giving us such a clear and reproducible case to work with! :-)
Badge +3

Thanks David.

I used below python code(iteration thru points)

then list exploder

vertex creator

point connector

this is the long process

i will replace yours now.

you are Genius.

import fme
import fmeobjects
import math


def frq(feature):
    a=0
    b=0
    while True:
        ol=feature.getAttribute("routes{0}.routeOptions{0}.optionAttributes.spatialReference.geometry.paths{0}.array{"+ str(a)+"}.array{"+str(b)+"}")
        if ol is None:
            break
        feature.setAttribute("_list{%d}.x" % a, str(ol))
        b += 1
        print ol
        ol=feature.getAttribute("routes{0}.routeOptions{0}.optionAttributes.spatialReference.geometry.paths{0}.array{"+ str(a)+"}.array{"+str(b)+"}")
        if ol is None:
            break
        print ol
        feature.setAttribute("_list{%d}.y" % a, str(ol))
        b =0
        a += 1


    
Userlevel 5

Thanks David.

I used below python code(iteration thru points)

then list exploder

vertex creator

point connector

this is the long process

i will replace yours now.

you are Genius.

import fme
import fmeobjects
import math


def frq(feature):
    a=0
    b=0
    while True:
        ol=feature.getAttribute("routes{0}.routeOptions{0}.optionAttributes.spatialReference.geometry.paths{0}.array{"+ str(a)+"}.array{"+str(b)+"}")
        if ol is None:
            break
        feature.setAttribute("_list{%d}.x" % a, str(ol))
        b += 1
        print ol
        ol=feature.getAttribute("routes{0}.routeOptions{0}.optionAttributes.spatialReference.geometry.paths{0}.array{"+ str(a)+"}.array{"+str(b)+"}")
        if ol is None:
            break
        print ol
        feature.setAttribute("_list{%d}.y" % a, str(ol))
        b =0
        a += 1


    
Not a genius at all, just a long time user :-) Glad I could help.

Reply