Question

Check JSON Coordinates For Correct Order

  • 29 November 2022
  • 4 replies
  • 3 views

Badge

I have JSON files that I am reading and using GeometryFilter to create points. GeometryFilter is looking for the coordinates as long, lat. Some of the points in the JSON input are incorecly entered as lat,long. Is there are way to read the JSON coordinates and switch the coordinates to long, lat if they are incorrectly set to lat,long? For example:

CHANGE FROM

"geometry":{

        "type":"Point",

        "coordinates":[ 29.32991754843333 , -82.16997782090549]

TO

"geometry":{

        "type":"Point",

        "coordinates":[ -82.16997782090549, 29.32991754843333 ]

Thanks,

David


4 replies

Userlevel 4
Badge +25

If your data is always in the same general area (and that area is not anywhere near a line running from -90,-90 to 0,0 to 90,90) then yes.

 

After the points are created you can use a CoordinateExtractor to read the coordinate values into attributes, say _x and _y, then a TestFilter to see if they're in the wrong order. Using your values as an example, a test to see if _x is larger than _y should suffice. If they are in the wrong order, you can use a VertexCreator to replace the point with a new one, where you swap the x and y coordinate attributes.

Userlevel 3
Badge +26

Is your input data always confined to a specific area? My first thought is to create a polygon in which all points should fall into. Use the Clipper to determine which have the correct coordinates, and which don't. Those that don't, create new points with reversed values in a VertexCreator.

 

The fact that they are both have valid coordinates makes it a little more challenging to identify which are incorrect. If the coordinates were 29.3299, -110.1699, it would be easier.🙂

Badge

If your data is always in the same general area (and that area is not anywhere near a line running from -90,-90 to 0,0 to 90,90) then yes.

 

After the points are created you can use a CoordinateExtractor to read the coordinate values into attributes, say _x and _y, then a TestFilter to see if they're in the wrong order. Using your values as an example, a test to see if _x is larger than _y should suffice. If they are in the wrong order, you can use a VertexCreator to replace the point with a new one, where you swap the x and y coordinate attributes.

Thank you for your reply. Both responses seem like they could work. I will give them a try.

Badge

Is your input data always confined to a specific area? My first thought is to create a polygon in which all points should fall into. Use the Clipper to determine which have the correct coordinates, and which don't. Those that don't, create new points with reversed values in a VertexCreator.

 

The fact that they are both have valid coordinates makes it a little more challenging to identify which are incorrect. If the coordinates were 29.3299, -110.1699, it would be easier.🙂

Thank you for your reply. Both responses seem like they could work. I will give them a try.

Reply