Ejemplo n.º 1
0
 def index(self):
     template_values = {}
     trails_js = []
     trailsQuery = Session.query(TrailDesc).all()
     for row in trailsQuery:
         trail_js = {"id": row.id, "searchVal": row.osm_search}
         trails_js.append(trail_js)
     template_values["trails_js"] = json.dumps(trails_js)
     return render("/map.html", template_values)
Ejemplo n.º 2
0
    def index(self):
	template_values = {}
        trails_js = []
        trailsQuery = Session.query(TrailDesc).all()
        for row in trailsQuery:
            trail_js = {
                "id": row.id,
                "searchVal": row.osm_search
            }
            trails_js.append(trail_js)
        template_values["trails_js"] = json.dumps(trails_js)
        return render("/map.html", template_values)
Ejemplo n.º 3
0
 def index(self):
     if "lat" in request.params:
         lat = float( request.params["lat"] )
     else:
         return { "error": True, "message": "No \"lat\" parameter was found." }
     
     if "lon" in request.params:
         lon = float( request.params["lon"] )
     else:
         return { "error": True, "message": "No \"lon\" parameter was found." }
     
     if "zoom" in request.params:
         zoom = int( request.params["zoom"] )
     else:
         return { "error": True, "message": "No \"zoom\" parameter was found." }
     
     is_mobile = False
     if "mobile" in request.params:
         if request.params["mobile"] == "true":
             is_mobile = True
         
     point = Point(lon, lat)
     wkb_point = WKBSpatialElement( buffer( point.wkb ), 4326 )
     
     meters_to_search = 1.8
     if is_mobile:
         meters_to_search = 2.1
     
     distance_meters = pow( meters_to_search, ( 20 - zoom ) )
     tolerance = metersToDegrees( distance_meters, lat )
     
     features = []
     
     #
     # Query points first
     #
     
     #
     # These layers aren't visible until we hit zoom 9
     #
     if zoom >= 9:        
         #
         # Light Rail Stop query
         #
         lightRailFilter = func.ST_DWithin( wkb_point, LightRail.geometry_column(), tolerance )
         lightRailQuery = Session.query( LightRail ).filter( lightRailFilter )
         
         for row in lightRailQuery:
             feature = row.toFeature()
             feature.properties["feature_type"] = "Light Rail Stop"
             features.append( feature )
             
         if len( features ) > 0:
             return FeatureCollection(features)
             
         if zoom >= 16:
             #
             # These layers aren't visible until we hit zoom 16
             #
             
             #
             # Bar/Pub query
             #
             barPubFilter = func.ST_DWithin( wkb_point, BarPub.geometry_column(), tolerance )
             barPubQuery = Session.query( BarPub ).filter ( barPubFilter )
             
             for row in barPubQuery:
                 feature = row.toFeature()
                 feature.properties["feature_type"] = "Bar/Pub"
                 features.append( feature )
                 
             if len( features ) > 0:
                 return FeatureCollection( features )
                 
             #
             # Cafe query
             #
             cafeFilter = func.ST_DWithin( wkb_point, Cafe.geometry_column(), tolerance )
             cafeQuery = Session.query( Cafe ).filter ( cafeFilter )
             
             for row in cafeQuery:
                 feature = row.toFeature()
                 feature.properties["feature_type"] = "Cafe"
                 features.append( feature )
                 
             if len( features ) > 0:
                 return FeatureCollection( features )
             
             #
             # Restaurant query
             #
             restaurantFilter = func.ST_DWithin( wkb_point, Restaurant.geometry_column(), tolerance )
             restaurantQuery = Session.query( Restaurant ).filter ( restaurantFilter )
             
             for row in restaurantQuery:
                 feature = row.toFeature()
                 feature.properties["feature_type"] = "Restaurant"
                 features.append( feature )
                 
             if len( features ) > 0:
                 return FeatureCollection( features )
             
             #
             # Bicycle Rental query
             #
             bicycleRentalFilter = func.ST_DWithin( wkb_point, BicycleRental.geometry_column(), tolerance )
             bicycleRentalQuery = Session.query( BicycleRental ).filter ( bicycleRentalFilter )
             
             for row in bicycleRentalQuery:
                 feature = row.toFeature()
                 feature.properties["feature_type"] = "Bicycle Rental"
                 features.append( feature )
                 
             if len( features ) > 0:
                 return FeatureCollection( features )
                 
     #
     # If no points, query lines
     #
     
     #
     # Light Rail Line query
     #
     lightRailLineFilter = func.ST_DWithin( wkb_point, LightRailLine.geometry_column(), tolerance )
     lightRailLineQuery = Session.query( LightRailLine ).filter( lightRailLineFilter )
     
     for row in lightRailLineQuery:
         feature = row.toFeature()
         feature.properties["feature_type"] = "Light Rail Line"
         features.append( feature )
         
     if len( features ) > 0:
         return FeatureCollection( features )
         
     #
     # Free Bus query
     #
     freeBusFilter = func.ST_DWithin( wkb_point, FreeBus.geometry_column(), tolerance )
     freeBusQuery = Session.query( FreeBus ).filter( freeBusFilter )
     
     for row in freeBusQuery:
         feature = row.toFeature()
         feature.properties["feature_type"] = "Free Bus"
         features.append( feature )
         
     if len( features ) > 0:
         return FeatureCollection( features )
 
     
     return FeatureCollection( features )