2
2
#include <osgDB/FileUtils>
3
3
#include <osgDB/Registry>
5
#include <osgTerrain/Locator>
5
9
#include "ESRIShape.h"
6
10
#include "ESRIShapeParser.h"
12
#include "XBaseParser.h"
8
15
class ESRIShapeReaderWriter : public osgDB::ReaderWriter
29
36
std::string fileName = osgDB::findDataFile(file, options);
30
37
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
32
ESRIShape::ESRIShapeParser sp(fileName);
39
bool useDouble = false;
40
if (options && options->getOptionString().find("double")!=std::string::npos)
46
ESRIShape::ESRIShapeParser sp(fileName, useDouble);
49
std::string xbaseFileName(osgDB::getNameLessExtension(fileName) + ".dbf");
50
ESRIShape::XBaseParser xbp(xbaseFileName);
53
if (sp.getGeode() && (xbp.getAttributeList().empty() == false))
55
if (sp.getGeode()->getNumDrawables() != xbp.getAttributeList().size())
57
osg::notify(osg::WARN) << "ESRIShape loader : .dbf file containe different record number that .shp file." << std::endl
58
<< " .dbf record skipped." << std::endl;
62
osg::Geode * geode = sp.getGeode();
65
ESRIShape::XBaseParser::ShapeAttributeListList::iterator it, end = xbp.getAttributeList().end();
66
for (it = xbp.getAttributeList().begin(); it != end; ++it, ++i)
68
geode->getDrawable(i)->setUserData(it->get());
76
std::string projFileName(osgDB::getNameLessExtension(fileName) + ".prj");
77
if (osgDB::fileExists(projFileName))
79
std::ifstream fin(projFileName.c_str());
82
std::string projstring;
87
fin.getline(readline, sizeof(readline));
88
if (!projstring.empty() && !fin.eof())
92
projstring += readline;
96
if (!projstring.empty())
98
osgTerrain::Locator* locator = new osgTerrain::Locator;
99
sp.getGeode()->setUserData(locator);
101
locator->setFormat("WKT");
102
locator->setCoordinateSystem(projstring);
103
locator->setDefinedInFile(false);
33
111
return sp.getGeode();
39
115
REGISTER_OSGPLUGIN(shp, ESRIShapeReaderWriter)