Home > postgis > How to find the nearest point projected on the road network?

# How to find the nearest point projected on the road network?

April 15Hits:1

I would like to know if there is a function at pgRouting that given a point (lon/lat) can give you the projection of that point to the road network .

There are linear referencing functions in PostGIS to help you out project the location of a point along a line. For example, if you have a road, and a point of interest (POI) that is along the side of the road, you can:

Here is the SQL to extract the interpolated POI on the road:

WITH data AS (
SELECT 'LINESTRING (50 40, 40 60, 50 90, 30 140)'::geometry AS road,
'POINT (60 110)'::geometry AS poi)

SELECT ST_AsText(

FROM data;

Returns POINT(44.4827586206897 103.793103448276), which is close to the POI, but projected on the road.

The tricky things you might run into is to locate the closest road LINESTRING and/or, your road network might be a MULTILINESTRING, which needs to be broken down into LINESTRINGs in order to work with the above. Also, linear referencing systems work best with projected (i.e., non-Lat/Lon) data, particularly if your data are far north/south from the equator.

Update An easier function that can use other geometries, including MULTILINESTRINGs is ST_ClosestPoint. For example, the closest POI on a road network is found using:

WITH data AS (
SELECT 'MULTILINESTRING ((20 30, 40 70, 40 110),
(40 110, 70 160, 80 190),
(40 110, 25 118, 10 140))'::geometry AS road_network,
'POINT (40 130)'::geometry AS poi)

FROM data;

(Also, as a side note, I'm using a CTE or "WITH" query to supply data. Your query only needs to use the "SELECT" part.)

## Related Articles

• ### How to find the nearest point projected on the road network?April 15

I would like to know if there is a function at pgRouting that given a point (lon/lat) can give you the projection of that point to the road network . Thanks in advance john --------------Solutions------------- There are linear referencing functions i

• ### Finding distance (in time) from nearest point out of 4 along a road networkApril 14

I have four points representing harbors along the coast. I also have a roads layer that has info on each road segment such as length, speed limit, and travel time. I calculated travel time with [(length in miles) / (speed limit in mph)] * 60 for the

• ### How join attributes for point feature from nearest points in road networkJuly 31

I have two layers: 'linear' - road network and 'point' - points in each linear features intersections. Point layer have in attribute table name for each point features: A,B,C,D,E,F, etc. How add in point layer names of nearest points of road network?

• ### On Google Compute Engine, is it possible to have VMs from one project talk to VMs from another project over the internal network?September 5

Is it possible for VMs from one project to talk to VMs from another project over the internal network? I ask this because we've hit some quota limits and we could try to divide our VMs into groups in separate projects. I tried connecting to ports in

• ### xampp - can access control panel, cannot access projects/sites on local networkJune 28

I've configured xampp and firewall so I can access desktop pc's localhost over my local network through desktop pc's IP. But I'm not able to access auctual projects: I can access: http://192.168.x.x/xampp or http://192.168.x.x/phpMyAdmin But I cannot

• ### How does the projection-angle of road arrows change drivers' expectations of the appropriate speed in a curve?July 29

Have any studies been conducted to decide the 'print angle' (anamorphic projection) of road signage? Are there any other expectations involved? --------------Solutions------------- I do not think there is an known answer to this question. There is re

• ### Speed up projection of a bipartitie network for a big file using NetworkX and PandasJuly 23

I have a pretty big file (3 million lines) with each line being a person-to-event relationship. Ultimate, I want to project this bipartite network onto a single-mode, weighted, network, and write it to a CSV file. I'm using NetworkX, and I've tested

• ### sliding window for K nearest links search on an adjacent list represented road mapFebruary 8

I am doing a K nearest links search on a road network, which is represented by an adjacency list (e.g. adj[1] = {{3,0.5},{8,0.6},{9,1.0}} means node1 is connected to node 3, 8, 9 and the links have the weights of 0.5, 0.6, 1.0 respectively.). I want

• ### Maximum Distance Nearest Neighbor and a Unknown Coordinate August 22

I have this hunch that I could travel no more than 50 miles from the most remote spot in the Eastern United States (east of the Mississippi River), in the direction of the nearest road, and find a road. Definitions: Most Remote: Spot furthest from a

• ### Create Eclipse Project From Host to Guest Using VirtualBoxMarch 15

I have windows 7 host and ubuntu 10 guest. I am using a bridged connection and can quite easily access files on the guest from the host. I can create files from within win explorer, edit files, delete files, everything..within explorer (or even notep

• ### How does k-nearest neighbor apply to wireless network positioning?February 15

I'm trying to gain some insight into the variety of positioning algorithms for wireless networks. Apparently there are three categories of algorithms: distance estimation, scene analysis and proximity. As far as I understand, distance estimation algo

• ### Assign projection to a satellite imageApril 28

Today I stumbled upon a picture taken from the ISS looking down Europe and it is really beautiful. So, I started thinking I could add more to the picture. Like world borders, cities, road network, everything. For fun. The problem is that I know next

• ### Calculating distance and/or time taken to travel from population centre to nearest hospital in QGISMay 20

I'm trying to find out how long it would take to travel by car from each of the Lower Layer Super Output Areas (LSOA) in Norfolk, England to the nearest Hospital (or just what the distance is and I can estimate drive time, if the former is too diffic

• ### Improving Network Flow Documentation in 3G- 4G upgrade projectMay 27

I just started on an upgrade project, 3G-> 4G, with network flow documentation in PNG, BMP and Visio files (500+ flows). The HLD and LLD documents have been written however it appears from reading them that a lot of the drawings were not very accurat

• ### problem with WFS Data, GDAL, Python, ArcGIS, & Defining ProjectionAugust 6

I'm pulling in data in gml2 format with a EPSG#4267 from a wfs. I create a datastream in python and then run the following from the python window in ArcMap: data = datastream.read() #write the gml data to a gml file rasterdata = open("E:\\Melo\\USGS&

• ### 3 bugs after starting Marionnet 0.90.6 and cant add Machine in new projectApril 5

I need to make simple project in Marionnet- virtual network. I have no experience with Marionnet and minimal experience with Ubuntu/Linux. After installing and starting Marionnet there are 3 errors: Unsatisfied dependency: You don't have a default UM

• ### Sharing a project tree between environmentsMay 28

To save space and time I copied a large project tree on a network drive as hard links, i.e. cp -a -r --link proj proj_B (background: it's huge, needs to be rebuilt from two incompatible environments, and doesn't have good support for specifying inter

• ### ArcMap Point Distance giving decimal degrees even when in projected coordinate systemJuly 16

I'm trying to calculate pairwise river distance among 60 XY coordinates in a small region of Mexico with ArcMap 10.2.2. I have defined my projections and projected both my stream network and XY coordinate layers as projected coordinates using the NAD

• ### Migrating MS-Project 2013 Master Schedule to SharePoint 2013August 12

The Master Schedule which I've been using on a Network Drive I've moved to SharePoint. So far it appears that if I also move the individual projects files to SharePoint and update the link it will work, however if I leave any individual projects file

• ### How to set-up a distributed data storage system for The Real Junkfood ProjectAugust 14

Context The Real Junkfood Project consists of a network of pay as you feel (PAYF) cafes. We need to log the data from each of ~100 cafes, generating perhaps 50 rows each par day. I estimate that this could (if we expand) generate around 1 million row