skip to Main Content

So I have geo Coordinates and I want to create polygon string that i can insert into Postgres as geometry type. I am using apache Nifi.

Input:

[
  [
    13,
    52
  ],
  [
    13,
    55
  ],
  [
    14,
    15
  ]
]

Expected Output:

POLYGON((13 52, 13 55, 14 15))

I tried with below JOLT but no luck:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[&1].[&0]"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "*": "=join(' ',@(1,&))"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=concat('POLYGON((',@(1,2),'))')"
    }
  }
]

2

Answers


  1. You can convert the current one to this :

    [
      { // form independent arrays with keys of indexes taken from the outermost array
        "operation": "shift",
        "spec": {
          "*": {
            "*": "&1"
          }
        }
      },
      { // stringify those arrays
        "operation": "modify-overwrite-beta",
        "spec": {
          "*": "=join(' ',@(1,&))"
        }
      },
      { // generate an array namely "Coord"
        "operation": "shift",
        "spec": {
          "*": {
            "@": "Coord"
          }
        }
      },
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "Coord": "=join(' ,',@(1,&))",
          "*": "=concat('POLYGON((',@(1,&),'))')"
        }
      }
    ]
    

    the demo on the site https://jolt-demo.appspot.com/ is :

    enter image description here

    Login or Signup to reply.
  2. Using a jolt expression to merge a 2D array is like optimizing code for efficiency. Just as we streamline processes in programming, let’s also ensure our daily life runs smoothly – like managing online bills with ease. Here’s to the precision of coding and the convenience of online utility management!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search