From cd06fa074df158c3b2564088ec4983e4a96dd871 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Wed, 22 Feb 2023 19:14:26 -0500 Subject: [PATCH] Complete sample file generator --- test-data/generator/generate.cpp | 48 +++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/test-data/generator/generate.cpp b/test-data/generator/generate.cpp index f7bfe4e..b00acb6 100644 --- a/test-data/generator/generate.cpp +++ b/test-data/generator/generate.cpp @@ -1,19 +1,47 @@ #include +#include +#include #include "s2/s2earth.h" +#include "s2/s2cell_id.h" #include "s2/s1angle.h" -int main(int argc, char **argv) { - S1Angle lat = S1Angle::Degrees(10.0); - S1Angle lon = S1Angle::Degrees(15.0); - S2LatLng s = S2LatLng(lat, lon); - S2LatLng g = s.Normalized(); +using namespace std; - std::cout << "hi\n"; +uint64 latLonStringsToCellId(string latString, string lonString) { + S1Angle lat = S1Angle::Degrees(atof(latString.c_str())); + S1Angle lon = S1Angle::Degrees(atof(lonString.c_str())); + + S2LatLng latLng = S2LatLng(lat, lon).Normalized(); + + S2CellId s2CellId = S2CellId(latLng); + + return s2CellId.id(); +} + +int main(int argc, char **argv) { + fstream file; + file.open("./sample-lat-lon.csv", fstream::in); + + if (!file) { + cerr << "Could not open input file" << endl; + exit(1); + } + + string latString = ""; + string lonString = ""; + + string header; + getline(file, header, '\n'); + + cout << header << ",cellid" << "\n"; + + while (getline(file, latString, ',')) { + getline(file, lonString, '\n') ; + uint64 generatedCellId = latLonStringsToCellId(latString, lonString); + + cout << latString << "," << lonString << "," << generatedCellId << "\n"; + } return 0; } - -S2LatLng randomLatLon() { - -}