26 #include "../../../geometry/Geometry.h" 27 #include "../../../geometry/WKBReader.h" 44 m_file.reset(
new std::ifstream(fileName, std::ios::in | std::ios::binary));
45 m_posFile.reset(
new std::ifstream((fileName+std::string(
".pos")).c_str(), std::ios::in | std::ios::binary));
57 unsigned int id =
m_i;
65 m_posFile->seekg(
id*
sizeof(
unsigned int), std::ios::beg);
66 m_posFile->read((
char*)&gPos,
sizeof(
unsigned int));
71 m_file->seekg(gPos, std::ios::beg);
73 m_file->read((
char*)&gSize,
sizeof(
unsigned int));
78 char* wkb =
new char[gSize];
94 std::string gFileName = std::string(fileName) +
".geom";
95 std::string posFileName = gFileName +
".pos";
97 std::ofstream gFile(gFileName.c_str(), std::ios::out | std::ios::binary);
98 std::ofstream gposFile(posFileName.c_str(), std::ios::out | std::ios::binary);
100 if(!gFile.is_open() || !gposFile.is_open())
103 unsigned int pos = 0;
105 for(std::map<int, te::gm::Geometry*>::const_iterator it = geoms.begin(); it != geoms.end(); ++it)
112 char * wkb = it->second->asBinary(gBSi);
114 gBS = (
unsigned int)gBSi;
117 gposFile.write((
char*)&pos,
sizeof(
unsigned int));
120 gFile.write((
char*)&gBS,
sizeof(
unsigned int));
121 gFile.write(wkb, gBS);
126 pos +=
sizeof(
unsigned int)+gBS;
135 std::string gFileName = std::string(fileName) +
".geom";
136 std::string posFileName = gFileName +
".pos";
137 std::string idsFileName = gFileName +
".ids";
139 std::ofstream gFile(gFileName.c_str(), std::ios::out | std::ios::binary);
140 std::ofstream gposFile(posFileName.c_str(), std::ios::out | std::ios::binary);
142 if(!gFile.is_open() || !gposFile.is_open())
145 unsigned int pos = 0;
147 for(std::vector<te::gm::Geometry*>::const_iterator it = geoms.begin(); it != geoms.end(); ++it)
154 char * wkb = (*it)->asBinary(gBSi);
156 gBS = (
unsigned int)gBSi;
159 gposFile.write((
char*)&pos,
sizeof(
unsigned int));
162 gFile.write((
char*)&gBS,
sizeof(
unsigned int));
163 gFile.write(wkb, gBS);
168 pos +=
sizeof(
unsigned int)+gBS;
void setGeometries(const std::vector< unsigned int > &gids)
Sets the desired geometries to get from file.
void openFile(const char *fileName)
Opens the file fileName.
~GeometryFile()
Destructor.
static void writeGeometries(const char *fileName, const std::map< int, te::gm::Geometry * > &geoms)
GeometryFile()
Constructor.
std::unique_ptr< std::ifstream > m_posFile
Pointer to the geometry pos file.
unsigned int m_i
Current position on traversing.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
std::vector< unsigned int > m_gids
Selected ids to use on traverse operation.
std::unique_ptr< std::ifstream > m_file
Pointer to the geometry file.
te::gm::Geometry * next()
Returns the next geometry.
static Geometry * read(const char *wkb)
It returns a valid geometry from a given WKB.