[SciPy-User] Raster Distance calculation of an numpy array?

Johannes Radinger JRadinger at gmx.at
Fri Jan 7 07:47:40 EST 2011


-------- Original-Nachricht --------
> Datum: Fri, 7 Jan 2011 07:17:03 -0500
> Von: Zachary Pincus <zachary.pincus at yale.edu>
> An: SciPy Users List <scipy-user at scipy.org>
> Betreff: Re: [SciPy-User] Raster Distance calculation of an numpy array?

> Hi,
> 
> You could use code that Almar Klein (and I to a lesser degree) wrote  
> for the scikits.image package -- it's an implementation of Dijkstra's  
> algorithm ("Minimum Cost Path") for numpy arrays. You provide a  
> "costs" array and a starting point and it finds the total cost to  
> travel to every point in the array from that starting point. (Multiple  
> start points and specified end points are allowed too.)
> 
> So your "costs" array would be the rasterized river; let river pixels  
> have cost-1 to traverse, and let other pixels have some very high  
> cost. (As it stands, the algorithm chokes on infinite-cost pixels when  
> no specified endpoint are given, as it forever tries to find a cheap  
> path to these pixels -- I need to fix this...):
> 
> import scikits.image.graph as graph
> import numpy
> costs = numpy.empty((10,10))
> costs.fill(1e10) # non-river
> costs[3,:] = 1 # a simple river
> mcp = graph.MCP_Geometric(costs)
> cumulative_costs, traceback = mcp.find_costs([[3,0]])
> 
> cumulative_costs now contains the distance from the starting point to  
> every other river point.
> 
> Zach
> 

Just some addional questions which are still unclear:
1) how can I define the starting point? 

2) My numpy array is derived from GIS so I know that each cell (now array element) is 10x10 metres. So the geografical distance between two cell depends if they are connected straight or diagonal. How is this handled with your algorithm? Eg. North-South travel from one cell to another is 10 m (from the center to center) but a travel from Northeast to Southwest (diagonal) is a distance around 14.14 metres.
3) As I have to calculate quite big datasets very often, is it possible to exclude NoData fields (or elements with a value 1e10) from the calculation to decrease processing time?

thank you for your help zach!



> 
> 
> 
> On Jan 7, 2011, at 6:43 AM, Johannes Radinger wrote:
> 
> > Hej,
> >
> > I am also looking for a cost distance algorithm I can use with python:
> >
> > I have a numpy array (extracted from arcgis) which represents a  
> > rastarized
> > river (river=1, else=nodatavalue) and I have a point shape file  
> > which is the startpoint. I want now to calcutlate how far each  
> > rastercell (rivercell) is away (flow-distance) from the given point.  
> > It is possible to calculate with the ArcGIS-CostDistance tool, but  
> > is there also a native python/numpy/scipy way?
> >
> > thanks
> > /j
> > -- 
> > NEU: FreePhone - kostenlos mobil telefonieren und surfen!			
> > Jetzt informieren: http://www.gmx.net/de/go/freephone
> > _______________________________________________
> > SciPy-User mailing list
> > SciPy-User at scipy.org
> > http://mail.scipy.org/mailman/listinfo/scipy-user
> 
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

-- 
NEU: FreePhone - kostenlos mobil telefonieren und surfen!			
Jetzt informieren: http://www.gmx.net/de/go/freephone



More information about the SciPy-User mailing list