Esempio n. 1
0
	/**
	 * \brief Renders a tile to the given path using the test styles.
	 * \param tilePath path to the resulting tile
	 * \param id identifier of the tile that should be rendered
	 */
	void renderTile(const char* tilePath, shared_ptr<TileIdentifier> id)
	{
		BOOST_TEST_MESSAGE("Render: " << tilePath);
		RenderAttributes attr;
		Style* canvas = attr.getCanvasStyle();
		canvas->fill_color = Color(1.0f, 1.0f, 1.0f, 1.0f);

		coord_t x0, x1, y0, y1;
		tileToMercator(id->getX(),     id->getY(),     id->getZoom(), x0, y0);
		tileToMercator(id->getX() + 1, id->getY() + 1, id->getZoom(), x1, y1);
		FixedRect r = FixedRect(FixedPoint(x0, y0), FixedPoint(x1, y1));

		auto nodes = data->getNodeIDs(r);
		auto ways = data->getWayIDs(r);
		auto relations = data->getRelationIDs(r);

		generateStyles();

		BOOST_TEST_MESSAGE(" - ways " << ways->size());
		styleWays(ways, attr);

		BOOST_TEST_MESSAGE(" - nodes " << nodes->size());
		styleNodes(nodes, attr);

		BOOST_TEST_MESSAGE(" - relations " << relations->size());
		styleRelations(relations, attr);

		shared_ptr<MetaIdentifier> mid = MetaIdentifier::Create(id);
		shared_ptr<MetaTile> meta = boost::make_shared<MetaTile>(mid);
		renderer->renderMetaTile(attr, meta);
		shared_ptr<Tile> tile = boost::make_shared<Tile>(id);
		renderer->sliceTile(meta, tile);

		BOOST_TEST_MESSAGE("Writing the tile:");
		std::ofstream out;
		out.open(tilePath);
		BOOST_TEST_MESSAGE("- get data");
        Tile::ImageType png = tile->getImage();
		BOOST_TEST_MESSAGE("- writing (" << png->size() << " Bytes)");
		out.write((const char*) png->data(), png->size());
		out.close();
	}
Esempio n. 2
0
void Cache::writeFile(shared_ptr<Tile> tile, const string& path) {
	std::ofstream out(path, std::ios::out | std::ios::binary);
	if(out.is_open())
	{
		Tile::ImageType png = tile->getImage();
		if (png==0) {
			out.close();
			boost::filesystem::path file(path);
			boost::filesystem::remove(file);
			BOOST_THROW_EXCEPTION(excp::InputFormatException());
		} else {
			auto size = png->size();
			out.write((const char*) png->data(), size);
		}
	} else {
		// e.g. Disk full
		BOOST_THROW_EXCEPTION(excp::FileNotFoundException() << excp::InfoFileName(path));
	}
}