From ff26db730d35d1395b7ade9a65ea28ec7d35f4ef Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Thu, 10 Jan 2013 08:01:47 +0100 Subject: [PATCH] Using logog logging in class SHPInterface and refomatting source code. --- FileIO/SHPInterface.cpp | 124 ++++++++++++++++++++-------------------- FileIO/SHPInterface.h | 16 +++++- 2 files changed, 75 insertions(+), 65 deletions(-) diff --git a/FileIO/SHPInterface.cpp b/FileIO/SHPInterface.cpp index d8799c2a7e4..15ac7350d65 100644 --- a/FileIO/SHPInterface.cpp +++ b/FileIO/SHPInterface.cpp @@ -1,9 +1,21 @@ /** - * \file SHPInterface.cpp - * 25/01/2010 KR Initial implementation + * @copyright + * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + * @file SHPInterface.cpp + * @date 25/01/2010 + * @author Karsten Rink */ +// ThirdParty/logog +#include "logog/include/logog.hpp" + #include "SHPInterface.h" + +// BaseLib #include "StringTools.h" // MathLib @@ -11,15 +23,15 @@ bool SHPInterface::readSHPInfo(const std::string &filename, int &shapeType, int &numberOfEntities) { - SHPHandle hSHP = SHPOpen(filename.c_str(),"rb"); - if(!hSHP) + SHPHandle hSHP = SHPOpen(filename.c_str(), "rb"); + if (!hSHP) return false; double padfMinBound[4], padfMaxBound[4]; // The SHPGetInfo() function retrieves various information about shapefile as a whole. // The bounds are read from the file header, and may be inaccurate if the file was improperly generated. - SHPGetInfo( hSHP, &numberOfEntities, &shapeType, padfMinBound, padfMaxBound ); + SHPGetInfo(hSHP, &numberOfEntities, &shapeType, padfMinBound, padfMaxBound); SHPClose(hSHP); return true; @@ -30,35 +42,33 @@ void SHPInterface::readSHPFile(const std::string &filename, OGSType choice, std: int shapeType, numberOfElements; double padfMinBound[4], padfMaxBound[4]; - SHPHandle hSHP = SHPOpen(filename.c_str(),"rb"); - SHPGetInfo( hSHP, &numberOfElements, &shapeType, padfMinBound, padfMaxBound ); + SHPHandle hSHP = SHPOpen(filename.c_str(), "rb"); + SHPGetInfo(hSHP, &numberOfElements, &shapeType, padfMinBound, padfMaxBound); - if ( ((shapeType - 1) % 10 == 0) && (choice == SHPInterface::POINT) ) + if (((shapeType - 1) % 10 == 0) && (choice == SHPInterface::POINT)) readPoints(hSHP, numberOfElements, listName); - if ( ((shapeType - 1) % 10 == 0) && (choice == SHPInterface::STATION) ) + if (((shapeType - 1) % 10 == 0) && (choice == SHPInterface::STATION)) readStations(hSHP, numberOfElements, listName); - if ( ((shapeType - 3) % 10 == 0 || - (shapeType - 5) % 10 == 0) && (choice == SHPInterface::POLYLINE) ) + if (((shapeType - 3) % 10 == 0 || (shapeType - 5) % 10 == 0) && (choice + == SHPInterface::POLYLINE)) readPolylines(hSHP, numberOfElements, listName); - if ( ((shapeType - 3) % 10 == 0 || - (shapeType - 5) % 10 == 0) && (choice == SHPInterface::POLYGON) ) + if (((shapeType - 3) % 10 == 0 || (shapeType - 5) % 10 == 0) && (choice + == SHPInterface::POLYGON)) readPolygons(hSHP, numberOfElements, listName); } void SHPInterface::readPoints(const SHPHandle &hSHP, int numberOfElements, std::string listName) { - if (numberOfElements > 0) - { + if (numberOfElements > 0) { std::vector<GeoLib::Point*>* points = new std::vector<GeoLib::Point*>(); SHPObject* hSHPObject; - for (int i = 0; i < numberOfElements; i++) - { - hSHPObject = SHPReadObject(hSHP,i); + for (int i = 0; i < numberOfElements; i++) { + hSHPObject = SHPReadObject(hSHP, i); GeoLib::Point* pnt = - new GeoLib::Point( *(hSHPObject->padfX), *(hSHPObject->padfY), - *(hSHPObject->padfZ) ); + new GeoLib::Point(*(hSHPObject->padfX), *(hSHPObject->padfY), + *(hSHPObject->padfZ)); points->push_back(pnt); } @@ -69,19 +79,17 @@ void SHPInterface::readPoints(const SHPHandle &hSHP, int numberOfElements, std:: void SHPInterface::readStations(const SHPHandle &hSHP, int numberOfElements, std::string listName) { - if (numberOfElements > 0) - { - std::vector<GeoLib::Point*>* stations (new std::vector<GeoLib::Point*>); - stations->reserve (numberOfElements); + if (numberOfElements > 0) { + std::vector<GeoLib::Point*>* stations(new std::vector<GeoLib::Point*>); + stations->reserve(numberOfElements); SHPObject* hSHPObject; - for (int i = 0; i < numberOfElements; i++) - { - hSHPObject = SHPReadObject(hSHP,i); - GeoLib::Station* stn = - GeoLib::Station::createStation( BaseLib::number2str(i), *(hSHPObject->padfX), - *(hSHPObject->padfY), - *(hSHPObject->padfZ) ); + for (int i = 0; i < numberOfElements; i++) { + hSHPObject = SHPReadObject(hSHP, i); + GeoLib::Station* stn = GeoLib::Station::createStation(BaseLib::number2str(i), + *(hSHPObject->padfX), + *(hSHPObject->padfY), + *(hSHPObject->padfZ)); stations->push_back(stn); } @@ -92,33 +100,28 @@ void SHPInterface::readStations(const SHPHandle &hSHP, int numberOfElements, std void SHPInterface::readPolylines(const SHPHandle &hSHP, int numberOfElements, std::string listName) { - size_t noOfPoints = 0, noOfParts = 0; + std::size_t noOfPoints = 0, noOfParts = 0; std::vector<GeoLib::Point*>* points = new std::vector<GeoLib::Point*>(); std::vector<GeoLib::Polyline*>* lines = new std::vector<GeoLib::Polyline*>(); SHPObject* hSHPObject; // for each polyline) - for (int i = 0; i < numberOfElements; i++) - { - hSHPObject = SHPReadObject(hSHP,i); + for (int i = 0; i < numberOfElements; i++) { + hSHPObject = SHPReadObject(hSHP, i); noOfPoints = hSHPObject->nVertices; - noOfParts = hSHPObject->nParts; + noOfParts = hSHPObject->nParts; - for (size_t p = 0; p < noOfParts; p++) - { + for (std::size_t p = 0; p < noOfParts; p++) { int firstPnt = *(hSHPObject->panPartStart + p); - int lastPnt = - (p < (noOfParts - 1)) ? *(hSHPObject->panPartStart + p + 1) : noOfPoints; + int lastPnt = (p < (noOfParts - 1)) ? *(hSHPObject->panPartStart + p + 1) : noOfPoints; GeoLib::Polyline* line = new GeoLib::Polyline(*points); // for each point in that polyline - for (int j = firstPnt; j < lastPnt; j++) - { - GeoLib::Point* pnt = - new GeoLib::Point( *(hSHPObject->padfX + j), - *(hSHPObject->padfY + j), - *(hSHPObject->padfZ + j) ); + for (int j = firstPnt; j < lastPnt; j++) { + GeoLib::Point* pnt = new GeoLib::Point(*(hSHPObject->padfX + j), + *(hSHPObject->padfY + j), + *(hSHPObject->padfZ + j)); points->push_back(pnt); line->addPoint(points->size() - 1); } @@ -128,8 +131,7 @@ void SHPInterface::readPolylines(const SHPHandle &hSHP, int numberOfElements, st } } - if (numberOfElements > 0) - { + if (numberOfElements > 0) { // add points vector to GEOObjects (and check for duplicate points) _geoObjects->addPointVec(points, listName); @@ -145,14 +147,13 @@ void SHPInterface::readPolygons(const SHPHandle &hSHP, int numberOfElements, std { this->readPolylines(hSHP, numberOfElements, listName); - const std::vector<GeoLib::Polyline*>* polylines (_geoObjects->getPolylineVec(listName)); + const std::vector<GeoLib::Polyline*>* polylines(_geoObjects->getPolylineVec(listName)); std::vector<GeoLib::Surface*>* sfc_vec(new std::vector<GeoLib::Surface*>); - for (std::vector<GeoLib::Polyline*>::const_iterator poly_it (polylines->begin()); - poly_it != polylines->end(); poly_it++) - { - std::cout << "triangulation of Polygon with " << (*poly_it)->getNumberOfPoints() << - " points ... " << std::flush; + for (std::vector<GeoLib::Polyline*>::const_iterator poly_it(polylines->begin()); poly_it + != polylines->end(); poly_it++) { + INFO("SHPInterface::readPolygons(): Triangulation of Polygon with %d points.", + (*poly_it)->getNumberOfPoints()); sfc_vec->push_back(GeoLib::Surface::createSurface(*(*poly_it))); } @@ -160,17 +161,16 @@ void SHPInterface::readPolygons(const SHPHandle &hSHP, int numberOfElements, std _geoObjects->addSurfaceVec(sfc_vec, listName); } -void SHPInterface::adjustPolylines (std::vector<GeoLib::Polyline*>* lines, - std::vector<size_t> id_map) +void SHPInterface::adjustPolylines(std::vector<GeoLib::Polyline*>* lines, + std::vector<std::size_t> id_map) { - for (size_t i = 0; i < lines->size(); i++) - { - GeoLib::Polyline* line( (*lines)[i] ); - size_t previous_pnt_id (std::numeric_limits<size_t>::max()); + for (std::size_t i = 0; i < lines->size(); i++) { + GeoLib::Polyline* line((*lines)[i]); + std::size_t previous_pnt_id(std::numeric_limits<std::size_t>::max()); - for (size_t j = 0; j < line->getNumberOfPoints(); j++) { - size_t jth_pnt_id(id_map[line->getPointID(j)]); + for (std::size_t j = 0; j < line->getNumberOfPoints(); j++) { + std::size_t jth_pnt_id(id_map[line->getPointID(j)]); if (previous_pnt_id == jth_pnt_id) { line->removePoint(j); j--; diff --git a/FileIO/SHPInterface.h b/FileIO/SHPInterface.h index 6930a80add8..3cbe718abd7 100644 --- a/FileIO/SHPInterface.h +++ b/FileIO/SHPInterface.h @@ -1,7 +1,15 @@ /** - * \file SHPInterface.cpp - * 25/01/2010 KR Initial implementation + * @copyright + * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + * @file SHPInterface.h + * @date 25/01/2010 + * @author Karsten Rink */ + #ifndef SHPINTERFACE_H #define SHPINTERFACE_H @@ -10,6 +18,7 @@ //ShapeLib includes #include "shapefil.h" +// GeoLib #include "GEOObjects.h" /** @@ -50,7 +59,8 @@ private: /// Reads lines into a vector of Polyline and Surface objects. void readPolygons (const SHPHandle &hSHP, int numberOfElements, std::string listName); - void adjustPolylines (std::vector<GeoLib::Polyline*>* lines, std::vector<std::size_t> id_map); + void adjustPolylines (std::vector<GeoLib::Polyline*>* lines, + std::vector<std::size_t> id_map); GeoLib::GEOObjects* _geoObjects; }; -- GitLab