def __init__(self): pi = _pi # Transform from raw mercator projection to tile coordinates t = deriveTransformation(-pi, pi, 0, 0, pi, pi, 1, 0, -pi, -pi, 0, 1) MercatorProjection.__init__(self, 0, t)
def calculate_corners(aspect, x, y, size, theta): ''' Return latitude, longitude corners for a geometric placement. ''' merc = MercatorProjection(0) # # Get the natural angle of the hypotenuse from map aspect ratio, # measured from the lower-right to the upper-left corner and expressed # in CCW radians from due east. # base_theta = atan2(1, -float(aspect)) # # Derive center-to-corners offset from natural angle and placement theta. # place_theta = base_theta + theta dx = sin(place_theta - pi/2) * size/2 dy = cos(place_theta - pi/2) * size/2 ul = Point(x - dx, y + dy) lr = Point(x + dx, y - dy) # # Convert back to degree latitude and longitude # ul = merc.rawUnproject(ul) lr = merc.rawUnproject(lr) ul_lat, ul_lon = rad2deg(ul.y), rad2deg(ul.x) lr_lat, lr_lon = rad2deg(lr.y), rad2deg(lr.x) return ul_lat, ul_lon, lr_lat, lr_lon
def preview_url(ul, ur, lr, ll): ''' ''' merc = MercatorProjection(0) ul = merc.rawUnproject(Point(*ul)) ur = merc.rawUnproject(Point(*ur)) lr = merc.rawUnproject(Point(*lr)) ll = merc.rawUnproject(Point(*ll)) q = dict(width='512', height='384', module='map') ulx, uly, urx, ury, lrx, lry, llx, lly \ = [rad2deg(v) for v in (ul.x, ul.y, ur.x, ur.y, lr.x, lr.y, ll.x, ll.y)] xmin, ymin = min(ulx, urx, lrx, llx), min(uly, ury, lry, lly) xmax, ymax = max(uly, ury, lry, lly), max(ulx, urx, lrx, llx) perimeter = (ulx, uly, urx, ury, lrx, lry, llx, lly, ulx, uly) q.update(dict(polygons=','.join(['%.4f' % v for v in perimeter]))) q.update( dict(bbox=','.join(('%.4f' % xmin, '%.4f' % ymax, '%.4f' % xmax, '%.4f' % ymin)))) return 'http://pafciu17.dev.openstreetmap.org/?' + urlencode(q)
def build_rough_placement_polygon(aspect, ul_lat, ul_lon, lr_lat, lr_lon): ''' Return rough placement geometry. Length of map hypotenuse in mercator units, angle of hypotenuse in radians counter-clockwise from due east, and footprint polygon. ''' merc = MercatorProjection(0) # # Get the natural angle of the hypotenuse from map aspect ratio, # measured from the lower-right to the upper-left corner and expressed # in CCW radians from due east. # base_theta = atan2(1, -float(aspect)) # # Convert corner lat, lons to conformal mercator projection # ul = merc.rawProject(Point(deg2rad(ul_lon), deg2rad(ul_lat))) lr = merc.rawProject(Point(deg2rad(lr_lon), deg2rad(lr_lat))) # # Derive dimensions of map in mercator units. # map_hypotenuse = hypot(ul.x - lr.x, ul.y - lr.y) map_width = map_hypotenuse * sin(base_theta - pi / 2) map_height = map_hypotenuse * cos(base_theta - pi / 2) # # Get the placed angle of the hypotenuse from the two placed corners, # again measured from the lower-right to the upper-left corner and # expressed in CCW radians from due east. # place_theta = atan2(ul.y - lr.y, ul.x - lr.x) diff_theta = place_theta - base_theta # # Derive the other two corners of the roughly-placed map, # and make a polygon in mercator units. # dx = map_height * sin(diff_theta) dy = map_height * cos(diff_theta) ur = Point(lr.x - dx, lr.y + dy) dx = map_width * cos(diff_theta) dy = map_width * sin(diff_theta) ll = Point(lr.x - dx, lr.y - dy) poly = [(ul.x, ul.y), (ur.x, ur.y), (lr.x, lr.y), (ll.x, ll.y)] return map_hypotenuse, diff_theta, poly
def build_rough_placement_polygon(aspect, ul_lat, ul_lon, lr_lat, lr_lon): ''' Return rough placement geometry. Length of map hypotenuse in mercator units, angle of hypotenuse in radians counter-clockwise from due east, and footprint polygon. ''' merc = MercatorProjection(0) # # Get the natural angle of the hypotenuse from map aspect ratio, # measured from the lower-right to the upper-left corner and expressed # in CCW radians from due east. # base_theta = atan2(1, -float(aspect)) # # Convert corner lat, lons to conformal mercator projection # ul = merc.rawProject(Point(deg2rad(ul_lon), deg2rad(ul_lat))) lr = merc.rawProject(Point(deg2rad(lr_lon), deg2rad(lr_lat))) # # Derive dimensions of map in mercator units. # map_hypotenuse = hypot(ul.x - lr.x, ul.y - lr.y) map_width = map_hypotenuse * sin(base_theta - pi/2) map_height = map_hypotenuse * cos(base_theta - pi/2) # # Get the placed angle of the hypotenuse from the two placed corners, # again measured from the lower-right to the upper-left corner and # expressed in CCW radians from due east. # place_theta = atan2(ul.y - lr.y, ul.x - lr.x) diff_theta = place_theta - base_theta # # Derive the other two corners of the roughly-placed map, # and make a polygon in mercator units. # dx = map_height * sin(diff_theta) dy = map_height * cos(diff_theta) ur = Point(lr.x - dx, lr.y + dy) dx = map_width * cos(diff_theta) dy = map_width * sin(diff_theta) ll = Point(lr.x - dx, lr.y - dy) poly = Polygon([(ul.x, ul.y), (ur.x, ur.y), (lr.x, lr.y), (ll.x, ll.y), (ul.x, ul.y)]) return map_hypotenuse, diff_theta, poly
def get_extent(gjson): extent = {} m = MercatorProjection(0) b = get_bbox(extract_coords(gjson)) points = [[b[3], b[0]], [b[1], b[2]]] if (points[0][0] - points[1][0] == 0) or (points[1][1] - points[0][1] == 0): extent['lat'] = points[0][0] extent['lon'] = points[1][1] extent['zoom'] = 18 else: i = float('inf') w = 800 h = 600 tl = [ min(map(lambda x: x[0], points)), min(map(lambda x: x[1], points)) ] br = [ max(map(lambda x: x[0], points)), max(map(lambda x: x[1], points)) ] c1 = m.locationCoordinate(Location(tl[0], tl[1])) c2 = m.locationCoordinate(Location(br[0], br[1])) while (abs(c1.column - c2.column) * 256.0) < w and (abs(c1.row - c2.row) * 256.0) < h: c1 = c1.zoomBy(1) c2 = c2.zoomBy(1) center = m.coordinateLocation( Coordinate((c1.row + c2.row) / 2, (c1.column + c2.column) / 2, c1.zoom)) extent['lat'] = center.lat extent['lon'] = center.lon if c1.zoom > 18: extent['zoom'] = 18 else: extent['zoom'] = c1.zoom return extent
def get_extent(gjson): extent = {} m = MercatorProjection(0) b = get_bbox(extract_coords(gjson)) points = [[b[3], b[0]], [b[1], b[2]]] if (points[0][0] - points[1][0] == 0) or (points[1][1] - points[0][1] == 0): extent['lat'] = points[0][0] extent['lon'] = points[1][1] extent['zoom'] = 18 else: i = float('inf') w = 800 h = 600 tl = [min(map(lambda x: x[0], points)), min(map(lambda x: x[1], points))] br = [max(map(lambda x: x[0], points)), max(map(lambda x: x[1], points))] c1 = m.locationCoordinate(Location(tl[0], tl[1])) c2 = m.locationCoordinate(Location(br[0], br[1])) while (abs(c1.column - c2.column) * 256.0) < w and (abs(c1.row - c2.row) * 256.0) < h: c1 = c1.zoomBy(1) c2 = c2.zoomBy(1) center = m.coordinateLocation(Coordinate( (c1.row + c2.row) / 2, (c1.column + c2.column) / 2, c1.zoom)) extent['lat'] = center.lat extent['lon'] = center.lon if c1.zoom > 18: extent['zoom'] = 18 else: extent['zoom'] = c1.zoom return extent
def preview_url(ul, ur, lr, ll): ''' ''' merc = MercatorProjection(0) ul = merc.rawUnproject(Point(*ul)) ur = merc.rawUnproject(Point(*ur)) lr = merc.rawUnproject(Point(*lr)) ll = merc.rawUnproject(Point(*ll)) q = dict(width='512', height='384', module='map') ulx, uly, urx, ury, lrx, lry, llx, lly \ = [rad2deg(v) for v in (ul.x, ul.y, ur.x, ur.y, lr.x, lr.y, ll.x, ll.y)] xmin, ymin = min(ulx, urx, lrx, llx), min(uly, ury, lry, lly) xmax, ymax = max(uly, ury, lry, lly), max(ulx, urx, lrx, llx) perimeter = (ulx, uly, urx, ury, lrx, lry, llx, lly, ulx, uly) q.update(dict(polygons=','.join(['%.4f' % v for v in perimeter]))) q.update(dict(bbox=','.join(('%.4f' % xmin, '%.4f' % ymax, '%.4f' % xmax, '%.4f' % ymin)))) return 'http://pafciu17.dev.openstreetmap.org/?' + urlencode(q)
def __init__(self): t = deriveTransformation(-pi, pi, 0, 0, pi, pi, 1, 0, -pi, -pi, 0, 1) self.projection = MercatorProjection(0, t)
def get_projection(): ''' Return the correct spherical mercator project for Nokia. ''' # the spherical mercator world tile covers (-π, -π) to (π, π) t = deriveTransformation(-pi, pi, 0, 0, pi, pi, 1, 0, -pi, -pi, 0, 1) return MercatorProjection(0, t)
def __init__(self): # these numbers are slightly magic. t = Transformation(1.068070779e7, 0, 3.355443185e7, 0, -1.068070890e7, 3.355443057e7) MercatorProjection.__init__(self, 26, t)