Skip to content
Snippets Groups Projects
Commit ff26db73 authored by Tom Fischer's avatar Tom Fischer
Browse files

Using logog logging in class SHPInterface and refomatting source code.

parent c491984c
No related branches found
No related tags found
No related merge requests found
/**
* \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--;
......
/**
* \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;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment