DM_get_by_id.cpp
// =================================================================
// Each object that is inserted into odm gets a unique 64bit id that
// can be used for directly accessing the object.
//
// The following example creates an odm that contains two points, a
// polygon and a polygon. First the ids of the objects are collected
// and then used to access them by the getGeometry function
// =================================================================
#include <iostream>
#include "DM/Datamanager.hpp"
#include "DM/IAddInfoLayoutFactory.hpp"
#include "DM/IPolylineFactory.hpp"
#include "DM/IPolygonFactory.hpp"
int64_t output_type_and_id(const DM::IGeometry &obj, DM::AddInfoLayoutHandle layout)
{
int64_t id;
std::cout << "\t";
switch(obj.type())
{
{
const DM::IPoint &pt = *(dynamic_cast<const DM::IPoint *>(&obj));
pt.getAsInt64ByView(layout,0,id);
std::cout << "Type: point ";
break;
}
{
const DM::IPolyline &line = *(dynamic_cast<const DM::IPolyline *>(&obj));
line.getAsInt64ByView(layout,0,id);
std::cout << "Type: polyline";
break;
}
{
const DM::IPolygon &poly = *(dynamic_cast<const DM::IPolygon *>(&obj));
poly.getAsInt64ByView(layout,0,id);
std::cout << "Type: polygon ";
break;
}
default:
std::cout << "Type: unkown ";
}
std::cout << " Id: " << id;
return id;
}
void DM_get_by_id()
{
DM::AddInfoLayoutFactoryHandle f = DM::IAddInfoLayoutFactory::New();
f->addColumn(DM::ColumnSemantic::Id);
DM::AddInfoLayoutHandle layout = f->getLayout();
if (odm == DM::DatamanagerHandle())
return;
DM::PointHandle pt1 = DM::IPoint::New(0,0,0);
DM::PointHandle pt2 = DM::IPoint::New(10,0,0);
odm->addPoint(*pt1);
odm->addPoint(*pt2);
DM::PolylineFactoryHandle lf = DM::IPolylineFactory::New();
lf->addPoint(0,0,0);
lf->addPoint(1,0,0);
lf->addPoint(1,1,0);
lf->addPoint(0,1,0);
DM::PolylineHandle line = lf->getPolyline();
odm->addPolyline(*line);
DM::PolygonFactoryHandle pf = DM::IPolygonFactory::New();
pf->addPoint(0,5,0);
pf->addPoint(0,6,0);
pf->addPoint(1,6,0);
pf->addPoint(1,5,0);
pf->closePart();
DM::PolygonHandle poly = pf->getPolygon();
odm->addPolygon(*poly);
odm->save();
std::cout << "List objects within odm:" << std::endl;
std::vector<int64_t> ids;
for(auto it = odm->beginGeometry(); it != odm->endGeometry(); ++it)
{
int64_t id = output_type_and_id(*it,layout);
ids.push_back(id);
std::cout << std::endl;
}
std::cout << std::endl << "Access objects by id:" << std::endl;
for(auto it= ids.cbegin(); it!= ids.cend(); ++it)
{
DM::GeometryHandle obj = odm->getGeometry(*it);
output_type_and_id(*obj,layout);
std::cout << " (check id: "<< *it << ")" << std::endl;
}
}
@ polyline
polyline type
interface to a 2.5d polygon of arbitrary complexity
Definition: IPolygon.hpp:33
Definition: Handle.hpp:427
static IDatamanager * create(const char *filename, bool threadSafety=true)
@ odm
OPALS Datamanager file.
Definition: IPolyline.hpp:14
@ point
point type
virtual GeometryType type() const =0
get geometry type (kind of runtime type information)
@ polygon
polygon type
Base class of all geometry objects.
Definition: IGeometry.hpp:26
Smart pointer class using reference counting with support for DM objects (see ObjectBase)
Definition: Handle.hpp:75
3d point object
Definition: IPoint.hpp:14