I'm very new to QGIS 3 and I have a problem. I got a point.shp indicating coastal transects long the world's coast set 500 m apart. I selected a subset projecting only the sandy transects along the Dutch coastline. From these points I know want to create a 5 km long transect inland 90° to the existing shoreline. The first picture shows the available points, second picture is a zoom-in and the red lines indicate what I want to achieve. Is there any way on how to create these inland transects perpendicular to the shore? Any suggestions, insights, tips, etc?
3 Answers
It can be done using Geometry by expression tool (in Processing Toolbox > Vector geometry
).
Assumption: (Please modify them as necessary)
- Your Dutch coastline layername:
Coast
- The coastline layer has an id (e.g.
"fid"
) field, and the said coastline's id is1
.
After starting Geometry by expression tool, please set parameters as:
- Input layer: your start points layer
- Output geometry: Line
(Geometry expression)
make_line($geometry,
project($geometry,
5000,
azimuth($geometry,
closest_point(
geometry(get_feature('Coast','fid', '1')),
$geometry))))
This expression may look complicated, but -
- First,
closest_point(geometry(get_feature('Coast','fid', '1')), $geometry)
finds a point on the coastline which is at the shortest distance from your start points. - Then
azimuth()
will find the bearing of the above point from the start point. - And
project($geometry, 5000, xxx)
will move your start point to theazimuth()
direction by 5000m. - Finally,
make_line($geometry, xxxx)
will draw a line from the start point to theproject(ed)
point in the above Step 3.
-
Also, when opening the "expression" tab in the "Geometry by expression"-panel, it states as "Output Prieview=NULL"– SolHCommented Jun 23, 2020 at 15:19
Firstly, thank you so much for taking the time to consider my issue. I tried to run the code you sent me. It works in the sense that it executes the command and I create an output .shp, however, it just projects an empty layer, despite the fact that I have an attribute table with information in it. Any suggestions on what goes wrong?
-
Geometry by expression will not produce or copy attributes so I suspect you have used other tool.– KazuhitoCommented Jun 23, 2020 at 7:51
-
I definitely used Geometry by expression. But then, my coastline also has a big attribute table and not just one field like yours. Could that be the issue?– SolHCommented Jun 24, 2020 at 8:02
-
No, I don't think the attribute table of the coastline can affect the output. Out of curiosity, are your point and coastline layers on the same CRS?– KazuhitoCommented Jun 24, 2020 at 8:48
-
I have been thinking possible cause of this strange output... can I ask which layer have you assigned to Input layer? Any possibility you have used coastline as the input layer?– KazuhitoCommented Jun 24, 2020 at 9:04
Thank you for baring with me. So, as you can see in the picture, I used the transect points layer as the input layer. All my layers are on the CSR Amersfoort / RD New 28992 However, my coastline does not only have one field, like in your example but a very extensive attribute table (see picture 2). Could this be the problem? If you, where did you get your Dutch coastline .shp file form? Maybe if I use your coastline layer it would work?
-
sorry, just saw that you said the coastline attribute table shouldn't be the problem.– SolHCommented Jun 24, 2020 at 19:51
-
Hi, welcome to GIS StackExchange, you are posting answers to your question, but you are not answering it. The Post Your Answer section is reserved to post an answer. You can write comments in Kazuhito's answer if you want to comment their answer, or you can improve your question editing it to include more details or sample data to let the users write an answer that fits exactly your model. In any case, please do not post answers if it is not to answer your question. Commented Jun 25, 2020 at 0:27
-
-
It seems your 'Dutch_coastline' layer consists of a lot of smaller segments, and you are trying to link them by
get_feature('Dutch_coastline','natural', 'coastline')
. Unfortunately it does not help to identify the appropriate segment, because there are lots of the samecoastline
s in thenatural
attribute field. Please merge the coastlines to make it one line. My Dutch coastline was taken from Natural Earth dataset.– KazuhitoCommented Jun 25, 2020 at 8:44