Skip to content

Commit

Permalink
Cleanup JNI; add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin committed Sep 24, 2023
1 parent 5ba8b0b commit 24e50ce
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 47 deletions.
157 changes: 157 additions & 0 deletions core/src/test/resources/quick-info-with-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"readers.las":
{
"bounds":
{
"maxx": 638982.55,
"maxy": 853535.43,
"maxz": 586.38,
"minx": 635619.85,
"miny": 848899.7,
"minz": 406.59
},
"dimensions": "X, Y, Z, Intensity, ReturnNumber, NumberOfReturns, ScanDirectionFlag, EdgeOfFlightLine, Classification, ScanAngleRank, UserData, PointSourceId, GpsTime, Red, Green, Blue",
"num_points": 1065,
"srs":
{
"compoundwkt": "PROJCS[\"NAD83(HARN) / Oregon LCC (m)\",GEOGCS[\"NAD83(HARN)\",DATUM[\"NAD83_High_Accuracy_Reference_Network\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6152\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4152\"]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"latitude_of_origin\",41.75],PARAMETER[\"central_meridian\",-120.5],PARAMETER[\"standard_parallel_1\",43],PARAMETER[\"standard_parallel_2\",45.5],PARAMETER[\"false_easting\",400000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH],AUTHORITY[\"EPSG\",\"2993\"]]",
"horizontal": "PROJCS[\"NAD83(HARN) / Oregon LCC (m)\",GEOGCS[\"NAD83(HARN)\",DATUM[\"NAD83_High_Accuracy_Reference_Network\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6152\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4152\"]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"latitude_of_origin\",41.75],PARAMETER[\"central_meridian\",-120.5],PARAMETER[\"standard_parallel_1\",43],PARAMETER[\"standard_parallel_2\",45.5],PARAMETER[\"false_easting\",400000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH],AUTHORITY[\"EPSG\",\"2993\"]]",
"isgeocentric": false,
"isgeographic": false,
"json": {
"type": "ProjectedCRS",
"name": "NAD83(HARN) / Oregon LCC (m)",
"base_crs": {
"name": "NAD83(HARN)",
"datum": {
"type": "GeodeticReferenceFrame",
"name": "NAD83 (High Accuracy Reference Network)",
"ellipsoid": {
"name": "GRS 1980",
"semi_major_axis": 6378137,
"inverse_flattening": 298.257222101
}
},
"coordinate_system": {
"subtype": "ellipsoidal",
"axis": [
{
"name": "Geodetic latitude",
"abbreviation": "Lat",
"direction": "north",
"unit": "degree"
},
{
"name": "Geodetic longitude",
"abbreviation": "Lon",
"direction": "east",
"unit": "degree"
}
]
},
"id": {
"authority": "EPSG",
"code": 4152
}
},
"conversion": {
"name": "unnamed",
"method": {
"name": "Lambert Conic Conformal (2SP)",
"id": {
"authority": "EPSG",
"code": 9802
}
},
"parameters": [
{
"name": "Latitude of false origin",
"value": 41.75,
"unit": "degree",
"id": {
"authority": "EPSG",
"code": 8821
}
},
{
"name": "Longitude of false origin",
"value": -120.5,
"unit": "degree",
"id": {
"authority": "EPSG",
"code": 8822
}
},
{
"name": "Latitude of 1st standard parallel",
"value": 43,
"unit": "degree",
"id": {
"authority": "EPSG",
"code": 8823
}
},
{
"name": "Latitude of 2nd standard parallel",
"value": 45.5,
"unit": "degree",
"id": {
"authority": "EPSG",
"code": 8824
}
},
{
"name": "Easting at false origin",
"value": 400000,
"unit": "metre",
"id": {
"authority": "EPSG",
"code": 8826
}
},
{
"name": "Northing at false origin",
"value": 0,
"unit": "metre",
"id": {
"authority": "EPSG",
"code": 8827
}
}
]
},
"coordinate_system": {
"subtype": "Cartesian",
"axis": [
{
"name": "Easting",
"abbreviation": "",
"direction": "east",
"unit": "metre"
},
{
"name": "Northing",
"abbreviation": "",
"direction": "north",
"unit": "metre"
}
]
},
"id": {
"authority": "EPSG",
"code": 2993
}
},
"prettycompoundwkt": "PROJCS[\"NAD83(HARN) / Oregon LCC (m)\",\n GEOGCS[\"NAD83(HARN)\",\n DATUM[\"NAD83_High_Accuracy_Reference_Network\",\n SPHEROID[\"GRS 1980\",6378137,298.257222101,\n AUTHORITY[\"EPSG\",\"7019\"]],\n AUTHORITY[\"EPSG\",\"6152\"]],\n PRIMEM[\"Greenwich\",0,\n AUTHORITY[\"EPSG\",\"8901\"]],\n UNIT[\"degree\",0.0174532925199433,\n AUTHORITY[\"EPSG\",\"9122\"]],\n AUTHORITY[\"EPSG\",\"4152\"]],\n PROJECTION[\"Lambert_Conformal_Conic_2SP\"],\n PARAMETER[\"latitude_of_origin\",41.75],\n PARAMETER[\"central_meridian\",-120.5],\n PARAMETER[\"standard_parallel_1\",43],\n PARAMETER[\"standard_parallel_2\",45.5],\n PARAMETER[\"false_easting\",400000],\n PARAMETER[\"false_northing\",0],\n UNIT[\"metre\",1,\n AUTHORITY[\"EPSG\",\"9001\"]],\n AXIS[\"Easting\",EAST],\n AXIS[\"Northing\",NORTH],\n AUTHORITY[\"EPSG\",\"2993\"]]",
"prettywkt": "PROJCS[\"NAD83(HARN) / Oregon LCC (m)\",\n GEOGCS[\"NAD83(HARN)\",\n DATUM[\"NAD83_High_Accuracy_Reference_Network\",\n SPHEROID[\"GRS 1980\",6378137,298.257222101,\n AUTHORITY[\"EPSG\",\"7019\"]],\n AUTHORITY[\"EPSG\",\"6152\"]],\n PRIMEM[\"Greenwich\",0,\n AUTHORITY[\"EPSG\",\"8901\"]],\n UNIT[\"degree\",0.0174532925199433,\n AUTHORITY[\"EPSG\",\"9122\"]],\n AUTHORITY[\"EPSG\",\"4152\"]],\n PROJECTION[\"Lambert_Conformal_Conic_2SP\"],\n PARAMETER[\"latitude_of_origin\",41.75],\n PARAMETER[\"central_meridian\",-120.5],\n PARAMETER[\"standard_parallel_1\",43],\n PARAMETER[\"standard_parallel_2\",45.5],\n PARAMETER[\"false_easting\",400000],\n PARAMETER[\"false_northing\",0],\n UNIT[\"metre\",1,\n AUTHORITY[\"EPSG\",\"9001\"]],\n AXIS[\"Easting\",EAST],\n AXIS[\"Northing\",NORTH],\n AUTHORITY[\"EPSG\",\"2993\"]]",
"proj4": "+proj=lcc +lat_0=41.75 +lon_0=-120.5 +lat_1=43 +lat_2=45.5 +x_0=400000 +y_0=0 +ellps=GRS80 +units=m +no_defs",
"units":
{
"horizontal": "metre",
"vertical": ""
},
"vertical": "",
"wkt": "PROJCS[\"NAD83(HARN) / Oregon LCC (m)\",GEOGCS[\"NAD83(HARN)\",DATUM[\"NAD83_High_Accuracy_Reference_Network\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6152\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4152\"]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"latitude_of_origin\",41.75],PARAMETER[\"central_meridian\",-120.5],PARAMETER[\"standard_parallel_1\",43],PARAMETER[\"standard_parallel_2\",45.5],PARAMETER[\"false_easting\",400000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH],AUTHORITY[\"EPSG\",\"2993\"]]"
}
}
}
9 changes: 8 additions & 1 deletion core/src/test/scala/io/pdal/PipelineSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,14 @@ class PipelineSpec extends TestEnvironmentSpec {
}

it("should get quickInfo") {
parser.parse(pipeline.getQuickInfo()) shouldBe quickInfoJson
val p = Pipeline(json)
parser.parse(p.getQuickInfo()) shouldBe quickInfoJson
}

it("should get quickInfo with metadata") {
val p = Pipeline(json)
p.execute()
parser.parse(p.getQuickInfo()) shouldBe quickInfoWithMetadataJson
}

it("should extract mesh in iterative fashion") {
Expand Down
1 change: 1 addition & 0 deletions core/src/test/scala/io/pdal/TestEnvironmentSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ trait TestEnvironmentSpec extends AnyFunSpec with Matchers with BeforeAndAfterAl
val schemaJson: Either[ParsingFailure, Json] = parser.parse(getJson("/schema.json"))
val metadataJson: Either[ParsingFailure, Json] = parser.parse(getJson("/metadata.json"))
val quickInfoJson: Either[ParsingFailure, Json] = parser.parse(getJson("/quick-info.json"))
val quickInfoWithMetadataJson: Either[ParsingFailure, Json] = parser.parse(getJson("/quick-info-with-metadata.json"))

val proj4String =
"+proj=lcc +lat_0=41.75 +lon_0=-120.5 +lat_1=43 +lat_2=45.5 +x_0=400000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
Expand Down
71 changes: 39 additions & 32 deletions native/src/JavaPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,38 @@
#include <pdal/XMLSchema.hpp>
#endif

#include <pdal/util/Utils.hpp>

using pdal::LogPtr;
using pdal::MetadataNode;
using pdal::PointId;
using pdal::PointViewSet;
using pdal::PointTableRef;
using pdal::Stage;
using pdal::point_count_t;

using std::string;
using std::stringstream;
using std::vector;

namespace libpdaljava
{

void CountPointTable::reset()
{
for (pdal::PointId idx = 0; idx < numPoints(); idx++)
for (PointId idx = 0; idx < numPoints(); idx++)
if (!skip(idx))
m_count++;
FixedPointTable::reset();
}

PipelineExecutor::PipelineExecutor(std::string const& json, int level)
PipelineExecutor::PipelineExecutor(string const& json, int level)
{
setLogLevel(level);

pdal::LogPtr log(pdal::Log::makeLog("javapipeline", &m_logStream));
LogPtr log(pdal::Log::makeLog("javapipeline", &m_logStream));
log->setLevel(m_logLevel);
m_manager.setLog(log);

std::stringstream strm;
stringstream strm;
strm << json;
m_manager.readPipeline(strm);

Expand All @@ -73,10 +80,10 @@ bool PipelineExecutor::validate()
return true;
}

pdal::point_count_t PipelineExecutor::execute()
point_count_t PipelineExecutor::execute()
{

pdal::point_count_t count = m_manager.execute();
point_count_t count = m_manager.execute();
m_executed = true;
return count;
}
Expand All @@ -97,49 +104,49 @@ const PointViewSet& PipelineExecutor::views() const
return m_manager.views();
}

std::string PipelineExecutor::getSrsWKT2() const
string PipelineExecutor::getSrsWKT2() const
{
std::string output("");
pdal::PointTableRef pointTable = m_manager.pointTable();
string output("");
PointTableRef pointTable = m_manager.pointTable();

pdal::SpatialReference srs = pointTable.spatialReference();
output = srs.getWKT();

return output;
}

std::string PipelineExecutor::getPipeline() const
string PipelineExecutor::getPipeline() const
{
std::stringstream strm;
stringstream strm;
pdal::PipelineWriter::writePipeline(m_manager.getStage(), strm);
return strm.str();
}


std::string PipelineExecutor::getMetadata() const
string PipelineExecutor::getMetadata() const
{
if (!m_executed)
throw java_error("Pipeline has not been executed!");

std::stringstream strm;
pdal::MetadataNode root = m_manager.getMetadata().clone("metadata");
stringstream strm;
MetadataNode root = m_manager.getMetadata().clone("metadata");
pdal::Utils::toJSON(root, strm);
return strm.str();
}


std::string PipelineExecutor::getSchema() const
string PipelineExecutor::getSchema() const
{
if (!m_executed)
throw java_error("Pipeline has not been executed!");

std::stringstream strm;
pdal::MetadataNode root = pointTable().layout()->toMetadata().clone("schema");
stringstream strm;
MetadataNode root = pointTable().layout()->toMetadata().clone("schema");
pdal::Utils::toJSON(root, strm);
return strm.str();
}

pdal::MetadataNode computePreview(pdal::Stage* stage)
MetadataNode computePreview(pdal::Stage* stage)
{
if (!stage)
throw java_error("no valid stage in QuickInfo");
Expand All @@ -150,21 +157,21 @@ pdal::MetadataNode computePreview(pdal::Stage* stage)
if (!qi.valid())
throw java_error("No summary data available for stage '" + stage->getName()+"'" );

std::stringstream strm;
pdal::MetadataNode summary(stage->getName());
stringstream strm;
MetadataNode summary(stage->getName());
summary.add("num_points", qi.m_pointCount);
if (qi.m_srs.valid())
{
pdal::MetadataNode srs = qi.m_srs.toMetadata();
MetadataNode srs = qi.m_srs.toMetadata();
summary.add(srs);
}
if (qi.m_bounds.valid())
{
pdal::MetadataNode bounds = pdal::Utils::toMetadata(qi.m_bounds);
MetadataNode bounds = pdal::Utils::toMetadata(qi.m_bounds);
summary.add(bounds.clone("bounds"));
}

std::string dims;
string dims;
auto di = qi.m_dimNames.begin();

while (di != qi.m_dimNames.end())
Expand All @@ -181,12 +188,12 @@ pdal::MetadataNode computePreview(pdal::Stage* stage)
}


std::string PipelineExecutor::getQuickInfo() const
string PipelineExecutor::getQuickInfo() const
{

pdal::Stage* stage(nullptr);
std::vector<pdal::Stage *> stages = m_manager.stages();
std::vector<pdal::Stage *> previewStages;
vector<Stage *> stages = m_manager.stages();
vector<Stage *> previewStages;

for (auto const& s: stages)
{
Expand All @@ -197,22 +204,22 @@ std::string PipelineExecutor::getQuickInfo() const
previewStages.push_back(s);
}

pdal::MetadataNode summary;
MetadataNode summary;
for (auto const& stage: previewStages)
{
pdal::MetadataNode n = computePreview(stage);
MetadataNode n = computePreview(stage);
summary.add(n);
}

std::stringstream strm;
stringstream strm;
pdal::Utils::toJSON(summary, strm);
return strm.str();
}

void PipelineExecutor::setLogStream(std::ostream& strm)
{

pdal::LogPtr log(pdal::Log::makeLog("javapipeline", &strm));
LogPtr log(pdal::Log::makeLog("javapipeline", &strm));
log->setLevel(m_logLevel);
m_manager.setLog(log);
}
Expand Down
1 change: 1 addition & 0 deletions native/src/include/JavaPipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <pdal/PipelineManager.hpp>
#include <pdal/PipelineWriter.hpp>
#include <pdal/util/FileUtils.hpp>
#include <pdal/util/Utils.hpp>
#include <pdal/Stage.hpp>

#include <string>
Expand Down
Loading

0 comments on commit 24e50ce

Please sign in to comment.