4

I want to only select coastal cities among Cities Over 300K(UN data).

So I downloaded open-source coastline shapefiles online(GSHHS_c_L1 and GSHHS_c_L2), made them into lines, merged 2 lines, reprojected them to CRS EPSG:6871 and CRS EPSG:3857).

With these reprojected coastlines, I made a buffer of 30km and 50km from the coastline.

And then intercepted Cities Over 300K and buffer.

The result shows that with 30km from the coastline, coastal cities are 706, and 50km from the coastline, coastal cities are 939.

However, I see the strange lines north and south of the world map if I zoom out, and when I zoom in it disappears.

How can I deal with this kind of error?

enter image description here

I keep searching for the solution, but it's hard for me to find this kind of error.

I am trying to "Select by Expression". Is this the right way to do it?

enter image description here

Taras
  • 32,823
  • 4
  • 66
  • 137
Yelim Kim
  • 41
  • 2
  • 3
    Same as here: https://gis.stackexchange.com/q/396460/88814 or https://gis.stackexchange.com/q/398086/88814 – Babel Feb 08 '22 at 08:33

1 Answers1

6

No need to create buffers or convert polygons to lines. You can select directly the cities with a maximum distance from the coastline using Select by expression.

On the layer containing the cities, run Select by expression (see docs) with this expression to select all cities with maximum distance of 30 km (30000 m - you can change this value in the last line) from the coastline. On line 7, replace coastline with the name of the layer containing the polygons of the landmass (see below how to get that):

length(
    make_line (
        $geometry, 
        closest_point (
            collect_geometries(
                overlay_nearest (
                    'coastline',
                    boundary($geometry)
                )
            ),
            $geometry
        )
    )
) < 30000

Do not use Mercator projection for distance measurements as results will be wrong due to heavy distortions.

To get the landmass, you can use the built-in world shapefile in QGIS:

  1. Type world to the coordinates field to load the file.

  2. Select all features, run Menu Vector / Geoprocessing Tool / Dissolve. Use the output of this as the coastline layer (line 7 in the expression above).

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
Babel
  • 71,072
  • 14
  • 78
  • 208
  • As I am QGIS newbie, I don't know how I can use the codes you showed me. Is this Youtube video similar to what you are talking about? https://www.youtube.com/watch?v=nE7Y0HxMPVI – Yelim Kim Feb 08 '22 at 09:36
  • 1
    No, you use it with Select by expression, there should be an icon in the selection toolbar, see: https://docs.qgis.org/3.16/en/docs/user_manual/introduction/general_tools.html#automatic-selection - yes, the youtube video you linked shows the select by expression – Babel Feb 08 '22 at 09:43