[Qgis-user] Visualize Distance matrix

Joris Hintjens jorishin at gmail.com
Tue Mar 10 02:52:53 PDT 2015


Thanks everybody.
I am illiterate when it comes to scripting. So that is not really an option for me.

To inform you all, 
Last night, I came with a solution that I want to share with you:

My layers are shape files.

what I did:
1) With the plugin “Pointconnector”, I created the lines layer(after a but of hustle: creating a cvs with from-to lines)
then I used the field calculator to measure the length
I used the “length” property to label the distance lines layer.

thanks for your input and ideas

Joris


> Op 10-mrt.-2015, om 10:32 heeft Alexandre Neto <senhor.neto at gmail.com> het volgende geschreven:
> 
> If your data is in a Spatialite or a Postgis database, it's quite easy to achieve what you seek.
> 
> All you need to do is create a SQL query similar to this one in DB Manager:
> 
> SELECT
>     a.gid as dep_id,
>     b.gid as dest_id, 
>     ST_Distance(a.geom, b.geom) as distance,
>     ST_MakeLine(a.geom, b.geom) as geom
> FROM
>     my_table as a, my_table as b
> WHERE
>     a.gid > b.gid
> 
> Note: This is the postgis version, not sure if the same function applies to spatialite
> 
> Add it to the map canvas by using dep_id as unique value column and geom as geometry column.
> 
> Hope it helps.
> 
> Alexandre Neto
> 
> On Tue, Mar 10, 2015 at 8:08 AM, Raymond Nijssen <r.nijssen at terglobo.nl <mailto:r.nijssen at terglobo.nl>> wrote:
> Hi Joris,
> 
> I dont know about that plugin, but i would write a little script for that like this:
> 
> # get active (point) layer as input
> inputlayer = iface.activeLayer()
> # create new memory layer for output
> outputlayer = QgsVectorLayer("Linestring", "distance_lines", "memory")
> outputprovider = outputlayer.dataProvider()
> # loop all points
> iter = inputlayer.getFeatures()
> for feature in iter:
>     p1 = feature.geometry().asPoint()
>     iter2 = layer.getFeatures()
>     for feature2 in iter2:
>         p2 = feature2.geometry().asPoint()
>         if not p1 == p2:
>             # create new line
>             l = QgsGeometry.fromPolyline([p1,p2])
>             feat = QgsFeature()
>             feat.setGeometry(l)
>             outputprovider.addFeatures([feat])
> outputlayer.commitChanges()
> outputlayer.updateExtents()
> # add to map
> QgsMapLayerRegistry.instance().addMapLayer(outputlayer)
> 
> Good luck,
> 
> Raymond
> 
> 
> 
> On 09-03-15 18:18, Joris Hintjens wrote:
> Thanks Raymond, but what I need is the distance from every point in a layer to every other point. That is what “distance matrix” gives me.
> Then, I want to plot every distance line (as a seperate layer?) on the map.
> 
> Joris
> 
> Begin doorgestuurd bericht:
> 
> Datum: 9 maart 2015 15:53:56 CET
> Van: Raymond Nijssen <r.nijssen at terglobo.nl <mailto:r.nijssen at terglobo.nl>>
> Aan: qgis-user at lists.osgeo.org <mailto:qgis-user at lists.osgeo.org>
> Onderwerp: Antw.: [Qgis-user] Visualize Distance matrix
> 
> Hi Joris,
> 
> Not sure if I understand your question, but if you want to do a distance calculation for all points in a point layer to a certain location you can use the field calculator in the attribute table window.
> 
> The expression should be:
> 
> distance($geometry ,geomFromWKT( 'POINT(0 0)' ))
> 
> to calculate all distances to coordinate 0,0.
> 
> Hope this helps you.
> 
> Raymond
> 
> 
> 
> On 09-03-15 15:13, Joris Hintjens wrote:
> I feel stupid: I am stuck with what seems a basic operation..
> I have a points layer, of which I want to visualize the distance matrix.
> I can create the martini CSV.
> I cannot create a distance hub layer with the MMQGIS plugin with From and To point from within  the same layer.
> 
> Any help on how I ca get this result on my map?
> 
> PoinA——————>PointB
>                 xxx Meter
> 
> and this for the entire matrix
> 
> 
> thanks
> Joris
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org <mailto:Qgis-user at lists.osgeo.org>
> http://lists.osgeo.org/mailman/listinfo/qgis-user <http://lists.osgeo.org/mailman/listinfo/qgis-user>
> 
> 
> --
> Terglobo
> Ampèrestraat 110
> 5223 CT 's-Hertogenbosch
> 06-25314983
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org <mailto:Qgis-user at lists.osgeo.org>
> http://lists.osgeo.org/mailman/listinfo/qgis-user <http://lists.osgeo.org/mailman/listinfo/qgis-user>
> 
> 
> 
> 
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org <mailto:Qgis-user at lists.osgeo.org>
> http://lists.osgeo.org/mailman/listinfo/qgis-user <http://lists.osgeo.org/mailman/listinfo/qgis-user>
> 
> 
> -- 
> Terglobo
> Ampèrestraat 110
> 5223 CT 's-Hertogenbosch
> 06-25314983
> 
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org <mailto:Qgis-user at lists.osgeo.org>
> http://lists.osgeo.org/mailman/listinfo/qgis-user <http://lists.osgeo.org/mailman/listinfo/qgis-user>
> 
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20150310/1bb0fbd1/attachment.html>


More information about the Qgis-user mailing list