NationalSecurityAgency/qgis-latlontools-plugin

Lat Lon Tools expression to be used in array foreach

roelsantiago opened this issue · 13 comments

Is there a way to use the ddmmss expression instead of to_dms inside the array for each? see expression below:

replace (
array_to_string (
array_foreach (
generate_series (1, num_points( $geometry)-1),
to_dms (x(point_n( $geometry,@element)),'y',2, 'suffix') || ' ' ||
to_dms(y(point_n( $geometry,@element)),'x',2, 'suffix') || '\n'
)),
',',''
)

The objective is to come up with an output of packed coordinates (Lat/Long) instead of the coordinates with symbols.

You could do something like this.

replace (
array_to_string (
array_foreach (
generate_series (1, num_points( $geometry)-1),
ddmmss(y(point_n( $geometry,@element)), x(point_n( $geometry,@element)), 'yx',0,'')
)),
',',''
)

This is the output for a simple polygon.

'370826N0964809W410103N0922947W394649N0875422W364109N0900559W'

You can use

transform(geometry,source_auth_id,dest_auth_id)

Perhaps I should add an optional crs parameter to ddmmss to make it easier.

I updated Lat Lon Tools to version 3.5.8 so you can now add an optional CRS parameter for your input coordinate like this:

ddmmss(3301866.78, -9081576.13, 'yx', 0, ', ', 'EPSG:3857')

You would do something like this:

replace (
array_to_string (
array_foreach (
generate_series (1, num_points( $geometry)-1),
ddmmss(y(point_n( $geometry,@element)), x(point_n( $geometry,@element)), 'yx', 0, '', 'EPSG:3857')
)),
',',''
)

You will need to use the proper EPSG code for your input coordinates. I don't know what you are using.

@roelsantiago Usually it is best to open a new ticket, but I will reopen this one. I didn't add a decimal degree routine because you can naturally get the x and y decimal coordinates from $x and $y. If you need to you can transform your coordinate first. I don't know if it is worth adding a Lat Lon Tools expression to format the entire string all at once.

@roelsantiago I decided to add two more expressions and should have a new Lat Lon Tools release before the end of the week.

I released Lat Lon Tools 3.6.2. There is a new function called ll_dd. Let me know how it works out for you.

@roelsantiago Glad it works for you.