Skip to content

Commit

Permalink
datetime Fix #44
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Romain committed May 8, 2024
1 parent ad80508 commit 19770ca
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# lasR ?.?.?

- Enhance: #44 `write_vpc` write the `datetime`

# lasR 0.5.2

- New: #42 `write_vpc()` gained an argument `absolute_path`
Expand Down
32 changes: 27 additions & 5 deletions src/LASRcore/LAScatalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <iomanip>
#include <algorithm>
#include <filesystem>
#include <ctime>

// To parse JSON VPC
#include <nlohmann/json.hpp>
Expand Down Expand Up @@ -282,6 +283,7 @@ bool LAScatalog::write_vpc(const std::string& vpcfile, const CRS& crs, bool abso
Rectangle& bbox = bboxes[i];
uint64_t n = npoints[i];
bool index = indexed[i];
std::string date = dates[i];

Rectangle bbwgs84 = bbox;
OGRSpatialReference oTargetSRS;
Expand All @@ -296,7 +298,7 @@ bool LAScatalog::write_vpc(const std::string& vpcfile, const CRS& crs, bool abso
{
last_error = "Transformation of the bounding in WGS 84 failed!";
return false;
}
}

char buffer[1024];
snprintf(buffer, sizeof(buffer), "[ [%.9lf,%.9lf,0], [%.9lf,%.9lf,0], [%.9lf,%.9lf,0], [%.9lf,%.9lf,0], [%.9lf,%.9lf,0] ]", bbwgs84.minx, bbwgs84.miny, bbwgs84.maxx, bbwgs84.miny, bbwgs84.maxx, bbwgs84.maxy, bbwgs84.minx, bbwgs84.maxy, bbwgs84.minx, bbwgs84.miny);
Expand All @@ -320,7 +322,7 @@ bool LAScatalog::write_vpc(const std::string& vpcfile, const CRS& crs, bool abso
output << " }," << std::endl;
output << " \"bbox\": " << sbbox << "," << std::endl;
output << " \"properties\": {" << std::endl;
output << " \"datetime\": " << "\"0-01-01T00:00:00Z\""<< "," << std::endl;
output << " \"datetime\": " << autoquote(date) << "," << std::endl;
output << " \"pc:count\": " << n << "," << std::endl;;
output << " \"pc:type\": " << "\"lidar\"" << ","<< std::endl;
output << " \"proj:bbox\": [" << std::fixed << std::setprecision(3) << bbox.minx << ", " << bbox.miny << ", " << bbox.maxx << ", " << bbox.maxy << "],"<< std::endl;
Expand Down Expand Up @@ -412,6 +414,27 @@ bool LAScatalog::add_file(const std::string& file, bool noprocess)
add_bbox(lasreader->header.min_x, lasreader->header.min_y, lasreader->header.max_x, lasreader->header.max_y, lasreader->get_index() || lasreader->get_copcindex(), noprocess);
npoints.push_back(MAX(lasreader->header.number_of_point_records, lasreader->header.extended_number_of_point_records));

int year = lasreader->header.file_creation_year;
int doy = lasreader->header.file_creation_day;
if (year > 0)
{
if (doy == 0) doy = 1;
std::tm timeinfo = {};
timeinfo.tm_year = year - 1900;
timeinfo.tm_mday = doy;
std::mktime(&timeinfo);
char buffer[26];
strftime(buffer, 26, "%Y-%m-%dT%H:%M:%SZ", &timeinfo);
std::string date(buffer);
dates.push_back(date);
print("Y %d, D %d\n", year, doy);
print("%s\n", date.c_str());
}
else
{
dates.push_back("0-01-01T00:00:00Z");
}

lasreader->close();
delete lasreader;

Expand Down Expand Up @@ -723,8 +746,8 @@ void LAScatalog::clear()
// CRS
wkt_set.clear();
epsg_set.clear();
//epsg = 0;
//wkt.clear();
//epsg = 0;
//wkt.clear();

use_dataframe = true;

Expand Down Expand Up @@ -788,4 +811,3 @@ LAScatalog::~LAScatalog()
}



1 change: 1 addition & 0 deletions src/LASRcore/LAScatalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class LAScatalog
std::vector<bool> noprocess; // the file is not processed and is used only for buffering
std::vector<Rectangle> bboxes; // bounding boxes of the files
std::vector<std::filesystem::path> files; // path to files
std::vector<std::string> dates;

// queries, partial read
LASkdtreeRectangles* laskdtree;
Expand Down

0 comments on commit 19770ca

Please sign in to comment.