1 /**********************************************************
2 * Version $Id: gpx2shp.cpp 911 2011-02-14 16:38:15Z reklov_w $
3 *********************************************************/
4 /*******************************************************************************
5 GPX2SHP.cpp
6 Copyright (C) Victor Olaya
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301, USA
21 *******************************************************************************/
22 #include "gpx2shp.h"
23
CGPX2SHP()24 CGPX2SHP::CGPX2SHP(){
25
26 Parameters.Set_Name(_TL("GPX to shapefile"));
27
28 Parameters.Set_Description(_TW(
29 "Converts a GPX file into a Shapefile (.shp)"
30 "(c) 2005 by Victor Olaya\r\nemail: volaya@ya.com")
31 );
32
33 Parameters.Add_FilePath(NULL,
34 "BASEPATH",
35 _TL("Gpx2shp path"),
36 _TL("Gpx2shp path"),
37 _TL(""),
38 _TL(""),
39 false,
40 true);
41
42 Parameters.Add_FilePath(NULL,
43 "FILE",
44 _TL("GPX file"),
45 _TL(""),
46 _TL("GPX files (*.gpx)|*.gpx|All Files|*.*")
47 );
48
49 Parameters.Add_Value(NULL,
50 "TRACKPOINTS",
51 _TL("Convert track points"),
52 _TL("Convert track points"),
53 PARAMETER_TYPE_Bool,
54 true);
55
56 Parameters.Add_Value(NULL,
57 "WAYPOINTS",
58 _TL("Convert way points"),
59 _TL("Convert way points"),
60 PARAMETER_TYPE_Bool,
61 true);
62
63 Parameters.Add_Value(NULL,
64 "ROUTES",
65 _TL("Convert routes"),
66 _TL("Convert routes"),
67 PARAMETER_TYPE_Bool,
68 true);
69
70 Parameters.Add_Value(NULL,
71 "ADD",
72 _TL("Load shapefile"),
73 _TL("Load shapefile after conversion"),
74 PARAMETER_TYPE_Bool,
75 true);
76
77 }//constructor
78
~CGPX2SHP()79 CGPX2SHP::~CGPX2SHP(){
80
81 }//destructor
82
On_Execute(void)83 bool CGPX2SHP::On_Execute(void){
84
85 CSG_String sCmd;
86 CSG_String sFile = Parameters("FILE")->asString();
87 CSG_String sBasePath = Parameters("BASEPATH")->asString();
88 CSG_String sShapefile;
89 bool bWaypoints = Parameters("WAYPOINTS")->asBool();
90 bool bTrackpoints = Parameters("TRACKPOINTS")->asBool();
91 bool bRoutes = Parameters("ROUTES")->asBool();
92 bool bAdd = Parameters("ADD")->asBool();
93 CSG_Shapes *pShapes;
94
95 sCmd = sBasePath + SG_T("\\gpx2shp ");
96
97 if (bWaypoints){
98 sCmd += SG_T("-w ");
99 }//if
100 if (bTrackpoints){
101 sCmd += SG_T("-t ");
102 }//if
103 if (bRoutes){
104 sCmd += SG_T("-r ");
105 }//if
106
107 sCmd += sFile;
108
109 system(sCmd.b_str());
110
111 if( bAdd )
112 {
113 CSG_String sDir(SG_File_Get_Path(sFile)), sName(SG_File_Get_Name(sFile, false));
114
115 //-------------------------------------------------
116 sFile = SG_File_Make_Path(sDir, sName + SG_T("_wpt"), SG_T("shp"));
117 pShapes = SG_Create_Shapes(sFile);
118
119 if( pShapes->is_Valid() )
120 DataObject_Add(pShapes, false);
121 else
122 delete(pShapes);
123
124 //-------------------------------------------------
125 sFile = SG_File_Make_Path(sDir, sName + SG_T("_trk"), SG_T("shp"));
126 pShapes = SG_Create_Shapes(sFile);
127
128 if( pShapes->is_Valid() )
129 DataObject_Add(pShapes, false);
130 else
131 delete(pShapes);
132
133 //-------------------------------------------------
134 sFile = SG_File_Make_Path(sDir, sName + SG_T("_rte"), SG_T("shp"));
135 pShapes = SG_Create_Shapes(sFile);
136
137 if( pShapes->is_Valid() )
138 DataObject_Add(pShapes, false);
139 else
140 delete(pShapes);
141 }//if
142
143 return true;
144
145 }//method