diff --git a/src/Makefile.am b/src/Makefile.am index b074e52fe..df1f7172d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -278,6 +278,7 @@ nobase_dist_HEADERS = \ overpass_api/osm-backend/way_updater.h\ overpass_api/output_formats/output_csv.h\ overpass_api/output_formats/output_custom.h\ + overpass_api/output_formats/fixed7.h\ overpass_api/output_formats/output_json.h\ overpass_api/output_formats/output_popup.h\ overpass_api/output_formats/output_xml.h\ diff --git a/src/overpass_api/output_formats/fixed7.h b/src/overpass_api/output_formats/fixed7.h new file mode 100644 index 000000000..5f1ead0d7 --- /dev/null +++ b/src/overpass_api/output_formats/fixed7.h @@ -0,0 +1,88 @@ +/** Copyright 2026 the Overpass API contributors + * + * This file is part of Overpass_API. + * + * Overpass_API is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Overpass_API is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Overpass_API. If not, see . + */ + +#ifndef DE__OSM3S___OVERPASS_API__OUTPUT_FORMATS__FIXED7_H +#define DE__OSM3S___OVERPASS_API__OUTPUT_FORMATS__FIXED7_H + +#include +#include +#include +#include + + +/* Writes a coordinate with exactly the same characters as + out< 0 || len < 8) + { + digits[len++] = '0' + (n % 10); + n /= 10; + } + int pos = 0; + if (std::signbit(value)) + buf[pos++] = '-'; + for (int i = len - 1; i >= 7; --i) + buf[pos++] = digits[i]; + buf[pos++] = '.'; + for (int i = 6; i >= 0; --i) + buf[pos++] = digits[i]; + buf[pos] = 0; + return pos; +} + + +inline std::ostream& operator<<(std::ostream& out, const Fixed7& f) +{ + out.setf(std::ios::fixed, std::ios::floatfield); + out.precision(7); + char buf[64]; + out.write(buf, format_fixed7(buf, f.value)); + return out; +} + + +#endif diff --git a/src/overpass_api/output_formats/output_csv.cc b/src/overpass_api/output_formats/output_csv.cc index 79be9a647..26aec3591 100644 --- a/src/overpass_api/output_formats/output_csv.cc +++ b/src/overpass_api/output_formats/output_csv.cc @@ -18,6 +18,7 @@ #include "../../expat/escape_json.h" #include "output_csv.h" +#include "fixed7.h" bool Output_CSV::write_http_headers() @@ -197,13 +198,13 @@ void process_csv_line(int otype, const std::string& type, Id_Type id, const Opaq { if ((mode.mode & (Output_Mode::COORDS | Output_Mode::GEOMETRY | Output_Mode::BOUNDS | Output_Mode::CENTER)) && geometry.has_center()) - std::cout<first == "lon") { if ((mode.mode & (Output_Mode::COORDS | Output_Mode::GEOMETRY | Output_Mode::BOUNDS | Output_Mode::CENTER)) && geometry.has_center()) - std::cout< #include @@ -329,9 +330,9 @@ std::string process_coords(const std::string& raw_template, uint32 id, double la else if (raw_template.substr(new_pos, 8) == "{{{id}}}") result<* line = geometry.get_line_geometry(); for (std::vector< Point_Double >::const_iterator it = line->begin(); it != line->end(); ++it) std::cout<<(it == line->begin() ? "" : ",")<<"\n"<lon<<", " - <lat<<"]"; + <lon)<<", " + <lat)<<"]"; std::cout<<"\n"<begin() ? "" : ",")<<"\n"<::const_iterator it = iti->begin(); it != iti->end(); ++it) std::cout<<(it == iti->begin() ? "" : ",")<<"\n"<lon<<", " - <lat<<"]"; + <lon)<<", " + <lat)<<"]"; std::cout<<"\n"<\n\n"; } @@ -167,10 +168,10 @@ void print_bounds(const Opaque_Geometry& geometry, Output_Mode mode, bool& inner inner_tags_printed = true; } std::cout<<" \n"; } else if ((mode.mode & Output_Mode::CENTER) && geometry.has_center()) @@ -181,8 +182,8 @@ void print_bounds(const Opaque_Geometry& geometry, Output_Mode mode, bool& inner inner_tags_printed = true; } std::cout<<" \n"; } } @@ -219,8 +220,8 @@ void print_geometry(const Opaque_Geometry& geometry, Output_Mode mode, bool& inn const std::vector< Point_Double >* line = geometry.get_line_geometry(); for (std::vector< Point_Double >::const_iterator it = line->begin(); it != line->end(); ++it) std::cout<lat<<"\"" - " lon=\""<lon<<"\"" + " lat=\""<lat)<<"\"" + " lon=\""<lon)<<"\"" "/>\n"; } else if ((mode.mode & Output_Mode::GEOMETRY) && geometry.has_multiline_geometry()) @@ -237,8 +238,8 @@ void print_geometry(const Opaque_Geometry& geometry, Output_Mode mode, bool& inn std::cout<\n"; for (std::vector< Point_Double >::const_iterator it = iti->begin(); it != iti->end(); ++it) std::cout<lat<<"\"" - " lon=\""<lon<<"\"" + " lat=\""<lat)<<"\"" + " lon=\""<lon)<<"\"" "/>\n"; std::cout<\n"; } @@ -251,8 +252,8 @@ void print_geometry(const Opaque_Geometry& geometry, Output_Mode mode, bool& inn inner_tags_printed = true; } std::cout<\n"; } else if ((mode.mode & Output_Mode::BOUNDS) && geometry.has_bbox()) @@ -263,10 +264,10 @@ void print_geometry(const Opaque_Geometry& geometry, Output_Mode mode, bool& inn inner_tags_printed = true; } std::cout<<" \n"; } else if ((mode.mode & Output_Mode::CENTER) && geometry.has_center()) @@ -277,8 +278,8 @@ void print_geometry(const Opaque_Geometry& geometry, Output_Mode mode, bool& inn inner_tags_printed = true; } std::cout<\n"; } } @@ -298,8 +299,8 @@ void print_members(const Way_Skeleton& skel, const Opaque_Geometry& geometry, { std::cout<<" \n"; } } @@ -327,8 +328,8 @@ void print_members(const Relation_Skeleton& skel, const Opaque_Geometry& geometr if (skel.members[i].type == Relation_Entry::NODE) { if (geometry.has_faithful_relation_geometry() && geometry.relation_pos_is_valid(i)) - std::cout<<" lat=\""<\n"; } else if (skel.members[i].type == Relation_Entry::WAY) @@ -349,8 +350,8 @@ void print_members(const Relation_Skeleton& skel, const Opaque_Geometry& geometr for (uint j = 0; j < geometry.relation_way_size(i); ++j) { if (geometry.relation_pos_is_valid(i, j)) - std::cout<<" \n"; + std::cout<<" \n"; else std::cout<<" \n"; } @@ -377,8 +378,8 @@ void print_node(const Node_Skeleton& skel, std::cout<<" id=\""<