VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
shapefile.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2003 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 /*******************************************************************************
6 ** $RCSfile: shapefile.h,v $ $Revision: 1.21 $ $State: Exp $
7 *******************************************************************************/
8 
9 #ifndef shapefile_H_
10 #define shapefile_H_
11 
12 #include "shape/shapeDefines.h"
13 #include <vlutil/vlFilename.h>
14 #include <vlutil/vlNetTypes.h>
15 #include <vlutil/vlList.h>
16 #include <vlutil/vlHashlist.h>
18 
19 class DtShapeEntry;
20 class DtShapeHeader;
21 class DtShapeReader;
24 class DtShapeInitializer;
26 class DtGroup;
27 class DtGeodeticCoord;
28 
29 class DtVectorNetwork;
30 
31 typedef void (*DtRealShapeImportFcn)(const char* feature, DtReal& value);
32 typedef void (*DtIntegerShapeImportFcn)(const char* feature, int& value);
33 typedef void (*DtStringShapeImportFcn)(const char* feature, DtString& value);
34 
35 //
36 // DtShapefile is the base class for DtShapeFeatureFile and DtShapeTerrainFile.
37 // It provides the interface for reading shape files, and the capability to
38 // read the associated .dbf dBASE files.
39 //
41 {
42 
43 public:
44 
45  // Constructor
47 
48  // Constructor
50 
51  // Destructor
52  virtual ~DtShapefile();
53 
54 private:
55  // Copy constructor and Assignment operator not implemented
56  DtShapefile(const DtShapefile& original);
57  DtShapefile& operator=(const DtShapefile& original);
58 
59 public:
60 
61  // Registers default dBASE import functions. Override this function to
62  // change or add import functions.
63  virtual void init();
64 
65  // Opens the given file and adds each DtShapeRecord to myList
66  virtual bool load(const DtFilename& path, const DtShapeEntry* entry);
67 
68  // Overridden by subclasses to process the DtShapeReader
69  virtual DtGroup* import(DtShapeReader* db) = 0;
70 
71  // Overridden by subclasses to process the DtShapeVectorReader
72  virtual bool importFeatures(DtShapeVectorReader* db) = 0;
73 
74  // Returns myHeader->myBoundingBox[0]
75  virtual double xMin();
76  // Returns myHeader->myBoundingBox[1];
77  virtual double yMin();
78  // Returns myHeader->myBoundingBox[2];
79  virtual double xMax();
80  // Returns myHeader->myBoundingBox[3];
81  virtual double yMax();
82 
83  // Returns myList
84  virtual DtList &list();
85 
86 
87  //
88  // dBASE import functions
89  //
90 
91  // Associates the given dBASE type with a DtRealShapeImportFcn that can
92  // convert it to a DtReal.
93  virtual void setRealImportFunction(const char type, DtRealShapeImportFcn fcn);
94  // Finds the DtRealShapeImportFcn associated with the give dBASE type
95  virtual DtRealShapeImportFcn lookupRealImportFunction(const char type);
96  // Converts the feature (as returned from readFeature) to a DtReal value
97  static void importNumberAsReal(const char* feature, DtReal& value);
98 
99  // Associates the given dBASE type with a DtIntegerShapeImportFcn that can
100  // convert it to a int.
101  virtual void setIntegerImportFunction(const char type, DtIntegerShapeImportFcn fcn);
102  // Finds the DtIntegerShapeImportFcn associated with the give dBASE type
103  virtual DtIntegerShapeImportFcn lookupIntegerImportFunction(const char type);
104  // Converts the feature (as returned from readFeature) to an int value
105  static void importNumberAsInteger(const char* feature, int& value);
106 
107  // Associates the given dBASE type with a DtStringShapeImportFcn that can
108  // convert it to a DtString.
109  virtual void setStringImportFunction(const char type, DtStringShapeImportFcn fcn);
110  // Finds the DtStringShapeImportFcn associated with the give dBASE type
111  virtual DtStringShapeImportFcn lookupStringImportFunction(const char type);
112  // Converts the feature (as returned from readFeature) to a DtString value
113  static void importCharAsString(const char* feature, DtString& value);
114 
115  virtual DtString projectionType() const;
116 
117  DtShapeProjection* projectionInformation() const;
118 
119  static void setShapeProjectionCreatorFcn(DtShapeProjectionCreatorFcn);
120 
121  // Returns a coordinate system from the shape projection (if exists). NULL if not.
122  // Caller must free returned pointer
123  virtual Coordinate_System* coordinateSystem() const;
124 
125  // Gets lower left/upper right corners in geodetic
126  virtual void getCorners(DtGeodeticCoord& ll, DtGeodeticCoord& ur);
127 
128  // @name Open/close dBASE file functions
129  // @{
130  // Opens and closes the .dbf dBASE file associated with the shape file,
131  // initializing the myDbfFile pointer.
132  // The ESRI shape standard requires them to have the same name prefix.
133  // The caller is responsible for closing the myDbfFile pointer.
134  virtual bool openDbf();
135 
136  // Given shapefile and path, opens .dbf file associated with it
137  virtual bool openDbf(const DtFilename&);
138 
139  virtual bool closeDbf();
140  // @}
141 
142  // @name Column dBASE file functions
143  // @{
144  // Returns information about columns
145 
146  // Returns number of columns in dbf file
147  virtual int numDbfColumns() const;
148  virtual bool column(int col, DtString& colName, char& colType, unsigned char& colLength);
149  // @}
150 
151  // Tries to load and parse .prj file based on current shape file to get projection information. Builds
152  // a hash list (key/value pair) of all information found
153  virtual void loadProjectionFile();
154 
155 protected:
156 
157  // Locates the record with the given featureName and featureNumber, allocates
158  // a string for the data, and returns the dBASE type ('C', 'N', etc.) in
159  // fieldType. The caller is responsible for freeing the returned pointer!
160  virtual char* readFeature(const DtString& featureName, int featureNumber,
161  char& fieldType);
162 
163  // Calls readFeature with the given featureName and featureNumber, then
164  // sets the value using the import function returned from
165  // lookupRealImportFunction
166  virtual bool readFeatureAsReal(const DtString& featureName, int featureNumber, DtReal& value);
167 
168  // Calls readFeature with the given featureName and featureNumber, then
169  // sets the value using the import function returned from
170  // lookupIntegerImportFunction
171  virtual bool readFeatureAsInteger(const DtString& featureName, int featureNumber, int& value);
172 
173  // Calls readFeature with the given featureName and featureNumber, then
174  // sets the value using the import function returned from
175  // lookupStringImportFunction
176  virtual bool readFeatureAsString(const DtString& featureName,
177  int featureNumber, DtString& value);
178 
179 protected:
180 
183 
185  DtFilename myFilename;
187  DtList myList;
190 
191  // .dbf file -- should be opened only for the duration of the import!
192  FILE* myDbfFile;
193  DtNetInt32 myDbfRecordCount;
194  DtNetInt16 myDbfRecordSize;
195  DtNetInt16 myDbfHeaderSize;
196 
200 
201  // Contains the projection type (string) that should be used to convert points
202  // from a non-geodetic source to a geodetic (degree) source
204 
206 };
207 
209 {
211 }
212 
213 #endif
DtShapeReader * myReader
Definition: shapefile.h:188
const DtShapeEntry * myEntry
Definition: shapefile.h:184
Definition: shapeHeader.h:17
Definition: shapeVectorReader.h:29
DtList myList
Definition: shapefile.h:187
Definition: shapeProjectionInformation.h:68
Definition: group.h:28
DtHashlist myStringImportFunctions
Definition: shapefile.h:199
DtShapeHeader * myHeader
Definition: shapefile.h:186
DtHashlist myIntegerImportFunctions
Definition: shapefile.h:198
DtHashlist myRealImportFunctions
Definition: shapefile.h:197
FILE * myDbfFile
Definition: shapefile.h:192
const DtShapeVectorInitializer * myVectorInitializer
Definition: shapefile.h:182
DtFilename myFilename
Definition: shapefile.h:185
DtShapeProjection * projectionInformation() const
Definition: shapefile.h:208
void(* DtIntegerShapeImportFcn)(const char *feature, int &value)
Definition: shapefile.h:32
Definition: coordSystem.h:54
const DtShapeInitializer * myInitializer
Definition: shapefile.h:181
DtShapeVectorReader * myVectorReader
Definition: shapefile.h:189
static DtShapeProjectionCreatorFcn theShapeProjectionCreator
Definition: shapefile.h:205
DtShapeProjection *(* DtShapeProjectionCreatorFcn)()
Definition: shapeProjectionInformation.h:112
DtNetInt16 myDbfRecordSize
Definition: shapefile.h:194
DtNetInt16 myDbfHeaderSize
Definition: shapefile.h:195
Definition: shapeReader.h:30
Definition: shapeInitializer.h:24
void(* DtStringShapeImportFcn)(const char *feature, DtString &value)
Definition: shapefile.h:33
DT_DLL_DEBUGDRAWRENDERER void init(makVrv::DtDe &de)
Work function for the plugin initialization.
DtShapeProjection * myProjectionInformation
Definition: shapefile.h:203
DtNetInt32 myDbfRecordCount
Definition: shapefile.h:193
#define DT_DLL_shape
Definition: shapeDefines.h:23
Definition: shapeEntry.h:33
void(* DtRealShapeImportFcn)(const char *feature, DtReal &value)
Definition: shapefile.h:31
Definition: shapefile.h:40
Definition: shapeVectorInitializer.h:30
Definition: vectorNetwork.h:37

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)