From e888e9621cb30e1f1d49154664d129d8b04ec552 Mon Sep 17 00:00:00 2001 From: Andreas Ekstrand Date: Tue, 3 Apr 2018 12:42:37 +0100 Subject: [PATCH] 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. --- src/osgPlugins/shp/ESRIShapeParser.cpp | 7 ++++--- src/osgPlugins/shp/ESRIShapeParser.h | 3 ++- src/osgPlugins/shp/ESRIShapeReaderWriter.cpp | 9 ++++++++- src/osgPlugins/shp/XBaseParser.cpp | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/osgPlugins/shp/ESRIShapeParser.cpp b/src/osgPlugins/shp/ESRIShapeParser.cpp index 299fbe5d2..4245f2232 100644 --- a/src/osgPlugins/shp/ESRIShapeParser.cpp +++ b/src/osgPlugins/shp/ESRIShapeParser.cpp @@ -12,9 +12,10 @@ using namespace ESRIShape; -ESRIShapeParser::ESRIShapeParser( const std::string fileName, bool useDouble ): +ESRIShapeParser::ESRIShapeParser(const std::string fileName, bool useDouble, bool keepSeparatePoints) : _valid(false), - _useDouble(useDouble) + _useDouble(useDouble), + _keepSeparatePoints(keepSeparatePoints) { int fd = 0; if( !fileName.empty() ) @@ -215,7 +216,7 @@ osg::Geode *ESRIShapeParser::getGeode() void ESRIShapeParser::_combinePointToMultipoint() { - if( !_valid ) return; + if (!_valid || _keepSeparatePoints) return; OSG_NOTICE<<"_combinePointToMultipoint()"< _geode; diff --git a/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp b/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp index faa997a13..abe9de05a 100644 --- a/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp +++ b/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp @@ -20,6 +20,7 @@ class ESRIShapeReaderWriter : public osgDB::ReaderWriter { supportsExtension("shp","Geospatial Shape file format"); 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"; } @@ -47,8 +48,14 @@ class ESRIShapeReaderWriter : public osgDB::ReaderWriter 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"); diff --git a/src/osgPlugins/shp/XBaseParser.cpp b/src/osgPlugins/shp/XBaseParser.cpp index ca06da466..61119ec9e 100644 --- a/src/osgPlugins/shp/XBaseParser.cpp +++ b/src/osgPlugins/shp/XBaseParser.cpp @@ -184,7 +184,7 @@ bool XBaseParser::parse(int fd) char* number = new char[it->_fieldLength + 1]; memcpy(number, recordPtr, it->_fieldLength); 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; break; }