Skip to main content
Tiny adjustments
Source Link
Taras
  • 33.9k
  • 4
  • 73
  • 148

You get NULL while using $x or $y because your geometry is probably either Polylines or Polygons.

So, I will suggest employing this expression to capture coordinates for a multitude of objects at once

map_to_json(
    map(
        'x', array_to_string(array_foreach(generate_series(1, num_points($geometry)), x(point_n($geometry, @element)))),
        'y', array_to_string(array_foreach(generate_series(1, num_points($geometry)), y(point_n($geometry, @element))))
     )
)

So, the result will look as following

{"x":"5395496.429117461,5395494.155999963,5395489.773418307","y":"5659901.713053187,5659897.333999608,5659899.601836967"}
{"x":"5396759.156386755,5396761.318999965,5396764.051999965,5396762.000375618,5396760.367999964,5396755.841312531","y":"5660769.610787445,5660770.32399961,5660769.08599961,5660764.5589490365,5660760.95699961,5660763.009167434"}
{"x":"5397230.945016465,5397230.575999966,5397225.642692687","y":"5660956.466597664,5660951.539999611,5660951.8752865605"}
...

There is also a possibility of using this expression with a different formatting

array_to_string(
               array_foreach(generate_series(1, num_points($geometry)),
                             'Point_'  || @element || ': (' || x(point_n($geometry, @element))|| ', ' || y(point_n($geometry, @element)) || ')'
                )
)

That will lead to this

Point_1: (5395496.429117461, 5659901.713053187),Point_2: (5395494.155999963, 5659897.333999608),Point_3: (5395489.773418307, 5659899.601836967)
Point_1: (5396759.156386755, 5660769.610787445),Point_2: (5396761.318999965, 5660770.32399961),Point_3: (5396764.051999965, 5660769.08599961),Point_4: (5396762.000375618, 5660764.5589490365),Point_5: (5396760.367999964, 5660760.95699961),Point_6: (5396755.841312531, 5660763.009167434)
Point_1: (5397230.945016465, 5660956.466597664),Point_2: (5397230.575999966, 5660951.539999611),Point_3: (5397225.642692687, 5660951.8752865605)
...

Both cases are approachable in the "Field Calculator" via creating a new text(string) field and using those expressions in Expression Dialog.

result

Note: it shall do the work for all geometry types

You get NULL while using $x or $y because your geometry is probably either Polylines or Polygons.

So, I will suggest employing this expression to capture coordinates for a multitude of objects at once

map_to_json(
    map(
        'x', array_to_string(array_foreach(generate_series(1, num_points($geometry)), x(point_n($geometry, @element)))),
        'y', array_to_string(array_foreach(generate_series(1, num_points($geometry)), y(point_n($geometry, @element))))
     )
)

So, the result will look as following

{"x":"5395496.429117461,5395494.155999963,5395489.773418307","y":"5659901.713053187,5659897.333999608,5659899.601836967"}
{"x":"5396759.156386755,5396761.318999965,5396764.051999965,5396762.000375618,5396760.367999964,5396755.841312531","y":"5660769.610787445,5660770.32399961,5660769.08599961,5660764.5589490365,5660760.95699961,5660763.009167434"}
{"x":"5397230.945016465,5397230.575999966,5397225.642692687","y":"5660956.466597664,5660951.539999611,5660951.8752865605"}
...

There is also a possibility of using this expression with a different formatting

array_to_string(
               array_foreach(generate_series(1, num_points($geometry)),
                             'Point_'  || @element || ': (' || x(point_n($geometry, @element))|| ', ' || y(point_n($geometry, @element)) || ')'
                )
)

That will lead to this

Point_1: (5395496.429117461, 5659901.713053187),Point_2: (5395494.155999963, 5659897.333999608),Point_3: (5395489.773418307, 5659899.601836967)
Point_1: (5396759.156386755, 5660769.610787445),Point_2: (5396761.318999965, 5660770.32399961),Point_3: (5396764.051999965, 5660769.08599961),Point_4: (5396762.000375618, 5660764.5589490365),Point_5: (5396760.367999964, 5660760.95699961),Point_6: (5396755.841312531, 5660763.009167434)
Point_1: (5397230.945016465, 5660956.466597664),Point_2: (5397230.575999966, 5660951.539999611),Point_3: (5397225.642692687, 5660951.8752865605)
...

Both cases are approachable in the "Field Calculator" via creating a new text(string) field and using those expressions in Expression Dialog.

Note: it shall do the work for all geometry types

You get NULL while using $x or $y because your geometry is probably either Polylines or Polygons.

So, I will suggest employing this expression to capture coordinates for a multitude of objects at once

map_to_json(
    map(
        'x', array_to_string(array_foreach(generate_series(1, num_points($geometry)), x(point_n($geometry, @element)))),
        'y', array_to_string(array_foreach(generate_series(1, num_points($geometry)), y(point_n($geometry, @element))))
     )
)

So, the result will look as following

{"x":"5395496.429117461,5395494.155999963,5395489.773418307","y":"5659901.713053187,5659897.333999608,5659899.601836967"}
{"x":"5396759.156386755,5396761.318999965,5396764.051999965,5396762.000375618,5396760.367999964,5396755.841312531","y":"5660769.610787445,5660770.32399961,5660769.08599961,5660764.5589490365,5660760.95699961,5660763.009167434"}
{"x":"5397230.945016465,5397230.575999966,5397225.642692687","y":"5660956.466597664,5660951.539999611,5660951.8752865605"}
...

There is also a possibility of using this expression with a different formatting

array_to_string(
               array_foreach(generate_series(1, num_points($geometry)),
                             'Point_'  || @element || ': (' || x(point_n($geometry, @element))|| ', ' || y(point_n($geometry, @element)) || ')'
                )
)

That will lead to this

Point_1: (5395496.429117461, 5659901.713053187),Point_2: (5395494.155999963, 5659897.333999608),Point_3: (5395489.773418307, 5659899.601836967)
Point_1: (5396759.156386755, 5660769.610787445),Point_2: (5396761.318999965, 5660770.32399961),Point_3: (5396764.051999965, 5660769.08599961),Point_4: (5396762.000375618, 5660764.5589490365),Point_5: (5396760.367999964, 5660760.95699961),Point_6: (5396755.841312531, 5660763.009167434)
Point_1: (5397230.945016465, 5660956.466597664),Point_2: (5397230.575999966, 5660951.539999611),Point_3: (5397225.642692687, 5660951.8752865605)
...

Both cases are approachable in the "Field Calculator" via creating a new text(string) field and using those expressions in Expression Dialog.

result

Note: it shall do the work for all geometry types

Tiny adjustments
Source Link
Taras
  • 33.9k
  • 4
  • 73
  • 148

You get NULL while using $x or $y because your geometry is probably either Polylines or Polygons.

So, I will suggest employing this expression to capture coordinates for a multitude of objects at once

map_to_json(
    map(
        'x', array_to_string(array_foreach(generate_series(1, num_points($geometry)), x(point_n($geometry, @element)))),
        'y', array_to_string(array_foreach(generate_series(1, num_points($geometry)), y(point_n($geometry, @element))))
     )
)

So, the result will look as following

{"x":"5395496.429117461,5395494.155999963,5395489.773418307","y":"5659901.713053187,5659897.333999608,5659899.601836967"}
{"x":"5396759.156386755,5396761.318999965,5396764.051999965,5396762.000375618,5396760.367999964,5396755.841312531","y":"5660769.610787445,5660770.32399961,5660769.08599961,5660764.5589490365,5660760.95699961,5660763.009167434"}
{"x":"5397230.945016465,5397230.575999966,5397225.642692687","y":"5660956.466597664,5660951.539999611,5660951.8752865605"}
...

There is also a possibility of using this expression with a different formatting

array_to_string(
               array_foreach(generate_series(1, num_points($geometry)),
                             'Point_'  || @element || ': (' || x(point_n($geometry, @element))|| ', ' || y(point_n($geometry, @element)) || ')'
                )
)

That will lead to this

Point_1: (5395496.429117461, 5659901.713053187),Point_2: (5395494.155999963, 5659897.333999608),Point_3: (5395489.773418307, 5659899.601836967)
Point_1: (5396759.156386755, 5660769.610787445),Point_2: (5396761.318999965, 5660770.32399961),Point_3: (5396764.051999965, 5660769.08599961),Point_4: (5396762.000375618, 5660764.5589490365),Point_5: (5396760.367999964, 5660760.95699961),Point_6: (5396755.841312531, 5660763.009167434)
Point_1: (5397230.945016465, 5660956.466597664),Point_2: (5397230.575999966, 5660951.539999611),Point_3: (5397225.642692687, 5660951.8752865605)
...

Both cases are approachable in the "Field Calculator" via creating a new text(string) field and using those expressions in Expression Dialog.

Note: it shall do the work for all geometry types

You get NULL while using $x or $y because your geometry is probably either Polylines or Polygons.

So, I will suggest employing this expression to capture coordinates for multitude of objects at once

map_to_json(
    map(
        'x', array_to_string(array_foreach(generate_series(1, num_points($geometry)), x(point_n($geometry, @element)))),
        'y', array_to_string(array_foreach(generate_series(1, num_points($geometry)), y(point_n($geometry, @element))))
     )
)

So, the result will look as following

{"x":"5395496.429117461,5395494.155999963,5395489.773418307","y":"5659901.713053187,5659897.333999608,5659899.601836967"}
{"x":"5396759.156386755,5396761.318999965,5396764.051999965,5396762.000375618,5396760.367999964,5396755.841312531","y":"5660769.610787445,5660770.32399961,5660769.08599961,5660764.5589490365,5660760.95699961,5660763.009167434"}
{"x":"5397230.945016465,5397230.575999966,5397225.642692687","y":"5660956.466597664,5660951.539999611,5660951.8752865605"}
...

There is also a possibility using this expression with a different formatting

array_to_string(
               array_foreach(generate_series(1, num_points($geometry)),
                             'Point_'  || @element || ': (' || x(point_n($geometry, @element))|| ', ' || y(point_n($geometry, @element)) || ')'
                )
)

That will lead to this

Point_1: (5395496.429117461, 5659901.713053187),Point_2: (5395494.155999963, 5659897.333999608),Point_3: (5395489.773418307, 5659899.601836967)
Point_1: (5396759.156386755, 5660769.610787445),Point_2: (5396761.318999965, 5660770.32399961),Point_3: (5396764.051999965, 5660769.08599961),Point_4: (5396762.000375618, 5660764.5589490365),Point_5: (5396760.367999964, 5660760.95699961),Point_6: (5396755.841312531, 5660763.009167434)
Point_1: (5397230.945016465, 5660956.466597664),Point_2: (5397230.575999966, 5660951.539999611),Point_3: (5397225.642692687, 5660951.8752865605)
...

Note: it shall do the work for all geometry types

You get NULL while using $x or $y because your geometry is probably either Polylines or Polygons.

So, I will suggest employing this expression to capture coordinates for a multitude of objects at once

map_to_json(
    map(
        'x', array_to_string(array_foreach(generate_series(1, num_points($geometry)), x(point_n($geometry, @element)))),
        'y', array_to_string(array_foreach(generate_series(1, num_points($geometry)), y(point_n($geometry, @element))))
     )
)

So, the result will look as following

{"x":"5395496.429117461,5395494.155999963,5395489.773418307","y":"5659901.713053187,5659897.333999608,5659899.601836967"}
{"x":"5396759.156386755,5396761.318999965,5396764.051999965,5396762.000375618,5396760.367999964,5396755.841312531","y":"5660769.610787445,5660770.32399961,5660769.08599961,5660764.5589490365,5660760.95699961,5660763.009167434"}
{"x":"5397230.945016465,5397230.575999966,5397225.642692687","y":"5660956.466597664,5660951.539999611,5660951.8752865605"}
...

There is also a possibility of using this expression with a different formatting

array_to_string(
               array_foreach(generate_series(1, num_points($geometry)),
                             'Point_'  || @element || ': (' || x(point_n($geometry, @element))|| ', ' || y(point_n($geometry, @element)) || ')'
                )
)

That will lead to this

Point_1: (5395496.429117461, 5659901.713053187),Point_2: (5395494.155999963, 5659897.333999608),Point_3: (5395489.773418307, 5659899.601836967)
Point_1: (5396759.156386755, 5660769.610787445),Point_2: (5396761.318999965, 5660770.32399961),Point_3: (5396764.051999965, 5660769.08599961),Point_4: (5396762.000375618, 5660764.5589490365),Point_5: (5396760.367999964, 5660760.95699961),Point_6: (5396755.841312531, 5660763.009167434)
Point_1: (5397230.945016465, 5660956.466597664),Point_2: (5397230.575999966, 5660951.539999611),Point_3: (5397225.642692687, 5660951.8752865605)
...

Both cases are approachable in the "Field Calculator" via creating a new text(string) field and using those expressions in Expression Dialog.

Note: it shall do the work for all geometry types

deleted 13 characters in body
Source Link
Taras
  • 33.9k
  • 4
  • 73
  • 148

When youYou get NULL while simply using $x$x or $y it probably means that the$y because your geometry is probably either Polylines or Polygons.

So, I will suggest employing this expression to capture coordinates for multitude of objects at once

map_to_json(
    map(
        'x', array_to_string(array_foreach(generate_series(1, num_points($geometry)), x(point_n($geometry, @element)))),
        'y', array_to_string(array_foreach(generate_series(1, num_points($geometry)), y(point_n($geometry, @element))))
     )
)

So, the result will look as following

{"x":"5395496.429117461,5395494.155999963,5395489.773418307","y":"5659901.713053187,5659897.333999608,5659899.601836967"}
{"x":"5396759.156386755,5396761.318999965,5396764.051999965,5396762.000375618,5396760.367999964,5396755.841312531","y":"5660769.610787445,5660770.32399961,5660769.08599961,5660764.5589490365,5660760.95699961,5660763.009167434"}
{"x":"5397230.945016465,5397230.575999966,5397225.642692687","y":"5660956.466597664,5660951.539999611,5660951.8752865605"}
...

There is also a possibility using this expression with a different formatting

array_to_string(
               array_foreach(generate_series(1, num_points($geometry)),
                             'Point_'  || @element || ': (' || x(point_n($geometry, @element))|| ', ' || y(point_n($geometry, @element)) || ')'
                )
)

That will lead to this

Point_1: (5395496.429117461, 5659901.713053187),Point_2: (5395494.155999963, 5659897.333999608),Point_3: (5395489.773418307, 5659899.601836967)
Point_1: (5396759.156386755, 5660769.610787445),Point_2: (5396761.318999965, 5660770.32399961),Point_3: (5396764.051999965, 5660769.08599961),Point_4: (5396762.000375618, 5660764.5589490365),Point_5: (5396760.367999964, 5660760.95699961),Point_6: (5396755.841312531, 5660763.009167434)
Point_1: (5397230.945016465, 5660956.466597664),Point_2: (5397230.575999966, 5660951.539999611),Point_3: (5397225.642692687, 5660951.8752865605)
...

Note: it shall do the work for all geometry types

When you get NULL while simply using $x or $y it probably means that the geometry is either Polylines or Polygons.

So, I will suggest employing this expression to capture coordinates for multitude of objects at once

map_to_json(
    map(
        'x', array_to_string(array_foreach(generate_series(1, num_points($geometry)), x(point_n($geometry, @element)))),
        'y', array_to_string(array_foreach(generate_series(1, num_points($geometry)), y(point_n($geometry, @element))))
     )
)

So, the result will look as following

{"x":"5395496.429117461,5395494.155999963,5395489.773418307","y":"5659901.713053187,5659897.333999608,5659899.601836967"}
{"x":"5396759.156386755,5396761.318999965,5396764.051999965,5396762.000375618,5396760.367999964,5396755.841312531","y":"5660769.610787445,5660770.32399961,5660769.08599961,5660764.5589490365,5660760.95699961,5660763.009167434"}
{"x":"5397230.945016465,5397230.575999966,5397225.642692687","y":"5660956.466597664,5660951.539999611,5660951.8752865605"}
...

There is also a possibility using this expression with a different formatting

array_to_string(
               array_foreach(generate_series(1, num_points($geometry)),
                             'Point_'  || @element || ': (' || x(point_n($geometry, @element))|| ', ' || y(point_n($geometry, @element)) || ')'
                )
)

That will lead to this

Point_1: (5395496.429117461, 5659901.713053187),Point_2: (5395494.155999963, 5659897.333999608),Point_3: (5395489.773418307, 5659899.601836967)
Point_1: (5396759.156386755, 5660769.610787445),Point_2: (5396761.318999965, 5660770.32399961),Point_3: (5396764.051999965, 5660769.08599961),Point_4: (5396762.000375618, 5660764.5589490365),Point_5: (5396760.367999964, 5660760.95699961),Point_6: (5396755.841312531, 5660763.009167434)
Point_1: (5397230.945016465, 5660956.466597664),Point_2: (5397230.575999966, 5660951.539999611),Point_3: (5397225.642692687, 5660951.8752865605)
...

Note: it shall do the work for all geometry types

You get NULL while using $x or $y because your geometry is probably either Polylines or Polygons.

So, I will suggest employing this expression to capture coordinates for multitude of objects at once

map_to_json(
    map(
        'x', array_to_string(array_foreach(generate_series(1, num_points($geometry)), x(point_n($geometry, @element)))),
        'y', array_to_string(array_foreach(generate_series(1, num_points($geometry)), y(point_n($geometry, @element))))
     )
)

So, the result will look as following

{"x":"5395496.429117461,5395494.155999963,5395489.773418307","y":"5659901.713053187,5659897.333999608,5659899.601836967"}
{"x":"5396759.156386755,5396761.318999965,5396764.051999965,5396762.000375618,5396760.367999964,5396755.841312531","y":"5660769.610787445,5660770.32399961,5660769.08599961,5660764.5589490365,5660760.95699961,5660763.009167434"}
{"x":"5397230.945016465,5397230.575999966,5397225.642692687","y":"5660956.466597664,5660951.539999611,5660951.8752865605"}
...

There is also a possibility using this expression with a different formatting

array_to_string(
               array_foreach(generate_series(1, num_points($geometry)),
                             'Point_'  || @element || ': (' || x(point_n($geometry, @element))|| ', ' || y(point_n($geometry, @element)) || ')'
                )
)

That will lead to this

Point_1: (5395496.429117461, 5659901.713053187),Point_2: (5395494.155999963, 5659897.333999608),Point_3: (5395489.773418307, 5659899.601836967)
Point_1: (5396759.156386755, 5660769.610787445),Point_2: (5396761.318999965, 5660770.32399961),Point_3: (5396764.051999965, 5660769.08599961),Point_4: (5396762.000375618, 5660764.5589490365),Point_5: (5396760.367999964, 5660760.95699961),Point_6: (5396755.841312531, 5660763.009167434)
Point_1: (5397230.945016465, 5660956.466597664),Point_2: (5397230.575999966, 5660951.539999611),Point_3: (5397225.642692687, 5660951.8752865605)
...

Note: it shall do the work for all geometry types

Tiny adjustments
Source Link
Taras
  • 33.9k
  • 4
  • 73
  • 148
Loading
Answer extended
Source Link
Taras
  • 33.9k
  • 4
  • 73
  • 148
Loading
Source Link
Taras
  • 33.9k
  • 4
  • 73
  • 148
Loading