Message Boards Message Boards

How can I make GraphDistance and FindShortestPath work with Quantities?

Posted 1 year ago

I am creating a local street map from OSM data. I have represented the street network as a weighted graph. The weight of an edge is its geographical length, expressed as a Quantity with Unit="Meters". The plan was to use GraphDistance to find shortest routes. I assumed quantities such as distances would be acceptable as weights for this purpose. It seem such an obvious requirement in any GIS application. But I can't make GraphDistance work with anything other than numbers. Same goes for FindShortestPath. Is there a way to make GraphDistance work with quantities? Obviously I could cast the quantities into pure numbers and then back to quantities, but that is inelegant, a potential source of error, and against all my instincts!

POSTED BY: Tony Durham
2 Replies

I would recommend storing the weights as just the quantity magnitudes without the Quantity wrappers

POSTED BY: Jason Biggs
Posted 1 year ago

Thanks, Jason, that does seem to be the way forward. My data is all in the same units so QuantityMagnitude won't lead to errors. PS if anyone working on product development is reading this, I think it would be cool if GraphDistance was able to add up weights of any kind, so long as they can be summed and compared. Obviously the algorithm won't work if you allow literally any expression as a weight.

POSTED BY: Tony Durham
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract