Skip to content

Commit

Permalink
Set SRS if it hasn't been overridden by an option.
Browse files Browse the repository at this point in the history
Close #2194
  • Loading branch information
abellgithub committed Oct 3, 2018
1 parent c226abe commit 4a91c69
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 25 deletions.
7 changes: 3 additions & 4 deletions io/BpfReader.cpp
Expand Up @@ -168,13 +168,12 @@ void BpfReader::initialize()
<< "' and coordinate id: '" << m_header.m_coordId << "'";
throwError(oss.str());
}
SpatialReference srs(code);
setSpatialReference(srs);

try
{
SpatialReference srs(code);
setSpatialReference(srs);
// If there is no override SRS, set the file SRS.
if (getSpatialReference().empty())
setSpatialReference(code);
}
catch (...)
{
Expand Down
3 changes: 2 additions & 1 deletion io/EptReader.cpp
Expand Up @@ -115,7 +115,8 @@ void EptReader::initialize()
m_info.reset(new EptInfo(parse(m_ep->get("entwine.json"))));
log()->get(LogLevel::Debug) << "Got EPT info" << std::endl;

if (!m_info->srs().empty())
// Set spatial reference if it's not overriden.
if (getSpatialReference().empty())
setSpatialReference(m_info->srs());

// Figure out our query parameters.
Expand Down
4 changes: 3 additions & 1 deletion io/GDALReader.cpp
Expand Up @@ -73,7 +73,9 @@ void GDALReader::initialize()
m_raster->open();
try
{
setSpatialReference(m_raster->getSpatialRef());
// Set the SRS from the file if we don't have an override.
if (getSpatialReference().empty())
setSpatialReference(m_raster->getSpatialRef());
}
catch (...)
{
Expand Down
5 changes: 3 additions & 2 deletions io/Ilvis2Reader.cpp
Expand Up @@ -125,8 +125,9 @@ void Ilvis2Reader::initialize(PointTableRef)
// Data are WGS84 (4326) with ITRF2000 datum (6656)
// See http://nsidc.org/data/docs/daac/icebridge/ilvis2/index.html for
// background
SpatialReference ref("EPSG:4326");
setSpatialReference(m_metadata, ref);
// Set the SRS to the default if not overridden.
if (getSpatialReference().empty())
setSpatialReference(SpatialReference("EPSG:4326"));
}


Expand Down
13 changes: 8 additions & 5 deletions io/OptechReader.cpp
Expand Up @@ -77,11 +77,7 @@ OptechReader::OptechReader()
, m_recordIndex(0)
, m_returnIndex(0)
, m_pulse()
{
// The Optech docs say that their lat/longs are referenced
// to the WGS84 reference frame.
setSpatialReference(SpatialReference("EPSG:4326"));
}
{}


const CsdHeader& OptechReader::getHeader() const { return m_header; }
Expand Down Expand Up @@ -117,6 +113,13 @@ void OptechReader::initialize()
m_header.misalignmentAngles[0] + m_header.imuOffsets[0],
m_header.misalignmentAngles[1] + m_header.imuOffsets[1],
m_header.misalignmentAngles[2] + m_header.imuOffsets[2]);

// The Optech docs say that their lat/longs are referenced
// to the WGS84 reference frame.
// Set default SRS if not overridden.
SpatialReference srs = getSpatialReference();
if (getSpatialReference().empty())
setSpatialReference(SpatialReference("EPSG:4326"));
}


Expand Down
4 changes: 3 additions & 1 deletion io/TIndexReader.cpp
Expand Up @@ -172,7 +172,9 @@ void TIndexReader::initialize()
else
m_out_ref.reset(new gdal::SpatialRef(m_out_ref->wkt()));

setSpatialReference(SpatialReference(m_out_ref->wkt()));
// Set SRS if not overridden.
if (getSpatialReference().empty())
setSpatialReference(SpatialReference(m_out_ref->wkt()));

std::unique_ptr<gdal::Geometry> wkt_g;

Expand Down
2 changes: 1 addition & 1 deletion plugins/greyhound/io/GreyhoundReader.cpp
Expand Up @@ -101,7 +101,7 @@ void GreyhoundReader::initialize(PointTableRef table)
throw pdal_error(std::string("Failed to fetch info: ") + e.what());
}

if (m_info.isMember("srs"))
if (m_info.isMember("srs") && getSpatialReference().empty())
setSpatialReference(m_info["srs"].asString());
}

Expand Down
5 changes: 3 additions & 2 deletions plugins/icebridge/io/IcebridgeReader.cpp
Expand Up @@ -204,8 +204,9 @@ void IcebridgeReader::initialize()
// Data are WGS84 (4326) with ITRF2000 datum (6656)
// See http://nsidc.org/data/docs/daac/icebridge/ilvis2/index.html for
// background
SpatialReference ref("EPSG:4326");
setSpatialReference(m_metadata, ref);
// Set spatial reference if not overridden.
if (getSpatialReference().empty())
setSpatialReference(SpatialReference("EPSG:4326"));
}

void IcebridgeReader::done(PointTableRef table)
Expand Down
12 changes: 5 additions & 7 deletions plugins/matlab/io/MatlabReader.cpp
Expand Up @@ -71,19 +71,17 @@ void MatlabReader::initialize(PointTableRef table)
m_numElements = 0;
m_numFields = 0;

std::string wkt = mlang::Script::getSRSWKT(m_structArray, log());
if (wkt.size())
{
SpatialReference srs(wkt);
setSpatialReference(srs);
}
// Set SRS if not overridden.
if (getSpatialReference().empty())
setSpatialReference(mlang::Script::getSRSWKT(m_structArray, log()));
m_tableMetadata = table.metadata();
}


void MatlabReader::addArgs(ProgramArgs& args)
{
args.add("struct", "Name of struct to read from file", m_structName, "PDAL");
args.add("struct", "Name of struct to read from file",
m_structName, "PDAL");
}


Expand Down
4 changes: 3 additions & 1 deletion plugins/rdb/io/RdbReader.cpp
Expand Up @@ -144,7 +144,9 @@ void RdbReader::addArgs(ProgramArgs& args)
void RdbReader::initialize()
{
m_pointcloud.reset(new RdbPointcloud(m_filename, m_filter, m_extras));
setSpatialReference(getSpatialReferenceSystem(*m_pointcloud));
// Set spatial reference form source if not overridden.
if (getSpatialReference().empty())
setSpatialReference(getSpatialReferenceSystem(*m_pointcloud));
readMetadata(*m_pointcloud, getMetadata());
}

Expand Down
2 changes: 2 additions & 0 deletions test/unit/io/OptechReaderTest.cpp
Expand Up @@ -136,6 +136,8 @@ TEST_F(OptechReaderTest, ReadingPoints)
TEST_F(OptechReaderTest, Spatialreference)
{
SpatialReference expected("EPSG:4326");
PointTable table;
m_reader.prepare(table);
EXPECT_EQ(expected, m_reader.getSpatialReference());
}
}

0 comments on commit 4a91c69

Please sign in to comment.