00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019
00020
00021 00022 00023 00024 00025 00026
00027
00028 #include <math.h>
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <gnome.h>
00032 #include "fmaps.h"
00033
00034 void FM_Export_Ellipsoid(PGconn *conn,const gchar *name)
00035 {
00036 gchar *buffer;
00037 gint i;
00038 gint nbtuples;
00039 gchar *col[4];
00040 PGresult *qryResult;
00041 FILE *ellipsoidfile;
00042
00043 g_return_if_fail(conn!=NULL);
00044 g_return_if_fail(name!=NULL);
00045
00046 gnome_app_flash (GNOME_APP(Fmaps), "Exporting Ellipsoid");
00047
00048 ellipsoidfile=fopen(name,"w");
00049 fprintf(ellipsoidfile,"ELLIPSOID\n");
00050
00051 buffer=g_strdup("SELECT DISTINCT * FROM f_ellipsoid");
00052 qryResult = PQexec(conn,buffer);
00053 g_free(buffer);
00054
00055 nbtuples = PQntuples(qryResult);
00056 i=0;
00057 while(i<nbtuples)
00058 {
00059 buffer = PQgetvalue(qryResult,i,0);
00060 col[0]=g_strdup(buffer);
00061 buffer = PQgetvalue(qryResult,i,1);
00062 col[1]=g_strdup(buffer);
00063 buffer = PQgetvalue(qryResult,i,2);
00064 col[2]=g_strdup(buffer);
00065 buffer = PQgetvalue(qryResult,i,3);
00066 col[3]=g_strdup(buffer);
00067 fprintf(ellipsoidfile,"%s , %s , %s , %s\n",col[0],col[1],col[2],col[3]);
00068 g_free(col[0]);
00069 g_free(col[1]);
00070 g_free(col[2]);
00071 g_free(col[3]);
00072 i++;
00073 }
00074
00075 PQclear(qryResult);
00076 fclose(ellipsoidfile);
00077
00078 gnome_app_flash (GNOME_APP(Fmaps), "Exporting Ellipsoid Completed");
00079 }
00080 void FM_Import_Ellipsoid(PGconn *conn,const gchar *name)
00081 {
00082 gchar *buffer;
00083 gchar *col[4];
00084 PGresult *qryResult;
00085 FILE *ellipsoidfile;
00086
00087 g_return_if_fail (conn!=NULL);
00088 g_return_if_fail (name!=NULL);
00089
00090 gnome_app_flash (GNOME_APP(Fmaps), "Importing Ellipsoid");
00091
00092 buffer=g_malloc0(100);
00093 col[0]=g_malloc0(100);
00094 col[1]=g_malloc0(100);
00095 col[2]=g_malloc0(100);
00096 col[3]=g_malloc0(100);
00097
00098 ellipsoidfile=fopen(name,"r");
00099 fscanf(ellipsoidfile,"%s\n",buffer);
00100
00101
00102 if (strcmp(buffer,"ELLIPSOID")!=0)
00103 {
00104 FM_MessageBox("This is not an ELLIPSOID file");
00105 return;
00106 }
00107 g_free(buffer);
00108
00109 buffer=g_strdup("DELETE FROM f_ellipsoid");
00110 qryResult = PQexec(conn,buffer);
00111 g_free(buffer);
00112 PQclear(qryResult);
00113 while (!feof(ellipsoidfile))
00114 {
00115 fscanf(ellipsoidfile,"%s , %s , %s , %s\n",col[0],col[1],col[2],col[3]);
00116 buffer=g_strdup_printf("INSERT INTO f_ellipsoid (ellipsoidid,name,a,f) VALUES(%s,'%s',%s,%s)",col[0],col[1],col[2],col[3]);
00117 qryResult = PQexec(conn,buffer);
00118 g_free(buffer);
00119 PQclear(qryResult);
00120 }
00121 g_free(col[0]);
00122 g_free(col[1]);
00123 g_free(col[2]);
00124 g_free(col[3]);
00125
00126
00127 fclose(ellipsoidfile);
00128
00129 gnome_app_flash (GNOME_APP(Fmaps), "Importing Ellipsoid Completed");
00130 }
00131
00132 void FM_Export_Datum(PGconn *conn,const gchar *name)
00133 {
00134 gchar *buffer;
00135 gint i,j;
00136 gint nbtuples;
00137 gchar *col[12];
00138 PGresult *qryResult;
00139 FILE *datumfile;
00140
00141 g_return_if_fail(conn!=NULL);
00142 g_return_if_fail(name!=NULL);
00143
00144 gnome_app_flash (GNOME_APP(Fmaps), "Exporting Datum");
00145
00146 datumfile=fopen(name,"w");
00147 fprintf(datumfile,"DATUM\n");
00148
00149 buffer=g_strdup("SELECT DISTINCT * FROM f_datum");
00150 qryResult = PQexec(conn,buffer);
00151 g_free(buffer);
00152
00153 nbtuples = PQntuples(qryResult);
00154 i=0;
00155 while(i<nbtuples)
00156 {
00157 for (j=0;j<12;j++)
00158 {
00159 buffer = PQgetvalue(qryResult,i,j);
00160 col[j]=g_strdup(buffer);
00161 }
00162 fprintf(datumfile,"%s , %s , %s , %s , %s , %s, %s , %s , %s , %s , %s , %s\n",col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7],col[8],col[9],col[10],col[11]);
00163 for (j=0;j<12;j++)
00164 {
00165 g_free(col[j]);
00166 }
00167 i++;
00168 }
00169
00170 PQclear(qryResult);
00171 fclose(datumfile);
00172
00173 gnome_app_flash (GNOME_APP(Fmaps), "Exporting Datum Completed");
00174 }
00175
00176 void FM_Import_Datum(PGconn *conn,const gchar *name)
00177 {
00178 gchar *buffer;
00179 gchar *col[12];
00180 PGresult *qryResult;
00181 FILE *datumfile;
00182 gint j;
00183
00184 g_return_if_fail (conn!=NULL);
00185 g_return_if_fail (name!=NULL);
00186
00187 gnome_app_flash (GNOME_APP(Fmaps), "Importing Datum");
00188
00189 buffer=g_malloc0(100);
00190
00191 for(j=0;j<12;j++)
00192 {
00193 col[j]=g_malloc0(100);
00194 }
00195
00196
00197 datumfile=fopen(name,"r");
00198 fscanf(datumfile,"%s\n",buffer);
00199
00200
00201 if (strcmp(buffer,"DATUM")!=0)
00202 {
00203 FM_MessageBox("This is not an DATUM file");
00204 return;
00205 }
00206 g_free(buffer);
00207
00208 buffer=g_strdup("DELETE FROM f_datum");
00209 qryResult = PQexec(conn,buffer);
00210 g_free(buffer);
00211 PQclear(qryResult);
00212 while (!feof(datumfile))
00213 {
00214 fscanf(datumfile,"%s , %s , %s , %s , %s , %s , %s , %s, %s , %s , %s , %s\n",col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7],col[8],col[9],col[10],col[11]);
00215 buffer=g_strdup_printf("INSERT INTO f_datum (datumid,name,type,ellipsoidid,dx,dy,dz,ox,oy,oz,scale,pm) VALUES (%s,'%s',%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7],col[8],col[9],col[10],col[11]);
00216 qryResult = PQexec(conn,buffer);
00217 g_free(buffer);
00218 PQclear(qryResult);
00219 }
00220 for(j=0;j<12;j++)
00221 {
00222 g_free(col[j]);
00223 }
00224
00225 fclose(datumfile);
00226
00227 gnome_app_flash (GNOME_APP(Fmaps), "Importing Datum Completed");
00228 }
00229
00230 void FM_Import_Projection(PGconn* conn,const char *name)
00231 {
00232 gchar *buffer;
00233 gchar *col[13];
00234 PGresult *qryResult;
00235 FILE *projectionfile;
00236 gint j;
00237
00238 g_return_if_fail (conn!=NULL);
00239 g_return_if_fail (name!=NULL);
00240
00241 gnome_app_flash (GNOME_APP(Fmaps), "Importing Projection");
00242
00243 buffer=g_malloc0(100);
00244
00245 for(j=0;j<13;j++)
00246 {
00247 col[j]=g_malloc0(100);
00248 }
00249
00250
00251 projectionfile=fopen(name,"r");
00252 fscanf(projectionfile,"%s\n",buffer);
00253
00254
00255 if (strcmp(buffer,"PROJECTION")!=0)
00256 {
00257 FM_MessageBox("This is not a Projection file");
00258 return;
00259 }
00260 g_free(buffer);
00261
00262 buffer=g_strdup("DELETE FROM f_projection");
00263 qryResult = PQexec(conn,buffer);
00264 g_free(buffer);
00265 PQclear(qryResult);
00266 while (!feof(projectionfile))
00267 {
00268 fscanf(projectionfile,"%s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s\n",col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7],col[8],col[9],col[10],col[11],col[12]);
00269 buffer=g_strdup_printf("INSERT INTO f_projection (projid,name,type,par1,par2,par3,par4,par5,par6,par7,par8,par9,par10) VALUES (%s,'%s',%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7],col[8],col[9],col[10],col[11],col[12]);
00270 qryResult = PQexec(conn,buffer);
00271 g_free(buffer);
00272 PQclear(qryResult);
00273 }
00274 for(j=0;j<13;j++)
00275 {
00276 g_free(col[j]);
00277 }
00278
00279 fclose(projectionfile);
00280
00281 gnome_app_flash (GNOME_APP(Fmaps), "Importing Projection Completed");
00282 }
00283
00284 void FM_Export_Projection(PGconn* conn,const char *name)
00285 {
00286 gchar *buffer;
00287 gint i,j;
00288 gint nbtuples;
00289 gchar *col[13];
00290 PGresult *qryResult;
00291 FILE *projectionfile;
00292
00293 g_return_if_fail(conn!=NULL);
00294 g_return_if_fail(name!=NULL);
00295
00296 gnome_app_flash (GNOME_APP(Fmaps), "Exporting Projection");
00297
00298 projectionfile=fopen(name,"w");
00299 fprintf(projectionfile,"PROJECTION\n");
00300
00301 buffer=g_strdup("SELECT DISTINCT * FROM f_projection");
00302 qryResult = PQexec(conn,buffer);
00303 g_free(buffer);
00304
00305 nbtuples = PQntuples(qryResult);
00306 i=0;
00307 while(i<nbtuples)
00308 {
00309 for (j=0;j<13;j++)
00310 {
00311 buffer = PQgetvalue(qryResult,i,j);
00312 col[j]=g_strdup(buffer);
00313 }
00314 fprintf(projectionfile,"%s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s\n",col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7],col[8],col[9],col[10],col[11],col[12]);
00315 for (j=0;j<13;j++)
00316 {
00317 g_free(col[j]);
00318 }
00319 i++;
00320 }
00321
00322 PQclear(qryResult);
00323 fclose(projectionfile);
00324
00325 gnome_app_flash (GNOME_APP(Fmaps), "Exporting Projection Completed");
00326 }