Skip to content

Commit

Permalink
Provide ordered SRSes in PointTable.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Dec 19, 2016
1 parent 5f26fee commit 0f15893
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
13 changes: 13 additions & 0 deletions pdal/PointTable.cpp
Expand Up @@ -47,6 +47,19 @@ MetadataNode BasePointTable::privateMetadata(const std::string& name)
}


void BasePointTable::addSpatialReference(const SpatialReference& spatialRef)
{
auto it = std::find(m_spatialRefs.begin(), m_spatialRefs.end(), spatialRef);

// If not found, add to the beginning.
if (it == m_spatialRefs.end())
m_spatialRefs.push_front(spatialRef);
// If not the first element, move the found element to the front.
else if (it != m_spatialRefs.begin())
m_spatialRefs.splice(m_spatialRefs.begin(), m_spatialRefs, it);
}


void SimplePointTable::setFieldInternal(Dimension::Id id, PointId idx,
const void *value)
{
Expand Down
8 changes: 4 additions & 4 deletions pdal/PointTable.hpp
Expand Up @@ -34,7 +34,7 @@

#pragma once

#include <set>
#include <list>
#include <vector>

#include "pdal/SpatialReference.hpp"
Expand All @@ -48,6 +48,7 @@ namespace pdal

class PDAL_DLL BasePointTable : public PointContainer
{
FRIEND_TEST(PointTable, srs);
friend class PointView;

protected:
Expand Down Expand Up @@ -75,8 +76,7 @@ class PDAL_DLL BasePointTable : public PointContainer
}
void clearSpatialReferences()
{ m_spatialRefs.clear(); }
void addSpatialReference(const SpatialReference& srs)
{ m_spatialRefs.insert(srs); }
void addSpatialReference(const SpatialReference& srs);
bool spatialReferenceUnique() const
{ return m_spatialRefs.size() == 1; }
SpatialReference spatialReference() const
Expand All @@ -103,7 +103,7 @@ class PDAL_DLL BasePointTable : public PointContainer

protected:
MetadataPtr m_metadata;
std::set<SpatialReference> m_spatialRefs;
std::list<SpatialReference> m_spatialRefs;
PointLayout& m_layoutRef;
};
typedef BasePointTable& PointTableRef;
Expand Down
28 changes: 27 additions & 1 deletion test/unit/PointTableTest.cpp
Expand Up @@ -38,7 +38,8 @@
#include <io/LasReader.hpp>
#include "Support.hpp"

using namespace pdal;
namespace pdal
{

TEST(PointTable, resolveType)
{
Expand Down Expand Up @@ -178,3 +179,28 @@ TEST(PointTable, userView)
EXPECT_TRUE(called);
}

TEST(PointTable, srs)
{
SpatialReference srs1("GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]");

SpatialReference srs2("PROJCS[\"WGS 84 / UTM zone 17N\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433],AUTHORITY[\"EPSG\",\"4326\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",-81],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"32617\"]]");

PointTable table;

table.addSpatialReference(srs1);
table.addSpatialReference(srs1);
EXPECT_TRUE(table.spatialReferenceUnique());
EXPECT_EQ(table.anySpatialReference(), srs1);

table.addSpatialReference(srs2);
EXPECT_FALSE(table.spatialReferenceUnique());
EXPECT_EQ(table.anySpatialReference(), srs2);
EXPECT_EQ(table.m_spatialRefs.size(), 2u);

table.addSpatialReference(srs1);
EXPECT_FALSE(table.spatialReferenceUnique());
EXPECT_EQ(table.anySpatialReference(), srs1);
EXPECT_EQ(table.m_spatialRefs.size(), 2u);
}

} // namespace

0 comments on commit 0f15893

Please sign in to comment.