Skip to main content
added 7 characters in body
Source Link
Micha
  • 15.8k
  • 23
  • 29

Continuing with simplexio's suggestion, if you don't have a PostGIS server at hand, you can do the job quickly and simply with SpatiaLite: Import both the transmission_lines layer and the center_points layer in a new spatialite DB. Then two SQL commands will give you the shortest distance from each point to the transmission line:

First add a column to the centerpoints for the distance value:

ALTER TABLE center_lines ADD COLUMN dist real;

Now calculate the distance:

UPDATE center_points SET dist=(
SELECT MIN( ST_Distance(cp.geometry, tl.geometry) )
FROM center_points AS cp, transmission_lines AS tl
WHERE cp.pk_uid = center_points.pk_uid);

Regarding projection: the ST_Distance function returns values in the units of the projection, so if you want meters, then you must have both layers in a meters based CRS. If your layers are in geographic (Long/Lat) coordinates, you will get the distance in degrees (not very usefull...), so reproject into an appropriate CRS first.

Continuing with simplexio's suggestion, if you don't have a PostGIS server at hand, you can do the job quickly and simply with SpatiaLite: Import both the transmission_lines layer and the center_points layer in a new spatialite DB. Then two SQL commands will give you the shortest distance from each point to the transmission line:

First add a column to the centerpoints for the distance value:

ALTER TABLE center_lines ADD COLUMN dist real;

Now calculate the distance:

UPDATE center_points SET dist=(
SELECT ST_Distance(cp.geometry, tl.geometry)
FROM center_points AS cp, transmission_lines AS tl
WHERE cp.pk_uid = center_points.pk_uid);

Regarding projection: the ST_Distance function returns values in the units of the projection, so if you want meters, then you must have both layers in a meters based CRS. If your layers are in geographic (Long/Lat) coordinates, you will get the distance in degrees (not very usefull...), so reproject into an appropriate CRS first.

Continuing with simplexio's suggestion, if you don't have a PostGIS server at hand, you can do the job quickly and simply with SpatiaLite: Import both the transmission_lines layer and the center_points layer in a new spatialite DB. Then two SQL commands will give you the shortest distance from each point to the transmission line:

First add a column to the centerpoints for the distance value:

ALTER TABLE center_lines ADD COLUMN dist real;

Now calculate the distance:

UPDATE center_points SET dist=(
SELECT MIN( ST_Distance(cp.geometry, tl.geometry) )
FROM center_points AS cp, transmission_lines AS tl
WHERE cp.pk_uid = center_points.pk_uid);

Regarding projection: the ST_Distance function returns values in the units of the projection, so if you want meters, then you must have both layers in a meters based CRS. If your layers are in geographic (Long/Lat) coordinates, you will get the distance in degrees (not very usefull...), so reproject into an appropriate CRS first.

Source Link
Micha
  • 15.8k
  • 23
  • 29

Continuing with simplexio's suggestion, if you don't have a PostGIS server at hand, you can do the job quickly and simply with SpatiaLite: Import both the transmission_lines layer and the center_points layer in a new spatialite DB. Then two SQL commands will give you the shortest distance from each point to the transmission line:

First add a column to the centerpoints for the distance value:

ALTER TABLE center_lines ADD COLUMN dist real;

Now calculate the distance:

UPDATE center_points SET dist=(
SELECT ST_Distance(cp.geometry, tl.geometry)
FROM center_points AS cp, transmission_lines AS tl
WHERE cp.pk_uid = center_points.pk_uid);

Regarding projection: the ST_Distance function returns values in the units of the projection, so if you want meters, then you must have both layers in a meters based CRS. If your layers are in geographic (Long/Lat) coordinates, you will get the distance in degrees (not very usefull...), so reproject into an appropriate CRS first.