I am trying to find the nearest point on the road network closest to a given point. I imported the road network into PostGIS from QGIS and am using the SQL window in QGIS DB Manager to query the road table. The query I used is:
SELECT *
FROM public."wa_transformed"
ORDER BY ST_Distance(
ST_StartPoint(geom),
st_SetSrid(ST_MakePoint(-122.2652671, 47.30995661), 4326),
true
) ASC
LIMIT 1;
The idea is to find the distance between all the roads in the road network and find the first item in the sorted list. . The red marker is the point (47.309, -122.265) whereas the thick brown line on the left is the query result (which is definitely not the closest source from red point).
I had to transform the roads (original SRID - 4326) to match the OpenStreetMap layer on QGIS using a CRS defined by (+proj=lcc +lat_1=45.83333333333334 +lat_2=47.33333333333334 +lat_0=45.33333333333334 +lon_0=-120.5 +x_0=500000.0000000001 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs). However, I get the same result whether I use the transformed table or original table.
I am using POSTGIS="2.5.2 r17328" [EXTENSION] PGSQL="110" GEOS="3.7.0-CAPI-1.11.0 3.7.1" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.2.4, released 2018/03/19" LIBXML="2.7.8" LIBJSON="0.12" LIBPROTOBUF="1.2.1" RASTER
The original roads shapefile is here and the transformed shapefile is here
USER 10000
which seemed to work.