28#ifndef PANGEA_MAP_WRITER_H
29#define PANGEA_MAP_WRITER_H
48 static void writeMetadata(
const fs::path& path,
const std::string& text) {
49 const fs::path temporary = path.string() +
".partial";
50 if (fs::exists(path) || fs::exists(temporary))
51 throw std::runtime_error(
"Refusing to overwrite map metadata: " + path.u8string());
54 std::ofstream
output(temporary, std::ios::binary);
57 if (!
output)
throw std::runtime_error(
"Cannot write map metadata: " + path.u8string());
59 fs::rename(temporary, path, ec);
60 if (ec)
throw std::runtime_error(
"Finalize map metadata failed: " + ec.message());
62 std::error_code
error;
63 fs::remove(temporary,
error);
64 if (
error) std::cerr <<
"WARNING: Cannot remove partial map metadata: " <<
error.message() <<
'\n';
74 static std::array<fs::path, 2>
mapFiles(
const fs::path& path) {
76 world.replace_extension(
".jgw");
77 return {world, fs::path(path.string() +
".aux.xml")};
97 bool orthorectified =
false) {
99 std::ostringstream world, xml;
100 world.imbue(std::locale::classic());
101 xml.imbue(std::locale::classic());
102 world << std::setprecision(15) << map.
pixelSize <<
"\n0\n0\n" << -map.
pixelSize <<
'\n'
105 const int zone = map.
epsg % 100;
106 xml << std::setprecision(15)
107 <<
"<PAMDataset><SRS>PROJCS["WGS 84 / UTM zone " << zone
108 << (map.
epsg < 32700 ?
"N" :
"S")
109 <<
"",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],"
110 "PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],"
111 "PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],"
112 "PARAMETER["central_meridian"," << zone * 6 - 183
113 <<
"],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],"
114 "PARAMETER["false_northing"," << (map.
epsg < 32700 ? 0 : 10000000)
115 <<
"],UNIT["metre",1],AUTHORITY["EPSG","" << map.
epsg
116 <<
""]]</SRS><GeoTransform>"
119 <<
"</GeoTransform><Metadata><MDI key=\"GEOREFERENCING_MODEL\">"
120 << (orthorectified ?
"Multi-view surface orthorectification; see geometry metadata for coverage classes" :
121 "Reference-plane georeferencing; not a true orthophoto")
122 <<
"</MDI></Metadata></PAMDataset>\n";
126 std::error_code
error;
127 fs::remove(paths[0],
error);
128 if (
error) std::cerr <<
"WARNING: Cannot remove incomplete map metadata: " <<
error.message() <<
'\n';
Shared logging and operating-system checks for the survey executable.
Create the georeferencing files paired with a rendered map image.
static std::array< fs::path, 2 > mapFiles(const fs::path &path)
Return the two sidecar paths associated with a map image.
static void writeMetadata(const fs::path &path, const std::string &text)
Write and publish one complete georeferencing sidecar.
static void writeMap(const fs::path &path, const pangea_survey::MapTile &map, int width, int height, bool orthorectified=false)
Publish a world file and GIS projection metadata for one map image.
struct jpeg_error_mgr error
Convert between WGS-84 coordinates and one local UTM grid.
Centre and pixel geometry for a projected image tile.