[Qgis-user] QGIS "Near"

Carson Farmer carson.farmer at gmail.com
Mon May 31 04:11:41 PDT 2010


No plugin that I know of, but it could probably be done quite easily
from the Python console,
something to the tune of (untested!):

layer = qgis.utils.iface.mapCanvas().layer(0)
provider = layer.dataProvider()
provider.select([])
feat = QgsFeature()
index = QgsSpatialIndex()
while provider.nextFeature(feat):
    index.insertFeature(feat)
provider.select([])
while provider.nextFeature(feat):
    near = index.nearestNeighbour(feat.geometry().asPoint(),1)
    nearest = near[0]
    # now do something here with the two points... and output results
as you like

# Obviously you'd have a bit more work to do here to compute angles
etc. but all this functionality is available via the QGIS API...
# If I get a chance, I might try to add this to the fTools/Vector menu...

Regards,

Carson

On 26 May 2010 22:13, whollycow <sjgardner at wisc.edu> wrote:
> Is anyone aware of a function equivalent to "Near" in ArcGIS? (see
> http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Near_(Analysis)
> for reference) I have been searching all day and haven't come across
> anything quite like it. It seems like such basic functionality I would be
> surprised if someone hasn't already coded a solution.
> ________________________________
> View this message in context: QGIS "Near"
> Sent from the qgis-user mailing list archive at Nabble.com.
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user
>
>



-- 
Carson J. Q. Farmer
ISSP Doctoral Fellow
National Centre for Geocomputation
National University of Ireland, Maynooth,
http://www.carsonfarmer.com/



More information about the Qgis-user mailing list