From David Callu, added support for automatically reading associate dbase files
This commit is contained in:
@@ -2,9 +2,14 @@
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/Registry>
|
||||
|
||||
#include "ESRIType.h"
|
||||
|
||||
#include "ESRIShape.h"
|
||||
#include "ESRIShapeParser.h"
|
||||
|
||||
#include "XBaseParser.h"
|
||||
|
||||
|
||||
class ESRIShapeReaderWriter : public osgDB::ReaderWriter
|
||||
{
|
||||
public:
|
||||
@@ -34,12 +39,38 @@ class ESRIShapeReaderWriter : public osgDB::ReaderWriter
|
||||
{
|
||||
useDouble = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ESRIShape::ESRIShapeParser sp(fileName, useDouble);
|
||||
|
||||
|
||||
std::string xbaseFileName(osgDB::getNameLessExtension(fileName) + ".dbf");
|
||||
ESRIShape::XBaseParser xbp(xbaseFileName);
|
||||
|
||||
|
||||
if (sp.getGeode() && (xbp.getAttributeList().empty() == false))
|
||||
{
|
||||
if (sp.getGeode()->getNumDrawables() != xbp.getAttributeList().size())
|
||||
{
|
||||
osg::notify(osg::WARN) << "ESRIShape loader : .dbf file containe different record number that .shp file." << std::endl
|
||||
<< " .dbf record skipped." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::Geode * geode = sp.getGeode();
|
||||
unsigned int i = 0;
|
||||
|
||||
ESRIShape::XBaseParser::ShapeAttributeListList::iterator it, end = xbp.getAttributeList().end();
|
||||
for (it = xbp.getAttributeList().begin(); it != end; ++it, ++i)
|
||||
{
|
||||
geode->getDrawable(i)->setUserData(it->get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return sp.getGeode();
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
REGISTER_OSGPLUGIN(shp, ESRIShapeReaderWriter)
|
||||
|
||||
Reference in New Issue
Block a user