Here's a little QGIS python function that implements this. It requires the rasterlang plugin (the repository has to be added to QGIS manually).
It expects three mandatory parameters: The points layer, a raster layer (to determine the size and resolution of the output), and a filename for the output layer. You can also provide an optional argument to determine the exponent of the distance decay function.
The weights for the points need to be in the first attribute column of the points layer.
The resulting raster is automatically added to the canvas.
Here's an example of how to run the script. The points have weights between 20 and 90, and the grid is 60 by 50 map units in size.
points = qgis.utils.iface.mapCanvas().layer(0)
raster = qgis.utils.iface.mapCanvas().layer(1)
huff(points,raster,"output.tiff",2)
from rasterlang.layers import layerAsArray
from rasterlang.layers import writeGeoTiff
import numpy as np
def huff(points, raster, outputfile, decay=1):
if points.type() != QgsMapLayer.VectorLayer:
print "Error: First argument is not a vector layer (but it has to be)"
return
if raster.type() != QgsMapLayer.RasterLayer:
print "Error: Second argument is not a raster layer (but it has to be)"
return
b = layerAsArray(raster)
e = raster.extent()
provider = points.dataProvider()
extent = [e.xMinimum(),e.yMinimum(),e.xMaximum(),e.yMaximum()]
xcols = np.size(layerAsArray(raster),1)
ycols = np.size(layerAsArray(raster),0)
xvec = np.linspace(extent[0], extent[2], xcols, endpoint=False)
xvec = xvec + (xvec[1]-xvec[0])/2
yvec = np.linspace(extent[3], extent[1], ycols, endpoint=False)
yvec = yvec + (yvec[1]-yvec[0])/2
coordArray = np.meshgrid(xvec,yvec)
gravity = b
point = QgsFeature()
provider.select( provider.attributeIndexes() )
while provider.nextFeature(point):
coord = point.geometry().asPoint()
weight = point.attributeMap()[0].toFloat()[0]
curGravity = weight * ( (coordArray[0]-coord[0])**2 + (coordArray[1]-coord[1])**2)**(-decay/2)
gravity = np.dstack((gravity, curGravity))
gravitySum = np.sum(gravity,2)
huff = np.max(gravity,2)/gravitySum
np.shape(huff)
writeGeoTiff(huff,extent,outputfile)
rlayer = QgsRasterLayer(outputfile)
QgsMapLayerRegistry.instance().addMapLayer(rlayer)