Skip to main content
Solved

how to create line string from json point array


f.kemminje
Contributor
Forum|alt.badge.img+11

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.

Best answer by david_r

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

View original
Did this help you find an answer to your question?

4 replies

david_r
Celebrity
  • Best Answer
  • June 29, 2017

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


david_r
Celebrity
  • June 29, 2017
david_r wrote:

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! :-)

f.kemminje
Contributor
Forum|alt.badge.img+11
  • Author
  • Contributor
  • June 30, 2017

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


    

david_r
Celebrity
  • June 30, 2017
f.kemminje wrote:

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.

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings