Book Image

Python Geospatial Analysis Cookbook

Book Image

Python Geospatial Analysis Cookbook

Overview of this book

Table of Contents (20 chapters)
Python Geospatial Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Other Geospatial Python Libraries
Mapping Icon Libraries
Index

Calculating indoor route walk time


Our indoor routing application would not be complete without letting us know how long it would take to walk to our indoor walk now, would it? We will create a couple of small functions that you can insert into your code in the previous recipe to print out the route walk times.

How to do it...

  1. Without further ado, let's take a look at some code:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    def format_walk_time(walk_time):
        """
        takes argument: float walkTime in seconds
        returns argument: string time  "xx minutes xx seconds"
        """
        if walk_time > 0.0:
            return str(int(walk_time / 60.0)) + " minutes " + str(int(round(walk_time % 60))) + " seconds"
        else:
            return "Walk time is less than zero! Something is wrong"
    
    
    def calc_distance_walktime(rows):
        """
        calculates distance and walk_time.
        rows must be an array of linestrings --> a route, retrieved from the DB.
        rows[5]: type of line (stairs, elevator, etc)
       ...