Navit SVN

/work/compile/navit/src/navit/tools/gpx2navit_txt/src/gpx2navit_txt.h

00001 
00020 #ifndef GPX2SHP_H_INCLUDED
00021 #define GPX2SHP_H_INCLUDED
00022 
00023 #define PROG gpx2navit_txt
00024 #define FILENAMELENGTH 255      /* 255 is max length for dbf string column */
00025 #define COMMENTLENGTH 255       /* 255 is max length for dbf string column */
00026 #define NAMELENGTH 32
00027 #define TIMELENGTH 32
00028 #define TYPELENGTH 16
00029 #define BUFFSIZE 8192
00030 #define DATABUFSIZE 16
00031 #define failToWriteAttr(S, T) failToWriteAttrRep((S), (T),__FILE__, __LINE__ )
00032 
00033 #include <stdio.h>
00034 #include <string.h>
00035 #include <ctype.h>
00036 #include <stdlib.h>
00037 #include <unistd.h>
00038 #include <libgen.h>
00039 #include <getopt.h>
00040 #include <time.h>
00041 #include <assert.h>
00042 #include <expat.h>
00043 #include "errorcode.h"
00044 //#include "shapefil.h"
00045 
00046 
00047 #define DEBUG 0
00048 
00051 typedef struct parent {
00052     char *name;         
00053     struct parent *parentptr;
00055 } parent;
00056 
00060 typedef struct g2scolumns {
00064     int name;
00065     int cmt;
00066     int desc;
00067     int src;
00068     int link;
00069     int type;
00070     int time;
00071     int number;
00072     int ele;
00073     int magvar;
00074     int geoidheight;
00075     int sym;
00076     int fix;
00077     int sat;
00078     int hdop;
00079     int vdop;
00080     int pdop;
00081     int ageofdgpsdata;
00082     int dgpsid;
00083     int length;
00084     int interval;
00085     int speed;
00086     int points;
00087     int gpxline;
00088 } g2scolumns;
00089 
00093 typedef struct pathattr {
00094     char name[NAMELENGTH];
00095     char cmt[COMMENTLENGTH];
00096     char desc[COMMENTLENGTH];
00097     char src[COMMENTLENGTH];
00098     char link[FILENAMELENGTH];
00099     int number;
00100     char type[TYPELENGTH];
00101     double length;
00102     double interval;
00103     double speed;
00104     /*
00105     double *x;
00106     double *y;
00107     double *z;
00108     */
00109     double *point;
00110     int count;
00111 } pathattr;
00112 
00116 typedef struct g2sattr {
00120     double lon;
00121     double lat;
00122     double minlon;
00123     double minlat;
00124     double maxlon;
00125     double maxlat;
00126     char name[NAMELENGTH];
00127     char cmt[COMMENTLENGTH];
00128     char desc[COMMENTLENGTH];
00129     char src[COMMENTLENGTH];
00130     char link[FILENAMELENGTH];
00131     char type[TYPELENGTH];
00132     char time[TIMELENGTH];
00133     int number;
00134     double ele;
00135     double magvar;
00136     double geoidheight;
00137     char sym[NAMELENGTH];
00138     char fix[NAMELENGTH];
00139     int sat;
00140     double hdop;
00141     double vdop;
00142     double pdop;
00143     double ageofdgpsdata;
00144     int dgpsid;
00145     char author[NAMELENGTH];
00146     char keywords[NAMELENGTH];
00147     char copyright[NAMELENGTH];
00148     int year;
00149     char license[NAMELENGTH];
00150 } g2sattr;
00151 
00155 typedef struct g2sstats {
00156         int trkpoints;  
00157         int trkcount;   
00158     double trklength;   
00159     int rtepoints;      
00160     int rtecount;       
00161     double rtelength;   
00162     int wptpoints;      
00163     int trkunconverted; 
00164     int rteunconverted; 
00165 } g2sstats;
00166 
00170 //typedef struct dbfhandles {
00171 //    DBFHandle trk;    /** for track */
00172 //    DBFHandle wpt;    /** for waypoint */
00173 //    DBFHandle rte;    /** for route */
00174 //    DBFHandle trk_edg;        /** for track each edge */
00175 //    DBFHandle trk_pnt;        /** for track each point */
00176 //    DBFHandle rte_edg;        /** for route each edge */
00177 //    DBFHandle rte_pnt;        /** for route each point */
00178 //} dbfhandles;
00179 
00183 //typedef struct shphandles {
00184 //    SHPHandle trk;    /** for track */
00185 //    SHPHandle wpt;    /** for waypoint */
00186 //    SHPHandle rte;    /** for route */
00187 //    SHPHandle trk_edg;        /** for track each edge */
00188 //    SHPHandle trk_pnt;        /** for track each point */
00189 //    SHPHandle rte_edg;        /** for route each edge */
00190 //    SHPHandle rte_pnt;        /** for route each point */
00191 //} shphandles;
00192 
00196 typedef struct g2sprop {
00197     int parseWpt;       
00198     int parseTrk;       
00199     int parseRte;       
00200     int is3d;           
00201     int isEdge;         
00202     int isPoint;        
00203     int isFast;         
00204     int needsStats;     
00205     int minpoints;      
00206     int minlength;      
00207     int mintime;        
00208     int verbose;        
00209     char *sourcefile;   
00210     char *output;       
00211     char *ellipsoid;    
00212     char *lengthUnit;   
00213     double length2meter;
00214     char *timeUnit;     
00215     double time2sec;    
00216     char *speedLengthUnit;
00218     double speed2meter; 
00219     char *speedTimeUnit;
00220     int speed2sec;      
00221     g2sstats *stats;    
00222     g2scolumns *cols;   
00223 } g2sprop;
00224 
00228 typedef struct parsedata {
00229     int depth;          
00230     char *databuf;      
00231     char *bufptr;       
00232     int failed;         
00233     int failedid;       
00234     XML_Parser parser;  
00235     parent *parent;     
00236     parent *current;    
00237     FILE *fp;           
00238 //    shphandles *shps; /** .shp file cluster that is used in this program */
00239 //    dbfhandles *dbfs; /** .dbf file cluster that is used in this program */
00240     g2sattr *attr;      
00241     pathattr *pattr;    
00242     g2sprop *prop;      
00243 } parsedata;
00244 
00245 /* utils.c */
00246 void checkEllpsUnit(char *unit);
00247 double checkLengthUnit(char *unit);
00248 int checkTimeUnit(char *unit);
00249 double getTimeInterval(char *_t, char *t);
00250 double getSpeed(double length, double ti, double to_meter, int to_sec);
00251 double getDistance(double _x, double _y, double x, double y);
00252 //void closeShpFiles(shphandles * shps);
00253 //void closeDbfFiles(dbfhandles * dbfs);
00254 void *myMallocRep(size_t size, const char *fileName, int line);
00255 
00256 /* misc.c */
00257 void failToWriteAttrRep(int iShape, int col, char *file, int line);
00258 void showStats(g2sprop * prop);
00259 void wipePathAttr(pathattr * pattr);
00260 pathattr *createPathAttr(void);
00261 void wipeAttr(g2sattr * attr);
00262 void setColsDefault(g2scolumns * cols);
00263 g2scolumns *createCols(void);
00264 g2sattr *createAttr(void);
00265 g2sprop *createProp(void);
00266 void closeProp(g2sprop * prop);
00267 //shphandles *createShps(void);
00268 //dbfhandles *createDbfs(void);
00269 parsedata *createParsedata(XML_Parser parser, g2sprop * prop);
00270 void closeParsedata(parsedata * pdata);
00271 
00272 /* parser.c */
00273 void parseMain(g2sprop * pr);
00274 
00275 /* elementControl.c */
00276 void startElementControl(parsedata * pdata, const char *element,
00277                          const char **attr);
00278 void endElementControl(parsedata * pdata, const char *element);
00279 
00280 /* setwpt.c */
00281 void setWpt( parsedata * pdata);
00282 
00283 /* setpath.c */
00284 void initPathAttr(pathattr * pattr, g2sattr * attr);
00285 void setPathInterval(parsedata *pdata);
00286 void setPathData(pathattr * parrt, g2sattr * attr);
00287 void setPath( parsedata * pdata);
00288 
00289 /* setmetadata.c */
00290 void setMetadata(parsedata * pdata);
00291 
00292 #endif