예제 #1
0
			# named view of the SVG document
			guide = svg.createElement("sodipodi:guide")
			guide.setAttribute("id",guide_id)
			guide.setAttribute("orientation","1,0")
			guide.setAttribute("position","{0},{1}".format(guide_pos,0))
			namedview.appendChild(guide)
			print("Added guide for meridian={0}° at x={1}.".format(lon,guide_pos))
			n_guides = n_guides + 1
		else:
			print("Skipping already existing guide for meridian={0}°.".format(lon))
	
	# iterate over parallels list...
	for lat in parallels:
		# calculate position and id; flip y coordinate because guides are an
		# extension by Inkscape which uses a different coordinate system...
		guide_pos = h_doc - (y + (OSMTools.lat_to_y(lat,args.ZOOM) - args.Y0) * height / args.NY)
		guide_id = "parallel{0}".format(lat)
		
		# check if guide is already present (id in use)
		if guide_id not in existing_guides:
			# create Inkscape guide element, populate it and append it to the
			# named view of the SVG document
			guide = svg.createElement("sodipodi:guide")
			guide.setAttribute("id",guide_id)
			guide.setAttribute("orientation","0,1")
			guide.setAttribute("position","{0},{1}".format(0,guide_pos))
			namedview.appendChild(guide)
			print("Added guide for parallel={0}° at y={1}.".format(lat,guide_pos))
			n_guides = n_guides + 1
		else:
			print("Skipping already existing guide for parallel={0}°.".format(lat))
예제 #2
0
			print("Invalid source URL provided!")
			sys.exit(1)
	
	# check bounding box values
	if args.EAST <= args.WEST or args.NORTH <= args.SOUTH:
		print("Invalid bounding box values! Required: WEST < EAST and SOUTH < NORTH")
		sys.exit(1)
	
	# check zoom factor
	if args.ZOOM < 0 or args.ZOOM > 18:
		print("Invalid zoom factor!")
		sys.exit(1)
	
	# upper left corner of map
	x0 = int(OSMTools.lon_to_x(args.WEST,args.ZOOM))
	y0 = int(OSMTools.lat_to_y(args.NORTH,args.ZOOM))
	
	# lower right corner of map
	# (i.e. lower right tile next to the one which contains EAST/SOUTH -> +1)
	x1 = int(OSMTools.lon_to_x(args.EAST, args.ZOOM))+1
	y1 = int(OSMTools.lat_to_y(args.SOUTH,args.ZOOM))+1
	
	tiles = [(args.ZOOM,x,y) for x in range(x0,x1) for y in range(y0,y1)]
	n     = len(tiles)
	
	# calculate image dimensions based on the standard 256x256 tile
	w = (x1 - x0) * 256
	h = (y1 - y0) * 256
	
	# open map image file
	img = PIL.Image.new("RGBA",(w,h))