Snap points to nearest line

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Snap points to nearest line

Cameron Munro
Hi,

I have two layers - points and lines. I'd like to snap the points to the nearest line and take the attributes of that line. Is this possible within QGIS?

Thanks,

Cameron.

_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: Snap points to nearest line

pcav
Yes

---
Paolo Cavallini http://faunalia.it/pc
Sent from mobile, sorry for being short

----- Reply message -----
Da: "Cameron Munro" <[hidden email]>
A: "[hidden email]" <[hidden email]>
Oggetto: [Qgis-user] Snap points to nearest line
Data: mar, nov 15, 2011 02:59


Hi,

I have two layers - points and lines. I'd like to snap the points to the nearest line and take the attributes of that line. Is this possible within QGIS?

Thanks,

Cameron.

_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: Snap points to nearest line

Andreas Neumann-4
In reply to this post by Cameron Munro
 Hi Cameron,

 Snapping works fine, but automatically getting the attributes from an
 object it snaps to is not possible.

 Andreas

 On Mon, 14 Nov 2011 17:59:58 -0800 (PST), Cameron Munro wrote:
> Hi,
>
> I have two layers - points and lines. I'd like to snap the points to
> the nearest line and take the attributes of that line. Is this
> possible within QGIS?
>
> Thanks,
>
> Cameron.

--
 --
 Andreas Neumann
 Böschacherstrasse 10A
 8624 Grüt (Gossau ZH)
 Switzerland
_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: Snap points to nearest line

nicklas
Hallo

If you have your data stored in PostGIS you can do it directly in the
database.

To get a new table with the snapped points and the line attribudes you
can run:

CREATE TABLE line_attribute_point AS
SELECT distinct on (linetable.id) linetable.*,
ST_ClosestPoint(linetable.geom, pointtable.geom) as snapped_point
FROM
linetable,pointtable
ORDER BY ST_Distance(linetable.geom, pointtable.geom);

Something like that.

But this will be slow if you have many points and polygons. Then you can
use ST_Dwithin to speed it up if you know how far away the line and
point can be that should be snapped. Say you don't want to snap longer
than 100 meters then:

CREATE TABLE line_attribute_point AS
SELECT distinct on (linetable.id) linetable.*,
ST_ClosestPoint(linetable.geom, pointtable.geom) as snapped_point
FROM
linetable INNER JOIN pointtable on ST_Dwithin(linetable.geom,
pointtable.geom, 100)
ORDER BY ST_Distance(linetable.geom, pointtable.geom);

Something like that.


HTH
Nicklas








On Tue, 2011-11-15 at 10:49 +0100, Andreas Neumann wrote:

> Hi Cameron,
>
>  Snapping works fine, but automatically getting the attributes from an
>  object it snaps to is not possible.
>
>  Andreas
>
>  On Mon, 14 Nov 2011 17:59:58 -0800 (PST), Cameron Munro wrote:
> > Hi,
> >
> > I have two layers - points and lines. I'd like to snap the points to
> > the nearest line and take the attributes of that line. Is this
> > possible within QGIS?
> >
> > Thanks,
> >
> > Cameron.
>


_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: Snap points to nearest line

Pedro Venâncio
In reply to this post by Andreas Neumann-4
Hi,

To automatically get the attributes from an object, in my view, only using PostgreSQL/PostGIS with triggers.

Best regards,

Pedro Venâncio





----- Original Message -----
From: Andreas Neumann

Hi Cameron,

Snapping works fine, but automatically getting the attributes from an object it snaps to is not possible.

Andreas

On Mon, 14 Nov 2011 17:59:58 -0800 (PST), Cameron Munro wrote:
> Hi,
>
> I have two layers - points and lines. I'd like to snap the points to
> the nearest line and take the attributes of that line. Is this
> possible within QGIS?
>
> Thanks,
>
> Cameron.

-- --
Andreas Neumann
Böschacherstrasse 10A
8624 Grüt (Gossau ZH)
Switzerland
_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user

_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: Snap points to nearest line

Andreas Neumann-4
> To automatically get the attributes from an object, in my view, only
> using PostgreSQL/PostGIS with triggers.

 yes - this would work, but the drawback is that the triggers are only
 triggered on saving the data and not when the snapping happens ...
 Saving in QGIS only happens manually after a user clicked on the save
 button or leaves the edit sesssion.

 It would be nice to have the option of immediate saves to PostgreSQL
 for each edit of any single record, for such purposes.

 Andreas

 --
 Andreas Neumann
 Böschacherstrasse 10A
 8624 Grüt (Gossau ZH)
 Switzerland
_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: Snap points to nearest line

magerlin
In reply to this post by Cameron Munro
Cameron Munro wrote
Hi,

I have two layers - points and lines. I'd like to snap the points to the nearest line and take the attributes of that line. Is this possible within QGIS?

Thanks,

Cameron.
Hi Cameron

Two suggestions, but not an excact solution:

You can use the mmqgis plugin and select "Hub Distance". With this you can transfer an attribute (or an ID and then use a join afterwards) to a pointlayer from the nearest line in a linelayer.

But be aware that "nearest" line will be based only on a "centre point" for the line and if your lines are very curved or of varying lengths you may not get the expected result.

You might use the "Vector-Geometry Tools-Extract Nodes" to convert your line layer to a point layer and use this point layer as the Hublayer instead of the line layer.

Anybody knows an excact method?


Regards Morten

Currently using Qgis 3.14.15
Windows 10, 64bit