route_distances/distances.py
def isochrone(self, from_long, from_lat, max_time = None,
                  max_distance = None, mode = "walk"):
        """ Generate an isochrone centered at a given point

        Args:
            orig_long: The origin longitude.
            orig_lat: The origin latitude.
            max_time: The time, in seconds via the given mode of
                transportation, that the outer edge of the isochrone will be
                generated at.
            max_distance: The distance, in meters, that the outer edge of
                the isochrone will be generated at. (BROKEN)
            mode: A key of the self.mode_map dictionary that will be remapped
                to a different string and passed to the API.

        Returns:
            A GeoJSON multipolygon.
        """

        isochrone_args = []

        if (max_distance):
            isochrone_args.append("maxWalkDistance=%d" % max_distance)

        if (max_time):
            isochrone_args.append("cutoffSec=%d" % max_time)

        if (len(isochrone_args) == 0):
            raise AssertionError("Both max_distance and max_time are None")

        url = ("http://%s/otp/routers/default/isochrone"
               "?fromPlace=%f,%f&%s&mode=%s" % (
            self.entrypoint,
            from_lat, from_long,
            "&".join(isochrone_args),
            self.map_mode(mode)
        ))

        self.log("Sending request: %s" % url)
        response = requests.get(url, timeout = self.timeout)
        data = response.content.decode()
        self.log("Response: %s" % data)

        if (response.status_code == 200):
            content = json.loads(data)
            if ("features" in content):
                geojson = content["features"][0]["geometry"]

                if (len(geojson["coordinates"]) > 0):

                    # Visualization
                    if (self.verbose):
                        base = False
                        for multipolygon in geojson["coordinates"]:
                            for polygon in multipolygon:
                                # Base polygon
                                if (base == False):
                                    self.staticmaps.add_coords(
                                        polygon,
                                        _type = "polygon",
                                        color = "0x00ff0066"
                                    )
                                    base = True
                                # Subtraction of that polygon
                                else:
                                    self.staticmaps.add_coords(
                                        polygon,
                                        _type = "polygon",
                                        color = "0xff000066"
                                    )

                        self.log("Preview with Google Static Maps API: %s"
                                 % self.staticmaps.generate_url())
                        self.staticmaps.reset()

                    return geojson
                else:
                    return False

        return False
 Generate an isochrone centered at a given point

        Args:
            orig_long: The origin longitude.
            orig_lat: The origin latitude.
            max_time: The time, in seconds via the given mode of
                transportation, that the outer edge of the isochrone will be
                generated at.
            max_distance: The distance, in meters, that the outer edge of
                the isochrone will be generated at. (BROKEN)
            mode: A key of the self.mode_map dictionary that will be remapped
                to a different string and passed to the API.

        Returns:
            A GeoJSON multipolygon.
        
Generate an isochrone centered at a given point
Generate an isochrone centered at a given point
def isochrone(self, from_long, from_lat, max_time = None,
                  max_distance = None, mode = "walk"):
        isochrone_args = []
        if (max_distance):
            isochrone_args.append("maxWalkDistance=%d" % max_distance)
        if (max_time):
            isochrone_args.append("cutoffSec=%d" % max_time)
        if (len(isochrone_args) == 0):
            raise AssertionError("Both max_distance and max_time are None")
        url = ("http://%s/otp/routers/default/isochrone"
               "?fromPlace=%f,%f&%s&mode=%s" % (
            self.entrypoint,
            from_lat, from_long,
            "&".join(isochrone_args),
            self.map_mode(mode)
        ))
        self.log("Sending request: %s" % url)
        response = requests.get(url, timeout = self.timeout)
        data = response.content.decode()
        self.log("Response: %s" % data)
        if (response.status_code == 200):
            content = json.loads(data)
            if ("features" in content):
                geojson = content["features"][0]["geometry"]
                if (len(geojson["coordinates"]) > 0):
                    if (self.verbose):
                        base = False
                        for multipolygon in geojson["coordinates"]:
                            for polygon in multipolygon:
                                if (base == False):
                                    self.staticmaps.add_coords(
                                        polygon,
                                        _type = "polygon",
                                        color = "0x00ff0066"
                                    )
                                    base = True
                                else:
                                    self.staticmaps.add_coords(
                                        polygon,
                                        _type = "polygon",
                                        color = "0xff000066"
                                    )
                        self.log("Preview with Google Static Maps API: %s"
                                 % self.staticmaps.generate_url())
                        self.staticmaps.reset()
                    return geojson
                else:
                    return False
        return False
def isochrone ( self , from_long , from_lat , max_time = None , max_distance = None , mode = "walk" ) : isochrone_args = [ ] if ( max_distance ) : isochrone_args . append ( "maxWalkDistance=%d" % max_distance ) if ( max_time ) : isochrone_args . append ( "cutoffSec=%d" % max_time ) if ( len ( isochrone_args ) == 0 ) : raise AssertionError ( "Both max_distance and max_time are None" ) url = ( "http://%s/otp/routers/default/isochrone" "?fromPlace=%f,%f&%s&mode=%s" % ( self . entrypoint , from_lat , from_long , "&" . join ( isochrone_args ) , self . map_mode ( mode ) ) ) self . log ( "Sending request: %s" % url ) response = requests . get ( url , timeout = self . timeout ) data = response . content . decode ( ) self . log ( "Response: %s" % data ) if ( response . status_code == 200 ) : content = json . loads ( data ) if ( "features" in content ) : geojson = content [ "features" ] [ 0 ] [ "geometry" ] if ( len ( geojson [ "coordinates" ] ) > 0 ) : if ( self . verbose ) : base = False for multipolygon in geojson [ "coordinates" ] : for polygon in multipolygon : if ( base == False ) : self . staticmaps . add_coords ( polygon , _type = "polygon" , color = "0x00ff0066" ) base = True else : self . staticmaps . add_coords ( polygon , _type = "polygon" , color = "0xff000066" ) self . log ( "Preview with Google Static Maps API: %s" % self . staticmaps . generate_url ( ) ) self . staticmaps . reset ( ) return geojson else : return False return False
Generate an isochrone centered at a given point
Generate an isochrone centered at a given point
""" Generate an isochrone centered at a given point

        Args:
            orig_long: The origin longitude.
            orig_lat: The origin latitude.
            max_time: The time, in seconds via the given mode of
                transportation, that the outer edge of the isochrone will be
                generated at.
            max_distance: The distance, in meters, that the outer edge of
                the isochrone will be generated at. (BROKEN)
            mode: A key of the self.mode_map dictionary that will be remapped
                to a different string and passed to the API.

        Returns:
            A GeoJSON multipolygon.
        """ # Visualization # Base polygon # Subtraction of that polygon
A GeoJSON multipolygon.
A GeoJSON multipolygon .
self
from_long
from_lat
max_time
The time, in seconds via the given mode of
transportation, that the outer edge of the isochrone will be
generated at.
The time in seconds via the given mode of transportation that the outer edge of the isochrone will be generated at .
max_distance
The distance, in meters, that the outer edge of
the isochrone will be generated at. (BROKEN)
The distance in meters that the outer edge of the isochrone will be generated at . ( BROKEN )
mode
A key of the self.mode_map dictionary that will be remapped
to a different string and passed to the API.
A key of the self . mode_map dictionary that will be remapped to a different string and passed to the API .
orig_long
The origin longitude.
The origin longitude .
orig_lat
The origin latitude.
The origin latitude .