Skip to content

Commit

Permalink
Merge pull request #53 from AnalyticalGraphicsInc/geometry-srs
Browse files Browse the repository at this point in the history
Read SRS names from geometry tags
  • Loading branch information
jklimke authored Sep 25, 2019
2 parents e301c77 + 05bc233 commit 6b56983
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sources/include/citygml/citygmlfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace citygml {

CityModel* createCityModel(const std::string& id);
CityObject* createCityObject(const std::string& id, CityObject::CityObjectsType type);
Geometry* createGeometry(const std::string& id, const CityObject::CityObjectsType& cityObjType = CityObject::CityObjectsType::COT_All, unsigned int lod = 0);
Geometry* createGeometry(const std::string& id, const CityObject::CityObjectsType& cityObjType = CityObject::CityObjectsType::COT_All, unsigned int lod = 0, std::string srsName = "");

std::shared_ptr<Polygon> createPolygon(const std::string& id);
std::shared_ptr<LineString> createLineString(const std::string& id);
Expand Down
8 changes: 7 additions & 1 deletion sources/include/citygml/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ namespace citygml {
unsigned int lod() const;
void setLod(unsigned int lod);

// Access the srs of the implicit geometry
std::string getSRSName() const;
void setSRSName(const std::string& srsName);

void addPolygon(std::shared_ptr<Polygon> );
void addLineString(std::shared_ptr<LineString>);

Expand All @@ -74,14 +78,16 @@ namespace citygml {


protected:
Geometry( const std::string& id, GeometryType type = GeometryType::GT_Unknown, unsigned int lod = 0 );
Geometry( const std::string& id, GeometryType type = GeometryType::GT_Unknown, unsigned int lod = 0, std::string srsName = "" );

bool m_finished;

GeometryType m_type;

unsigned int m_lod;

std::string m_srsName;

std::vector<std::shared_ptr<Geometry> > m_childGeometries;

std::vector<std::shared_ptr<Polygon> > m_polygons;
Expand Down
4 changes: 2 additions & 2 deletions sources/src/citygml/citygmlfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ namespace citygml {

}

Geometry* CityGMLFactory::createGeometry(const std::string& id, const CityObject::CityObjectsType& cityObjType, unsigned int lod)
Geometry* CityGMLFactory::createGeometry(const std::string& id, const CityObject::CityObjectsType& cityObjType, unsigned int lod, std::string srsName)
{
Geometry* geom = new Geometry(id, mapCityObjectsTypeToGeometryType(cityObjType), lod);
Geometry* geom = new Geometry(id, mapCityObjectsTypeToGeometryType(cityObjType), lod, srsName);
appearanceTargetCreated(geom);
return geom;
}
Expand Down
13 changes: 11 additions & 2 deletions sources/src/citygml/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace citygml {

Geometry::Geometry(const std::string& id, Geometry::GeometryType type, unsigned int lod)
: AppearanceTarget( id ), m_finished(false), m_type( type ), m_lod( lod )
Geometry::Geometry(const std::string& id, Geometry::GeometryType type, unsigned int lod, std::string srsName)
: AppearanceTarget( id ), m_finished(false), m_type( type ), m_lod( lod ), m_srsName( srsName )
{

}
Expand Down Expand Up @@ -115,6 +115,15 @@ namespace citygml {
m_lod = lod;
}

std::string Geometry::getSRSName() const
{
return m_srsName;
}

void Geometry::setSRSName(const std::string& srsName)
{
m_srsName = srsName;
}

void Geometry::addPolygon( std::shared_ptr<Polygon> p )
{
Expand Down
9 changes: 8 additions & 1 deletion sources/src/parser/geocoordinatetransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,14 @@ namespace citygml {
//}
}

void GeoCoordinateTransformer::transform(Geometry& obj, GeoTransform& transformation) {
void GeoCoordinateTransformer::transform(Geometry& obj, GeoTransform& parentTransformation) {
GeoTransform transformation = parentTransformation;
transformation.setSourceSRS(parentTransformation.sourceURN());

// If geometry has a different SRS or object SRS is not defined
if (!obj.getSRSName().empty() && !transformation.hasSourceSRS(obj.getSRSName())) {
transformation.setSourceSRS(obj.getSRSName());
}

if (!transformation.valid()) {
CITYGML_LOG_WARN(m_logger, "No valid spatial reference system is given for Geometry with id '" << obj.getId() << "'. Child Polygons are not transformed"
Expand Down
4 changes: 3 additions & 1 deletion sources/src/parser/geometryelementparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ namespace citygml {
throw std::runtime_error("Unexpected start tag found.");
}

m_model = m_factory.createGeometry(attributes.getCityGMLIDAttribute(), m_parentType, m_lodLevel);
std::string srsName = attributes.getAttribute("srsName");

m_model = m_factory.createGeometry(attributes.getCityGMLIDAttribute(), m_parentType, m_lodLevel, srsName);
m_orientation = attributes.getAttribute("orientation", "+"); // A gml:OrientableSurface may define a negative orientation
return true;

Expand Down

0 comments on commit 6b56983

Please sign in to comment.