~ubuntu-branches/ubuntu/trusty/openscenegraph/trusty

« back to all changes in this revision

Viewing changes to OpenSceneGraph/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-07-29 04:34:38 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20080729043438-no1h9h0dpsrlzp1y
* Non-maintainer upload.
* No longer try to detect (using /proc/cpuinfo when available) how many
  CPUs are available, fixing the FTBFS (due to -j0) on various platforms
  (Closes: #477353). The right way to do it is to support parallel=n in
  DEB_BUILD_OPTIONS (see Debian Policy §4.9.1), and adequate support has
  been implemented.
* Add patch to fix FTBFS due to the build system now refusing to handle
  whitespaces (Policy CMP0004 say the logs), thanks to Andreas Putzo who
  provided it (Closes: #482239):
   - debian/patches/fix-cmp0004-build-failure.dpatch
* Remove myself from Uploaders, as requested a while ago, done by Luk in
  his 2.2.0-2.1 NMU, which was never acknowledged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include <osgDB/FileUtils>
3
3
#include <osgDB/Registry>
4
4
 
 
5
#include <osgTerrain/Locator>
 
6
 
 
7
#include "ESRIType.h"
 
8
 
5
9
#include "ESRIShape.h"
6
10
#include "ESRIShapeParser.h"
7
11
 
 
12
#include "XBaseParser.h"
 
13
 
 
14
 
8
15
class ESRIShapeReaderWriter : public osgDB::ReaderWriter
9
16
{
10
17
    public:
29
36
            std::string fileName = osgDB::findDataFile(file, options);
30
37
            if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
31
38
 
32
 
            ESRIShape::ESRIShapeParser sp(fileName);
 
39
            bool useDouble = false;
 
40
            if (options && options->getOptionString().find("double")!=std::string::npos)
 
41
            {
 
42
                useDouble = true;
 
43
            }
 
44
            
 
45
            
 
46
            ESRIShape::ESRIShapeParser sp(fileName, useDouble);
 
47
 
 
48
            
 
49
            std::string xbaseFileName(osgDB::getNameLessExtension(fileName) + ".dbf");
 
50
            ESRIShape::XBaseParser xbp(xbaseFileName);
 
51
            
 
52
            
 
53
            if (sp.getGeode() && (xbp.getAttributeList().empty() == false))
 
54
            {
 
55
                if (sp.getGeode()->getNumDrawables() != xbp.getAttributeList().size())
 
56
                {
 
57
                    osg::notify(osg::WARN) << "ESRIShape loader : .dbf file containe different record number that .shp file." << std::endl
 
58
                                           << "                   .dbf record skipped." << std::endl;
 
59
                }
 
60
                else
 
61
                {
 
62
                    osg::Geode * geode = sp.getGeode();
 
63
                    unsigned int i = 0;
 
64
                    
 
65
                    ESRIShape::XBaseParser::ShapeAttributeListList::iterator it, end = xbp.getAttributeList().end();
 
66
                    for (it = xbp.getAttributeList().begin(); it != end; ++it, ++i)
 
67
                    {
 
68
                        geode->getDrawable(i)->setUserData(it->get());
 
69
                    }
 
70
                }
 
71
            }    
 
72
 
 
73
            if (sp.getGeode())
 
74
            {
 
75
            
 
76
                std::string projFileName(osgDB::getNameLessExtension(fileName) + ".prj");
 
77
                if (osgDB::fileExists(projFileName))
 
78
                {
 
79
                    std::ifstream fin(projFileName.c_str());
 
80
                    if (fin)
 
81
                    {
 
82
                        std::string projstring;
 
83
                        while(!fin.eof())
 
84
                        {
 
85
                            char readline[4096];
 
86
                            *readline = 0;
 
87
                            fin.getline(readline, sizeof(readline));
 
88
                            if (!projstring.empty() && !fin.eof())
 
89
                            {
 
90
                                projstring += '\n';
 
91
                            }
 
92
                            projstring += readline;
 
93
 
 
94
                        }
 
95
                        
 
96
                        if (!projstring.empty())
 
97
                        {
 
98
                            osgTerrain::Locator* locator = new osgTerrain::Locator;
 
99
                            sp.getGeode()->setUserData(locator);
 
100
 
 
101
                            locator->setFormat("WKT");
 
102
                            locator->setCoordinateSystem(projstring);
 
103
                            locator->setDefinedInFile(false);
 
104
                        }
 
105
                    }
 
106
                    
 
107
                }
 
108
 
 
109
 
 
110
            }
33
111
            return sp.getGeode();
34
112
        }
35
 
 
36
 
    private:
37
113
};
38
114
 
39
115
REGISTER_OSGPLUGIN(shp, ESRIShapeReaderWriter)