From 4a79644810c855a7fe2400b3aa93f10a79fab386 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 16 Dec 2007 16:18:58 +0000 Subject: [PATCH] Added support for automatically setting the coordinate system of a shapefile by reading associate .prj file --- src/osgPlugins/shp/CMakeLists.txt | 5 +-- src/osgPlugins/shp/ESRIShapeReaderWriter.cpp | 39 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/osgPlugins/shp/CMakeLists.txt b/src/osgPlugins/shp/CMakeLists.txt index 30c382cdd..0101731c8 100644 --- a/src/osgPlugins/shp/CMakeLists.txt +++ b/src/osgPlugins/shp/CMakeLists.txt @@ -1,8 +1,5 @@ -#this file is automatically generated - - SET(TARGET_SRC ESRIShape.cpp ESRIShapeParser.cpp ESRIShapeReaderWriter.cpp XBaseParser.cpp) SET(TARGET_H ESRIShape.h ESRIShapeParser.h XBaseParser.h) -SET(TARGET_ADDED_LIBRARIES osgSim ) +SET(TARGET_ADDED_LIBRARIES osgSim osgTerrain) #### end var setup ### SETUP_PLUGIN(shp) diff --git a/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp b/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp index 6dc4a38bd..aea1e4fc0 100644 --- a/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp +++ b/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp @@ -2,6 +2,8 @@ #include #include +#include + #include "ESRIType.h" #include "ESRIShape.h" @@ -68,7 +70,44 @@ class ESRIShapeReaderWriter : public osgDB::ReaderWriter } } + if (sp.getGeode()) + { + std::string projFileName(osgDB::getNameLessExtension(fileName) + ".prj"); + if (osgDB::fileExists(projFileName)) + { + std::ifstream fin(projFileName.c_str()); + if (fin) + { + std::string projstring; + while(!fin.eof()) + { + char readline[4096]; + *readline = 0; + fin.getline(readline, sizeof(readline)); + if (!projstring.empty() && !fin.eof()) + { + projstring += '\n'; + } + projstring += readline; + + } + + if (!projstring.empty()) + { + osgTerrain::Locator* locator = new osgTerrain::Locator; + sp.getGeode()->setUserData(locator); + + locator->setFormat("WKT"); + locator->setCoordinateSystem(projstring); + locator->setDefinedInFile(false); + } + } + + } + + + } return sp.getGeode(); } };