![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /******************************************************************************* 00002 ** Copyright (c) 2003 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *******************************************************************************/ 00005 /******************************************************************************* 00006 ** $RCSfile: shapefile.h,v $ $Revision: 1.21 $ $State: Exp $ 00007 *******************************************************************************/ 00008 00009 #ifndef shapefile_H_ 00010 #define shapefile_H_ 00011 00012 #include "shape/shapeDefines.h" 00013 #include <vlutil/vlFilename.h> 00014 #include <vlutil/vlNetTypes.h> 00015 #include <vlutil/vlList.h> 00016 #include <vlutil/vlHashlist.h> 00017 #include "shape/shapeProjectionInformation.h" 00018 00019 class DtShapeEntry; 00020 class DtShapeHeader; 00021 class DtShapeReader; 00022 class DtShapeVectorReader; 00023 class DtShapeVectorReader; 00024 class DtShapeInitializer; 00025 class DtShapeVectorInitializer; 00026 class DtGroup; 00027 class DtGeodeticCoord; 00028 00029 class DtVectorNetwork; 00030 00031 typedef void (*DtRealShapeImportFcn)(const char* feature, DtReal& value); 00032 typedef void (*DtIntegerShapeImportFcn)(const char* feature, int& value); 00033 typedef void (*DtStringShapeImportFcn)(const char* feature, DtString& value); 00034 00035 // 00036 // DtShapefile is the base class for DtShapeFeatureFile and DtShapeTerrainFile. 00037 // It provides the interface for reading shape files, and the capability to 00038 // read the associated .dbf dBASE files. 00039 // 00040 class DT_DLL_shape DtShapefile 00041 { 00042 00043 public: 00044 00045 // Constructor 00046 DtShapefile(const DtShapeInitializer* i); 00047 00048 // Constructor 00049 DtShapefile(const DtShapeVectorInitializer* i); 00050 00051 // Destructor 00052 virtual ~DtShapefile(); 00053 00054 private: 00055 // Copy constructor and Assignment operator not implemented 00056 DtShapefile(const DtShapefile& original); 00057 DtShapefile& operator=(const DtShapefile& original); 00058 00059 public: 00060 00061 // Registers default dBASE import functions. Override this function to 00062 // change or add import functions. 00063 virtual void init(); 00064 00065 // Opens the given file and adds each DtShapeRecord to myList 00066 virtual bool load(const DtFilename& path, const DtShapeEntry* entry); 00067 00068 // Overridden by subclasses to process the DtShapeReader 00069 virtual DtGroup* import(DtShapeReader* db) = 0; 00070 00071 // Overridden by subclasses to process the DtShapeVectorReader 00072 virtual bool importFeatures(DtShapeVectorReader* db) = 0; 00073 00074 // Returns myHeader->myBoundingBox[0] 00075 virtual double xMin(); 00076 // Returns myHeader->myBoundingBox[1]; 00077 virtual double yMin(); 00078 // Returns myHeader->myBoundingBox[2]; 00079 virtual double xMax(); 00080 // Returns myHeader->myBoundingBox[3]; 00081 virtual double yMax(); 00082 00083 // Returns myList 00084 virtual DtList &list(); 00085 00086 00087 // 00088 // dBASE import functions 00089 // 00090 00091 // Associates the given dBASE type with a DtRealShapeImportFcn that can 00092 // convert it to a DtReal. 00093 virtual void setRealImportFunction(const char type, DtRealShapeImportFcn fcn); 00094 // Finds the DtRealShapeImportFcn associated with the give dBASE type 00095 virtual DtRealShapeImportFcn lookupRealImportFunction(const char type); 00096 // Converts the feature (as returned from readFeature) to a DtReal value 00097 static void importNumberAsReal(const char* feature, DtReal& value); 00098 00099 // Associates the given dBASE type with a DtIntegerShapeImportFcn that can 00100 // convert it to a int. 00101 virtual void setIntegerImportFunction(const char type, DtIntegerShapeImportFcn fcn); 00102 // Finds the DtIntegerShapeImportFcn associated with the give dBASE type 00103 virtual DtIntegerShapeImportFcn lookupIntegerImportFunction(const char type); 00104 // Converts the feature (as returned from readFeature) to an int value 00105 static void importNumberAsInteger(const char* feature, int& value); 00106 00107 // Associates the given dBASE type with a DtStringShapeImportFcn that can 00108 // convert it to a DtString. 00109 virtual void setStringImportFunction(const char type, DtStringShapeImportFcn fcn); 00110 // Finds the DtStringShapeImportFcn associated with the give dBASE type 00111 virtual DtStringShapeImportFcn lookupStringImportFunction(const char type); 00112 // Converts the feature (as returned from readFeature) to a DtString value 00113 static void importCharAsString(const char* feature, DtString& value); 00114 00115 virtual DtString projectionType() const; 00116 00117 DtShapeProjection* projectionInformation() const; 00118 00119 static void setShapeProjectionCreatorFcn(DtShapeProjectionCreatorFcn); 00120 00121 // Returns a coordinate system from the shape projection (if exists). NULL if not. 00122 // Caller must free returned pointer 00123 virtual Coordinate_System* coordinateSystem() const; 00124 00125 // Gets lower left/upper right corners in geodetic 00126 virtual void getCorners(DtGeodeticCoord& ll, DtGeodeticCoord& ur); 00127 00128 // @name Open/close dBASE file functions 00129 // @{ 00130 // Opens and closes the .dbf dBASE file associated with the shape file, 00131 // initializing the myDbfFile pointer. 00132 // The ESRI shape standard requires them to have the same name prefix. 00133 // The caller is responsible for closing the myDbfFile pointer. 00134 virtual bool openDbf(); 00135 00136 // Given shapefile and path, opens .dbf file associated with it 00137 virtual bool openDbf(const DtFilename&); 00138 00139 virtual bool closeDbf(); 00140 // @} 00141 00142 // @name Column dBASE file functions 00143 // @{ 00144 // Returns information about columns 00145 00146 // Returns number of columns in dbf file 00147 virtual int numDbfColumns() const; 00148 virtual bool column(int col, DtString& colName, char& colType, unsigned char& colLength); 00149 // @} 00150 00151 // Tries to load and parse .prj file based on current shape file to get projection information. Builds 00152 // a hash list (key/value pair) of all information found 00153 virtual void loadProjectionFile(); 00154 00155 protected: 00156 00157 // Locates the record with the given featureName and featureNumber, allocates 00158 // a string for the data, and returns the dBASE type ('C', 'N', etc.) in 00159 // fieldType. The caller is responsible for freeing the returned pointer! 00160 virtual char* readFeature(const DtString& featureName, int featureNumber, 00161 char& fieldType); 00162 00163 // Calls readFeature with the given featureName and featureNumber, then 00164 // sets the value using the import function returned from 00165 // lookupRealImportFunction 00166 virtual bool readFeatureAsReal(const DtString& featureName, int featureNumber, DtReal& value); 00167 00168 // Calls readFeature with the given featureName and featureNumber, then 00169 // sets the value using the import function returned from 00170 // lookupIntegerImportFunction 00171 virtual bool readFeatureAsInteger(const DtString& featureName, int featureNumber, int& value); 00172 00173 // Calls readFeature with the given featureName and featureNumber, then 00174 // sets the value using the import function returned from 00175 // lookupStringImportFunction 00176 virtual bool readFeatureAsString(const DtString& featureName, 00177 int featureNumber, DtString& value); 00178 00179 protected: 00180 00181 const DtShapeInitializer* myInitializer; 00182 const DtShapeVectorInitializer* myVectorInitializer; 00183 00184 const DtShapeEntry* myEntry; 00185 DtFilename myFilename; 00186 DtShapeHeader* myHeader; 00187 DtList myList; 00188 DtShapeReader* myReader; 00189 DtShapeVectorReader* myVectorReader; 00190 00191 // .dbf file -- should be opened only for the duration of the import! 00192 FILE* myDbfFile; 00193 DtNetInt32 myDbfRecordCount; 00194 DtNetInt16 myDbfRecordSize; 00195 DtNetInt16 myDbfHeaderSize; 00196 00197 DtHashlist myRealImportFunctions; 00198 DtHashlist myIntegerImportFunctions; 00199 DtHashlist myStringImportFunctions; 00200 00201 // Contains the projection type (string) that should be used to convert points 00202 // from a non-geodetic source to a geodetic (degree) source 00203 DtShapeProjection* myProjectionInformation; 00204 00205 static DtShapeProjectionCreatorFcn theShapeProjectionCreator; 00206 }; 00207 00208 inline DtShapeProjection* DtShapefile::projectionInformation() const 00209 { 00210 return myProjectionInformation; 00211 } 00212 00213 #endif