diff --git a/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp b/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp index a292e5bb0..6dc4a38bd 100644 --- a/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp +++ b/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp @@ -2,9 +2,14 @@ #include #include +#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)