The attached code (from the 3.6 branch) adds a keepSeparatePoints option to the SHP plugin which makes it possible to avoid merging point features into multi-points, in case you e.g. need to keep separate point attributes.

It also contains a fix in the Xbase DBF parser, converting a numeric shape attribute to double instead of integer. As stated in e.g. https://en.wikipedia.org/wiki/.dbf the numeric field can contain decimals.
This commit is contained in:
Andreas Ekstrand 2018-04-03 12:42:37 +01:00 committed by Robert Osfield
parent 3450b9fee8
commit e888e9621c
4 changed files with 15 additions and 6 deletions

View File

@ -12,9 +12,10 @@
using namespace ESRIShape; using namespace ESRIShape;
ESRIShapeParser::ESRIShapeParser( const std::string fileName, bool useDouble ): ESRIShapeParser::ESRIShapeParser(const std::string fileName, bool useDouble, bool keepSeparatePoints) :
_valid(false), _valid(false),
_useDouble(useDouble) _useDouble(useDouble),
_keepSeparatePoints(keepSeparatePoints)
{ {
int fd = 0; int fd = 0;
if( !fileName.empty() ) if( !fileName.empty() )
@ -215,7 +216,7 @@ osg::Geode *ESRIShapeParser::getGeode()
void ESRIShapeParser::_combinePointToMultipoint() void ESRIShapeParser::_combinePointToMultipoint()
{ {
if( !_valid ) return; if (!_valid || _keepSeparatePoints) return;
OSG_NOTICE<<"_combinePointToMultipoint()"<<std::endl; OSG_NOTICE<<"_combinePointToMultipoint()"<<std::endl;

View File

@ -61,7 +61,7 @@ class ESRIShapeParser
{ {
public: public:
ESRIShapeParser( const std::string fileName, bool useDouble); ESRIShapeParser( const std::string fileName, bool useDouble, bool keepSeparatePoints);
osg::Geode *getGeode(); osg::Geode *getGeode();
@ -81,6 +81,7 @@ class ESRIShapeParser
bool _valid; bool _valid;
bool _useDouble; bool _useDouble;
bool _keepSeparatePoints;
osg::ref_ptr<osg::Geode> _geode; osg::ref_ptr<osg::Geode> _geode;

View File

@ -20,6 +20,7 @@ class ESRIShapeReaderWriter : public osgDB::ReaderWriter
{ {
supportsExtension("shp","Geospatial Shape file format"); supportsExtension("shp","Geospatial Shape file format");
supportsOption("double","Read x,y,z data as double an stored as geometry in osg::Vec3dArray's."); supportsOption("double","Read x,y,z data as double an stored as geometry in osg::Vec3dArray's.");
supportsOption("keepSeparatePoints", "Avoid combining point features into multi-point.");
} }
virtual const char* className() const { return "ESRI Shape ReaderWriter"; } virtual const char* className() const { return "ESRI Shape ReaderWriter"; }
@ -47,8 +48,14 @@ class ESRIShapeReaderWriter : public osgDB::ReaderWriter
useDouble = true; useDouble = true;
} }
bool keepSeparatePoints = false;
if (options && options->getOptionString().find("keepSeparatePoints") != std::string::npos)
{
keepSeparatePoints = true;
}
ESRIShape::ESRIShapeParser sp(fileName, useDouble);
ESRIShape::ESRIShapeParser sp(fileName, useDouble, keepSeparatePoints);
std::string xbaseFileName(osgDB::getNameLessExtension(fileName) + ".dbf"); std::string xbaseFileName(osgDB::getNameLessExtension(fileName) + ".dbf");

View File

@ -184,7 +184,7 @@ bool XBaseParser::parse(int fd)
char* number = new char[it->_fieldLength + 1]; char* number = new char[it->_fieldLength + 1];
memcpy(number, recordPtr, it->_fieldLength); memcpy(number, recordPtr, it->_fieldLength);
number[it->_fieldLength] = 0; number[it->_fieldLength] = 0;
shapeAttributeList->push_back(osgSim::ShapeAttribute((const char *) it->_name, (int) atoi(number))); shapeAttributeList->push_back(osgSim::ShapeAttribute((const char *) it->_name, atof(number)));
delete [] number; delete [] number;
break; break;
} }