GeoTessCPP 2.6.1 Software to facilitate storage and retrieval of 3D information about the Earth.

Loading...
Searching...
No Matches
GeoTessPolygonFactory.h
Go to the documentation of this file.
1//- ****************************************************************************
2//-
3//- Copyright 2009 Sandia Corporation. Under the terms of Contract
4//- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
5//- retains certain rights in this software.
6//-
7//- BSD Open Source License.
8//- All rights reserved.
9//-
10//- Redistribution and use in source and binary forms, with or without
11//- modification, are permitted provided that the following conditions are met:
12//-
13//- * Redistributions of source code must retain the above copyright notice,
14//- this list of conditions and the following disclaimer.
15//- * Redistributions in binary form must reproduce the above copyright
16//- notice, this list of conditions and the following disclaimer in the
17//- documentation and/or other materials provided with the distribution.
18//- * Neither the name of Sandia National Laboratories nor the names of its
19//- contributors may be used to endorse or promote products derived from
20//- this software without specific prior written permission.
21//-
22//- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23//- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24//- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25//- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26//- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27//- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28//- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29//- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30//- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31//- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32//- POSSIBILITY OF SUCH DAMAGE.
33//-
34//- ****************************************************************************
35
36#ifndef POLYGONFACTORY_H_
37#define POLYGONFACTORY_H_
38
39// **** _SYSTEM INCLUDES_ ******************************************************
40
41#include <cstdio>
42#include <iostream>
43#include <iomanip>
44#include <vector>
45
46// use standard library objects
47 using namespace std;
48
49// **** _LOCAL INCLUDES_ *******************************************************
50
51#include "CPPUtils.h"
52#include "GeoTessUtils.h"
53#include "GeoTessGreatCircle.h"
54#include "IFStreamAscii.h"
55
56// **** _BEGIN GEOTESS NAMESPACE_ **********************************************
57
58 namespace geotess {
59
60// **** _FORWARD REFERENCES_ ***************************************************
61
62// **** _CLASS DEFINITION_ *****************************************************
63
72 class GEOTESS_EXP_IMP GeoTessPolygonFactory
73{
74 public:
75
76 static GeoTessPolygon* getPolygon(string inputFileName)
77 {
78 if (inputFileName.find(".kmz", inputFileName.length() - 4) != string::npos
79 || inputFileName.find(".kml", inputFileName.length() - 4) != string::npos)
80 {
81 ostringstream os;
82 os << endl << "ERROR in Polygon::constructor" << endl
83 << "Cannot read files in kml or kmz format (Google Earth)." << endl
84 << "GeoTessExplorer has a utility to translate to ascii." << endl;
85 throw GeoTessException(os, __FILE__, __LINE__, 10201);
86 }
87
88 GeoTessPolygon* polygon = NULL;
89
90 vector<string> records;
91
92 IFStreamAscii input;
93 input.openForRead(inputFileName);
94 string line;
95 while (input.readLine(line))
96 {
97 line = CPPUtils::uppercase_string(CPPUtils::trim(line));
98 if (line.length() > 0 && line.find('#') != 0)
99 records.push_back(line);
100 }
101 input.close();
102
103 if (records[0].find("POLYGON3D") == 0)
104 {
105 polygon = new GeoTessPolygon3D();
106 polygon->loadAscii(records);
107 }
108 else
109 {
110 polygon = new GeoTessPolygon();
111 polygon->loadAscii(records);
112 }
113
114 return polygon;
115 }
116
117
118}; // end class PolygonFactory
119
120} // end namespace geotess
121
122#endif /* POLYGONFACTORY_H_ */
GEOTESS_EXP_IMP
#define GEOTESS_EXP_IMP
Definition CPPGlobals.h:71
CPPUtils.h
GeoTessGreatCircle.h
GeoTessUtils.h
IFStreamAscii.h
geotess::CPPUtils::trim
static string trim(const string &str, const string &delim=" \t")
geotess::CPPUtils::uppercase_string
static string uppercase_string(const string &str)
geotess::GeoTessException
An exception class for all GeoTess objects.
Definition GeoTessException.h:66
geotess::GeoTessPolygon3D
Extends Polygon by including information and constraints about the radial dimension.
Definition GeoTessPolygon3D.h:115
geotess::GeoTessPolygonFactory
Factory method with a static method getPolygon() that returns a pointer to either a Polygon or Polygo...
Definition GeoTessPolygonFactory.h:73
geotess::GeoTessPolygonFactory::getPolygon
static GeoTessPolygon * getPolygon(string inputFileName)
Definition GeoTessPolygonFactory.h:76
geotess::GeoTessPolygon
An ordered list of points on the surface of a unit sphere that define a closed polygon.
Definition GeoTessPolygon.h:112
geotess::IFStreamAscii
Opens ascii file for read and write access.
Definition IFStreamAscii.h:81
geotess::IFStreamAscii::readLine
bool readLine(string &ln)
geotess::IFStreamAscii::openForRead
void openForRead(const string &fn)
geotess::IFStreamAscii::close
void close()
Definition IFStreamAscii.h:198
geotess
Definition ArrayReuse.h:55