0

I have a no geometry table (named TABLE) with 3 fields. There are “Station”, “Offset”, and “Angle”. There are many rows of values (real numbers). These values will be used in geometry by expression. In running geometry by expression, instead of typing the values manually, will get these values from the table, perform the task.

As a reference follow the link below for a calculation that was performed to locate a point using three input values such as the station along a line, the offset, and the angle. If possible, the output should be put in a single layer. I am just starting to learn the in and out of the commands

Locating point along line at specified distance from beginning of line and at given offset (buffer) from line either left or right using QGIS


This procedure works well. From the output, I used single part to multipart to "explode" the attributes, redefine the id to match the table id, and join the output with the table fields to get the input data. I will use this procedure to create a DEM for a road in a mountainous area (not an actual project - just curiosity on my part). The points station, offset, elevation will be calculated by other software.

0

1 Answer 1

2

The basic idea to get the attribute values from another layer is using QGIS expression functions get_feature_by_id() and attribute() (see links for help about syntax and arguments). To get the attribute value from field station on layer table (if a geometry or data only layer does not matter), the syntax is like this, where [id] stands for the id of the feature (row, a number):

attribute (get_feature_by_id ('table', [id]), 'station')

I suppose you have a line layer called line and a data only layer table with attribute fields station, offset and angle. You want to 1) start at the line's start point, follow the along the line for a distance defined in station, from there offset from the line for a distance (value in offset) and an angle (relative to the line at the station point) with value from angle, as described in the solution you linked.

Red points: solution, based on the values form layer table; thin black lines are for visualization purpose only, to show how the red points are created, based on the point on the thick black line with distance defined in station from the line's start point: enter image description here

To look through all features from table, aggregate all $id values from there in an array with aggregate(), then iterate with array_foreach(). Finally, convert the array of geometries into a multipart geomtry with collect_geometries(). The whole expression to use:

collect_geometries(
    array_foreach(
        aggregate (
            'table',
            'array_agg',
            $id
        ),
        with_variable(
            'point',
            end_point (
                line_substring (
                    $geometry, 
                    0, 
                    attribute (
                        get_feature_by_id ('table',@element),
                        'station'
                    )
                )
            ),
            project(
                @point, 
                attribute (
                    get_feature_by_id ('table',@element),
                    'offset'
                ), 
                radians(
                    90 + 
                    attribute (
                        get_feature_by_id ('table',@element),
                        'angle'
                    )
                )
            )
        )
    )
)

Not the answer you're looking for? Browse other questions tagged or ask your own question.