Sunday 26 February 2017

Looking for a fast, open-source raster cost-distance function to use in code


I've been scouring the internet for a fast, open-source cost-distance function that I can embed inside my code. The functionality should basically work like the ArcGIS implementation where I can specify a source raster and cost raster and output a cost distance raster. That said, the implementation does not need to be as sophisticated as ArcGIS in that I don't need to necessarily input "rasters" with embedded geo metadata - a signature that takes simple numeric arrays will suffice since I can verify that the data overlaps correctly at the time I call the function.


My specific intent is to calculate the cost-distance to a single point in the center of a 1000 x 1000 cost raster based on a user click, so fast execution is very important.


A C# implementation would be ideal but I'll look at anything that's out there.


Does anyone know of an open-source library that supports this? Thanks for your help!



Answer



GRASS GIS has a C implementation in r.cost (source, documentation) which uses a min-heap. Alternatively, you could use a graph package like QuickGraph and Floyd-Warshall to compute the cost.


Recent changes in GRASS 6.4 have made r.cost significantly faster, so perhaps performance may be good enough: on my laptop, it takes about 3s for a 1M cell region, or 5s with knight's move enabled. GRASS is a C application, not a drop-in solution for a C# codebase. If you're OK adding to your stack, you could use PyWPS to make calls to GRASS, and then use the result elsewhere in your application.



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...