コード例 #1
0
 def get(self, lng, lat):
     try:
         lnglat = map(float, (lng, lat))
     except Exception:
         raise tornado.web.HTTPError(400)
     sampler = TileSampler()
     pixel = CoordSystem.lnglat_to_pixel(lnglat)
     print 'Getting elevation at lng,lat:%s,%s %s,%s:' % (lng, lat, pixel[0], pixel[1])
     value = yield sampler.sample_pixel(pixel)
     lnglat = CoordSystem.pixel_to_lnglat(pixel)
     self.write_geojson(Feature(geometry=Point(lnglat), properties={
         "elevation":float(value)
     }))
コード例 #2
0
 def get(self, format):
     lng = self.get_argument('lng')
     lat = self.get_argument('lat')
     try:
         lnglat = map(float, (lng, lat))
     except Exception:
         raise tornado.web.HTTPError(400)
     sampler = TileSampler(url_template=options.tile_template)
     pixel = CoordSystem.lnglat_to_pixel(lnglat)
     print 'Getting elevation at lng,lat:%s,%s %s,%s:' % (lng, lat, pixel[0], pixel[1])
     value = yield sampler.sample_pixel(pixel)
     lnglat = CoordSystem.pixel_to_lnglat(pixel)
     self.write_api_response(format, Feature(geometry=Point(lnglat), properties={
         "elevation":float(value),
         "uiMapCenter":lnglat,
         "uiPopupContent": "{} meters".format(float(value))
     }))
コード例 #3
0
    def get(self, format):
        lng = self.get_argument('lng')
        lat = self.get_argument('lat')
        radius = self.get_argument('radius', 1000)
        try:
            lng, lat, radius = map(float, (lng, lat, radius))
        except Exception:
            raise tornado.web.HTTPError(400)
        radius = CoordSystem.pixel_per_meter((lng, lat))*radius #meters -> pixels
        print 'Getting top of hill at lng: {}, lat: {}, radius:{}'.format(lng, lat, radius)
        center = CoordSystem.lnglat_to_pixel((lng, lat))
        sampler = TileSampler(url_template=options.tile_template)

        # Iterate over all points in the square which surrounds the circle
        max_elv = None
        max_pos = None

        center = (int(center[0]), int(center[1]))
        radius = int(radius)

        top_left = (center[0] - radius, center[1] - radius)
        for x in xrange(top_left[0], top_left[0] + radius * 2):
            for y in xrange(top_left[1], top_left[1] + radius * 2):
                # Is it in the circle?
                if math.sqrt((x - center[0]) ** 2 + (y - center[1]) ** 2) < radius:
                    # Find the elevation
                    elevation = yield sampler.sample_pixel((x, y))
                    if max_elv is None or elevation > max_elv:
                        max_elv = elevation
                        max_pos = (x, y)

        lnglat = CoordSystem.pixel_to_lnglat(max_pos)
        self.write_api_response(format, Feature(geometry=Point(lnglat), properties={
            "elevation":float(max_elv),
            "uiMapCenter":lnglat,
            "uiPopupContent": "{} meters\n({},{})".format(float(max_elv), lnglat[1], lnglat[0])
        }))
コード例 #4
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)
     }))