Beispiel #1
0
def BoundsToRawJson(lat, lng, lod, bounds):
    """Convert bounds and original point to json object and outputs the json.

  Args:
    lat: (float) Latitude in degrees.
    lng: (float) Longitude in degrees.
    lod: (integer) Level of detail (zoom).
    bounds: (dictonary)  North, west, south, east bounds.
  Returns:
    raw json containing point and tile bounds.
  """
    utils = search_utils.SearchUtils()
    print "%s\n" % utils.GetContentType("json")

    coordinates = "[%f,%f,0]" % (bounds["west"], bounds["south"])
    coordinates += ",[%f,%f,0]" % (bounds["west"], bounds["north"])
    coordinates += ",[%f,%f,0]" % (bounds["east"], bounds["north"])
    coordinates += ",[%f,%f,0]" % (bounds["east"], bounds["south"])
    coordinates += ",[%f,%f,0]" % (bounds["west"], bounds["south"])

    placemark = utils.json_placemark_polygon_template.substitute(
        name="bounds",
        styleUrl="#placemark_label",
        description="Bounds of tile containing %5.3f,%5.3f at LOD %d." %
        (lat, lng, lod),
        coordinates=coordinates)
    search_placemarks = "%s" % placemark

    placemark = utils.json_placemark_point_template.substitute(
        name="point",
        styleUrl="#placemark_label",
        description="%5.3f,%5.3f" % (lat, lng),
        lat=lat,
        lng=lng)
    search_placemarks += ",%s" % placemark

    json_response = utils.json_template.substitute(
        foldername="Results",
        json_style=utils.json_style,
        json_placemark=search_placemarks)
    return json_response
Beispiel #2
0
def BoundsToKml(lat, lng, lod, bounds):
    """Convert bounds and original point to kml and outputs the kml.

  Args:
    lat: (float) Latitude in degrees.
    lng: (float) Longitude in degrees.
    lod: (integer) Level of detail (zoom).
    bounds: (dictonary)  North, west, south, east bounds.
  """
    utils = search_utils.SearchUtils()
    print "%s\n" % utils.GetContentType("kml")

    coordinates = "%f,%f,0" % (bounds["west"], bounds["south"])
    coordinates += " %f,%f,0" % (bounds["west"], bounds["north"])
    coordinates += " %f,%f,0" % (bounds["east"], bounds["north"])
    coordinates += " %f,%f,0" % (bounds["east"], bounds["south"])
    coordinates += " %f,%f,0" % (bounds["west"], bounds["south"])

    placemark = utils.placemark_polygon_template.substitute(
        name="bounds",
        styleUrl="#placemark_label",
        description="Bounds of tile containing %5.3f,%5.3f at LOD %d." %
        (lat, lng, lod),
        coordinates=coordinates)
    search_placemarks = "\n%s" % placemark

    placemark = utils.placemark_point_template.substitute(
        name="point",
        styleUrl="#placemark_label",
        description="%5.3f,%5.3f" % (lat, lng),
        lat=lat,
        lng=lng)
    search_placemarks += "\n%s" % placemark

    kml_response = utils.kml_template.substitute(foldername="Results",
                                                 style=utils.style,
                                                 placemark=search_placemarks)
    print kml_response