Skip to content

Commit

Permalink
Merge pull request #51 from shehzan10/sourceSRS-option
Browse files Browse the repository at this point in the history
Add a source SRS CLI option
  • Loading branch information
jklimke authored Dec 2, 2018
2 parents b71d2e8 + d1f8254 commit 209e19e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sources/include/citygml/citygml.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace citygml
// pruneEmptyObjects: remove the objects which do not contains any geometrical entity
// tesselate: convert the interior & exteriors polygons to triangles
// destSRS: the SRS (WKT, EPSG, OGC URN, etc.) where the coordinates must be transformed, default ("") is no transformation
// srsSRS: the SRS (WKT, EPSG, OGC URN, etc.) to overrride the SRS in the CityGML data (if any), default ("") means no override or use included SRS

class LIBCITYGML_EXPORT ParserParams
{
Expand All @@ -70,6 +71,7 @@ namespace citygml
, optimize( false )
, pruneEmptyObjects( false )
, destSRS( "" )
, srcSRS( "" )
, keepVertices ( false )
{ }

Expand All @@ -82,6 +84,7 @@ namespace citygml
bool tesselate;
bool keepVertices;
std::string destSRS;
std::string srcSRS;
};

LIBCITYGML_EXPORT std::shared_ptr<const CityModel> load( std::istream& stream, const ParserParams& params, std::shared_ptr<CityGMLLogger> logger = nullptr);
Expand Down
2 changes: 2 additions & 0 deletions sources/include/parser/citygmldocumentparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace citygml {

std::shared_ptr<const CityModel> getModel();

const ParserParams getParserParams() const;

// Methods used by CityGMLElementParser

void setCurrentElementParser(ElementParser* parser);
Expand Down
4 changes: 4 additions & 0 deletions sources/include/parser/gmlfeaturecollectionparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ namespace citygml {
// GMLObjectElementParser interface
virtual Object* getObject() override;

const Envelope& getEnvelope() const;
bool getSourceSRSOverride() const;

private:
Envelope* m_bounds;
bool m_sourceSRSOverride;


};
Expand Down
5 changes: 5 additions & 0 deletions sources/src/parser/citygmldocumentparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ namespace citygml {
return m_rootModel;
}

const ParserParams CityGMLDocumentParser::getParserParams() const
{
return m_parserParams;
}

void CityGMLDocumentParser::setCurrentElementParser(ElementParser* parser)
{
m_parserStack.push(std::shared_ptr<ElementParser>(parser));
Expand Down
6 changes: 6 additions & 0 deletions sources/src/parser/citymodelelementparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ namespace citygml {
CITYGML_LOG_WARN(m_logger, "Expected end tag <" << NodeType::CORE_CityModelNode.name() << "> got <" << node.name() << "> at " << getDocumentLocation());
}

if (getSourceSRSOverride()) {
Envelope *envelope = new Envelope(getEnvelope().srsName());
envelope->setLowerBound(m_model->getEnvelope().getLowerBound());
envelope->setUpperBound(m_model->getEnvelope().getUpperBound());
m_model->setEnvelope(envelope);
}
m_callback(m_model);
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions sources/src/parser/cityobjectelementparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ namespace citygml {

bool CityObjectElementParser::parseElementEndTag(const NodeType::XMLNode&, const std::string&)
{
if (getSourceSRSOverride()) {
Envelope *envelope = new Envelope(getEnvelope().srsName());
envelope->setLowerBound(m_model->getEnvelope().getLowerBound());
envelope->setUpperBound(m_model->getEnvelope().getUpperBound());
m_model->setEnvelope(envelope);
}
m_callback(m_model);
m_model = nullptr;
return true;
Expand Down
18 changes: 18 additions & 0 deletions sources/src/parser/gmlfeaturecollectionparser.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "parser/gmlfeaturecollectionparser.h"

#include "parser/attributes.h"
#include "parser/citygmldocumentparser.h"
#include "parser/parserutils.hpp"
#include "parser/nodetypes.h"

Expand All @@ -19,6 +20,12 @@ namespace citygml {
: GMLObjectElementParser(documentParser, factory, logger)
{
m_bounds = nullptr;
m_sourceSRSOverride = false;
std::string paramsSrcSRS = documentParser.getParserParams().srcSRS;
if (!paramsSrcSRS.empty()) {
m_bounds = new Envelope(paramsSrcSRS);
m_sourceSRSOverride = true;
}
}

bool GMLFeatureCollectionElementParser::parseChildElementStartTag(const NodeType::XMLNode& node, Attributes& attributes)
Expand All @@ -33,6 +40,9 @@ namespace citygml {
return true;
} else if (node == NodeType::GML_EnvelopeNode) {

if (m_sourceSRSOverride) {
return true;
}
if (m_bounds != nullptr) {
CITYGML_LOG_WARN(m_logger, "Duplicate definition of " << NodeType::GML_EnvelopeNode << " at " << getDocumentLocation());
return true;
Expand Down Expand Up @@ -83,6 +93,14 @@ namespace citygml {
return getFeatureObject();
}

const Envelope& GMLFeatureCollectionElementParser::getEnvelope() const
{
return *m_bounds;
}

bool GMLFeatureCollectionElementParser::getSourceSRSOverride() const
{
return m_sourceSRSOverride;
}

}
1 change: 1 addition & 0 deletions test/citygmltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ int main( int argc, char **argv )
if ( param == "-log" ) { log = true; fargc = i+1; }
//if ( param == "-filter" ) { if ( i == argc - 1 ) usage(); params.objectsMask = argv[i+1]; i++; fargc = i+1; }
if ( param == "-destsrs" ) { if ( i == argc - 1 ) usage(); params.destSRS = argv[i+1]; i++; fargc = i+1; }
if ( param == "-srcsrs" ) { if ( i == argc - 1 ) usage(); params.srcSRS = argv[i+1]; i++; fargc = i+1; }
}

if ( argc - fargc < 1 ) usage();
Expand Down

0 comments on commit 209e19e

Please sign in to comment.