Ejemplo n.º 1
0
 def get(self, lng, lat, altitude, radius):
     #168036.0, 404958.0
     #(168036.0, 404958.0) (168038.83662185463, 404948.41075725335)
     try:
         lng, lat, altitude, radius = map(float, (lng, lat, altitude, radius))
     except Exception:
         raise tornado.web.HTTPError(400)
     print 'Getting elevation at lng: {}, lat: {}, altitude: {}, radius:{}'.format(lng, lat, altitude, radius)
     center = CoordSystem.lnglat_to_pixel((lng, lat))
     sampler = TileSampler()
     line_segments = []
     for start, stop in generate_line_segments(radius, center):
         print start, stop
         elevations, pixels = yield sampler.sample_line(start, stop)
         line_segments.extend(iter_to_runs(generate_visible(altitude, elevations), pixels))
     line_segments = [map(tuple, segment) for segment in line_segments]
     self.write_json(line_segments)
Ejemplo n.º 2
0
 def get(self, format):
     #168036.0, 404958.0
     #(168036.0, 404958.0) (168038.83662185463, 404948.41075725335)
     lng = self.get_argument('lng')
     lat = self.get_argument('lat')
     altitude = self.get_argument('altitude')
     radius = self.get_argument('radius', 1000)
     abs_altitude = self.get_argument('abs_altitude', False)
     try:
         lng, lat, altitude, radius = map(float, (lng, lat, altitude, radius))
     except Exception:
         raise tornado.web.HTTPError(400)
     radius = CoordSystem.pixel_per_meter((lng, lat))*radius #meters -> pixels
     print 'Getting viewshed at lng: {}, lat: {}, altitude: {}, radius:{}'.format(lng, lat, altitude, radius)
     center = CoordSystem.lnglat_to_pixel((lng, lat))
     sampler = TileSampler(url_template=options.tile_template)
     #add relative altitude offset
     if not abs_altitude:
         offset = yield sampler.sample_pixel(center)
     else:
         offset = 0
     line_segments = []
     for start, stop in generate_line_segments(radius, center):
         elevations, pixels = yield sampler.sample_line(start, stop)
         if elevations is None: continue #if no data found skip it
         line_segments.extend(iter_to_runs(generate_visible(altitude+offset, elevations), pixels))
     if len(line_segments) == 0:
         raise tornado.web.HTTPError(404, "No elevation data was found for query")
     line_segments = [[CoordSystem.pixel_to_lnglat(coord) for coord in segment] for segment in line_segments]
     self.write_api_response(format, Feature(geometry=MultiLineString(line_segments), properties={
         "calculationAltitude":altitude,
         "calculationRaduis":float(self.get_argument('radius', 1000)),
         "calculationLat":lat,
         "calculationLng":lng,
         "uiMapCenter":line_segments[0][0],
         "uiPopupContent":"Viewshed at {} meters above sea level".format(altitude)
     }))