]> granicus.if.org Git - postgis/commitdiff
change empty table error to just a warning
authorRegina Obe <lr@pcorp.us>
Mon, 27 Apr 2009 22:04:47 +0000 (22:04 +0000)
committerRegina Obe <lr@pcorp.us>
Mon, 27 Apr 2009 22:04:47 +0000 (22:04 +0000)
git-svn-id: http://svn.osgeo.org/postgis/branches/1.3@4033 b70326c6-7e19-0410-871a-916f4a2858ee

loader/pgsql2shp.c

index f1e592a775dd8d70268e48c51f230ffd64e9472b..24dabad125bca5cb602bbe1d41a6b1bc116e8787 100644 (file)
@@ -7,7 +7,7 @@
  *
  * This is free software; you can redistribute and/or modify it under
  * the terms of the GNU General Public Licence. See the COPYING file.
- * 
+ *
  **********************************************************************
  *
  * PostGIS to Shapefile converter
@@ -38,7 +38,7 @@ static char rcsid[] =
 #include <unistd.h> // for getpid()
 
 #ifdef __CYGWIN__
-#include <sys/param.h>       
+#include <sys/param.h>
 #endif
 
 #define        POINTTYPE       1
@@ -117,9 +117,9 @@ static void parse_table(char *spec);
 static int create_usrquerytable(void);
 static const char *nullDBFValue(char fieldType);
 int projFileCreate(const char * pszFilename, char *schema, char *table, char *geo_col_name);
-/* 
+/*
  * Make appropriate formatting of a DBF value based on type.
- * Might return untouched input or pointer to static private 
+ * Might return untouched input or pointer to static private
  * buffer: use return value right away.
  */
 static const char * goodDBFValue(const char *in, char fieldType);
@@ -200,19 +200,19 @@ main(int ARGC, char **ARGV)
        /*
         * Make sure dates are returned in ISO
         * style (YYYY-MM-DD).
-        * This is to allow goodDBFValue() function 
+        * This is to allow goodDBFValue() function
         * to successfully extract YYYYMMDD format
         * expected in shapefile's dbf file.
         */
        putenv("PGDATESTYLE=ISO");
 
        if ( ! parse_commandline(ARGC, ARGV) ) {
-                printf("\n**ERROR** invalid option or command parameters\n\n");
+                               printf("\n**ERROR** invalid option or command parameters\n\n");
                usage(ARGV[0], 2, stderr);
        }
 
        /* Use table name as shapefile name */
-        if(shp_file == NULL) shp_file = table;
+               if(shp_file == NULL) shp_file = table;
 
        /* Make a connection to the specified database, and exit on failure */
        conn = PQconnectdb(conn_string);
@@ -238,7 +238,7 @@ main(int ARGC, char **ARGV)
        fprintf(stdout, "Initializing... "); fflush(stdout);
        if ( ! initialize() ) exit_nicely(conn, 1);
        fprintf(stdout, "Done (postgis major version: %d).\n",
-               pgis_major_version); 
+               pgis_major_version);
 
        if ( pgis_major_version > 0 && dswitchprovided )
        {
@@ -296,7 +296,7 @@ main(int ARGC, char **ARGV)
                int i;
 
                /* Fetch next record buffer from cursor */
-#if VERBOSE 
+#if VERBOSE
                fprintf(stdout, "X"); fflush(stdout);
 #endif
                res = PQexec(conn, fetchquery);
@@ -316,7 +316,7 @@ main(int ARGC, char **ARGV)
                {
                        /* Add record in all output files */
                        if ( ! addRecord(res, i, row) ) exit_nicely(conn, 1);
-                       row++; 
+                       row++;
                }
 
 #if VERBOSE > 2
@@ -382,7 +382,7 @@ shape_creator_wrapper_WKB(byte *str, int idx)
                                return create_multiline3D_WKB(str);
                        else if ( ndims == 4 )
                                return create_multiline4D_WKB(str);
-                               
+
                case LINETYPE:
                        if ( ndims == 2 )
                                return create_line2D_WKB(str);
@@ -430,7 +430,7 @@ shape_creator_wrapper_WKB(byte *str, int idx)
        }
 }
 
-/* 
+/*
  * Reads WKT points into x,y,z co-ord arrays
  */
 int
@@ -442,18 +442,18 @@ parse_points(char *str, int num_points, double *x,double *y,double *z){
        if ( (str == NULL) || (str[0] == 0) ){
                return 0;  /* either null string or empty string */
        }
-       
+
        /* look ahead for the "(" */
        str = strchr(str,'(') ;
-       
+
        /* either didnt find "(" or its at the end of the string */
        if ( (str == NULL) || (str[1] == 0) ) {  /* str[0] = '('; */
-               return 0; 
+               return 0;
        }
        str++;  /*move forward one char */
        keep_going = 1;
        while (keep_going == 1){
-               
+
                /*
                 * attempt to get the point
                 * scanf is slow, so we use strtod()
@@ -477,9 +477,9 @@ parse_points(char *str, int num_points, double *x,double *y,double *z){
                if (str != NULL && str[0] == ','){
                        str++;
                }
-               keep_going = (str != NULL) && (str[0] != ')');          
+               keep_going = (str != NULL) && (str[0] != ')');
        }
-       return num_found; 
+       return num_found;
 }
 
 
@@ -492,8 +492,8 @@ parse_points(char *str, int num_points, double *x,double *y,double *z){
  *  1. scan ahead looking for "("
  *  2. find "," until hit a ")"
  *  3. return number of points found
- *     
- * NOTE: doesnt actually parse the points, so if the 
+ *
+ * NOTE: doesnt actually parse the points, so if the
  *       str contains an invalid geometry, this could give
  *        back the wrong answer.
  *
@@ -504,7 +504,7 @@ num_points(char *str)
 {
        int keep_going;
        int points_found = 1; /* no "," if only one point (and last point) */
-                                               
+
 
        if ( (str == NULL) || (str[0] == 0) )
        {
@@ -514,15 +514,15 @@ num_points(char *str)
        /* look ahead for the "(" */
 
        str = strchr(str,'(') ;
-       
+
        /* either didnt find "(" or its at the end of the string */
        if ( (str == NULL) || (str[1] == 0) )  /* str[0] = '('; */
        {
-               return 0; 
+               return 0;
        }
 
        keep_going = 1;
-       while (keep_going) 
+       while (keep_going)
        {
                str=strpbrk(str,",)");  /* look for a "," or ")" */
                keep_going = (str != NULL);
@@ -559,7 +559,7 @@ num_points(char *str)
  *                               for every ")", depth (nesting) decreases by 1
  * if find a "(" at depth 1, then there is a sub list
  *
- * example: 
+ * example:
  *      "(((..),(..)),((..)))"
  *depth  12333223332112333210
  *        +           +         increase here
@@ -689,7 +689,7 @@ points_per_sublist( char *str, int *npoints, long max_lists)
                        {
                                if (current_depth==2)
                                {
-                                       npoints[current_list] ++;       
+                                       npoints[current_list] ++;
                                }
                        }
 
@@ -777,7 +777,7 @@ create_multiline4D_WKB (byte *wkb)
        int zmflag;
 
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -839,9 +839,9 @@ create_multiline2D_WKB (byte *wkb)
        int li;
        SHPObject *obj;
        int zmflag;
-       
+
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -899,9 +899,9 @@ create_line4D_WKB (byte *wkb)
        uint32 npoints=0, pn;
        SHPObject *obj;
        int zmflag;
-       
+
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -940,9 +940,9 @@ create_line3D_WKB (byte *wkb)
        uint32 npoints=0, pn;
        SHPObject *obj;
        int zmflag;
-       
+
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -985,9 +985,9 @@ create_line2D_WKB (byte *wkb)
        uint32 npoints=0, pn;
        SHPObject *obj;
        int zmflag;
-       
+
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -1009,7 +1009,7 @@ create_line2D_WKB (byte *wkb)
        }
 
        obj = SHPCreateSimpleObject(outshptype, npoints, x, y, z);
-       free(x); free(y); 
+       free(x); free(y);
 
        return obj;
 }
@@ -1022,7 +1022,7 @@ create_point4D_WKB(byte *wkb)
        int zmflag;
 
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -1046,7 +1046,7 @@ create_point3D_WKB(byte *wkb)
        int zmflag;
 
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -1074,7 +1074,7 @@ create_point2D_WKB(byte *wkb)
        int zmflag;
 
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -1097,7 +1097,7 @@ create_multipoint4D_WKB(byte *wkb)
        int zmflag;
 
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -1137,7 +1137,7 @@ create_multipoint3D_WKB(byte *wkb)
        int zmflag;
 
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -1180,7 +1180,7 @@ create_multipoint2D_WKB(byte *wkb)
        int zmflag;
 
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -1200,7 +1200,7 @@ create_multipoint2D_WKB(byte *wkb)
        }
 
        obj = SHPCreateSimpleObject(outshptype,npoints,x,y,NULL);
-       free(x); free(y); 
+       free(x); free(y);
 
        return obj;
 }
@@ -1212,9 +1212,9 @@ create_polygon2D_WKB(byte *wkb)
        int ri, nrings, totpoints=0, *part_index=NULL;
        double *x=NULL, *y=NULL, *z=NULL;
        int zmflag;
-       
+
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -1276,7 +1276,7 @@ create_polygon2D_WKB(byte *wkb)
                x, y, z, NULL);
 
        free(part_index);
-       free(x); free(y); 
+       free(x); free(y);
 
        return obj;
 }
@@ -1288,9 +1288,9 @@ create_polygon4D_WKB(byte *wkb)
        int ri, nrings, totpoints=0, *part_index=NULL;
        double *x=NULL, *y=NULL, *z=NULL, *m=NULL;
        int zmflag;
-       
+
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -1366,9 +1366,9 @@ create_polygon3D_WKB(byte *wkb)
        int ri, nrings, totpoints=0, *part_index=NULL;
        double *x=NULL, *y=NULL, *zm=NULL, *z=NULL;
        int zmflag;
-       
+
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -1459,7 +1459,7 @@ create_multipolygon2D_WKB(byte *wkb)
        int zmflag;
 
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
@@ -1568,7 +1568,7 @@ create_multipolygon2D_WKB(byte *wkb)
 #endif
 
        free(part_index);
-       free(x); free(y); 
+       free(x); free(y);
 
        return obj;
 }
@@ -1586,11 +1586,11 @@ create_multipolygon3D_WKB(byte *wkb)
        int zmflag;
 
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
-       
+
        /*
         * Scan all polygons in multipolygon
         */
@@ -1726,11 +1726,11 @@ create_multipolygon4D_WKB(byte *wkb)
        int zmflag;
 
        /* skip byteOrder  */
-       skipbyte(&wkb); 
+       skipbyte(&wkb);
 
        /* extract zmflag from type */
        zmflag = ZMFLAG(popint(&wkb));
-       
+
        /*
         * Scan all polygons in multipolygon
         */
@@ -1848,7 +1848,7 @@ create_multipolygon4D_WKB(byte *wkb)
 int
 reverse_points(int num_points, double *x, double *y, double *z, double *m)
 {
-       
+
        int i,j;
        double temp;
        j = num_points -1;
@@ -1890,10 +1890,10 @@ is_clockwise(int num_points, double *x, double *y, double *z)
        int i;
        double x_change,y_change,area;
        double *x_new, *y_new; /* the points, translated to the origin
-                               * for safer accuracy */
+                                                       * for safer accuracy */
 
-       x_new = (double *)malloc(sizeof(double) * num_points);  
-       y_new = (double *)malloc(sizeof(double) * num_points);  
+       x_new = (double *)malloc(sizeof(double) * num_points);
+       y_new = (double *)malloc(sizeof(double) * num_points);
        area=0.0;
        x_change = x[0];
        y_change = y[0];
@@ -1929,7 +1929,7 @@ getGeometryOID(PGconn *conn)
        char *temp_int;
        int OID;
 
-       res1=PQexec(conn, "select OID from pg_type where typname = 'geometry'");        
+       res1=PQexec(conn, "select OID from pg_type where typname = 'geometry'");
        if ( ! res1 || PQresultStatus(res1) != PGRES_TUPLES_OK )
        {
                printf( "OIDQuery: %s", PQerrorMessage(conn));
@@ -1952,7 +1952,7 @@ getGeometryOID(PGconn *conn)
 
 
 
-/* 
+/*
  * Passed result is a 1 row result.
  * Return 1 on success.
  * Return 0 on failure.
@@ -2002,7 +2002,7 @@ fprintf(stdout, "s"); fflush(stdout);
                        flds++;
                        continue;
                }
-               
+
                /* If we arrived here it is a geometry attribute */
 
                /* Handle NULL shapes */
@@ -2079,7 +2079,7 @@ fprintf(stdout, "s"); fflush(stdout);
        return 1;
 }
 
-/* 
+/*
  * Return allocate memory. Free after use.
  */
 char *
@@ -2117,7 +2117,7 @@ getTableOID(char *schema, char *table)
        }else{
                ret = strdup(PQgetvalue(res3, 0, 0));
                printf( "Warning: Multiple relations detected, the program will only dump the first relation.\n");
-       }       
+       }
        PQclear(res3);
        return ret;
 }
@@ -2160,7 +2160,7 @@ getGeometryType(char *schema, char *table, char *geo_col_name)
 #if VERBOSE > 2
        printf( "%s\n",query);
 #endif
-       res = PQexec(conn, query);      
+       res = PQexec(conn, query);
        if ( ! res || PQresultStatus(res) != PGRES_TUPLES_OK ) {
                printf( "GeometryType: %s", PQerrorMessage(conn));
                return -1;
@@ -2266,7 +2266,7 @@ getGeometryMaxDims(char *schema, char *table, char *geo_col_name)
        if ( schema )
        {
                sprintf(query, "SELECT max(zmflag(\"%s\")) "
-                       "FROM \"%s\".\"%s\"", 
+                       "FROM \"%s\".\"%s\"",
                         geo_col_name, schema, table);
        }
        else
@@ -2279,7 +2279,7 @@ getGeometryMaxDims(char *schema, char *table, char *geo_col_name)
 #if VERBOSE > 2
        printf("%s\n",query);
 #endif
-       res = PQexec(conn, query);      
+       res = PQexec(conn, query);
        if ( ! res || PQresultStatus(res) != PGRES_TUPLES_OK ) {
                printf( "ZMflagQuery: %s", PQerrorMessage(conn));
                PQclear(res);
@@ -2316,27 +2316,27 @@ getGeometryMaxDims(char *schema, char *table, char *geo_col_name)
 void
 usage(char* me, int status, FILE* out)
 {
-        fprintf(out,"RCSID: %s RELEASE: %s\n", rcsid, POSTGIS_VERSION);
+               fprintf(out,"RCSID: %s RELEASE: %s\n", rcsid, POSTGIS_VERSION);
        fprintf(out,"USAGE: %s [<options>] <database> [<schema>.]<table>\n", me);
        fprintf(out,"       %s [<options>] <database> <query>\n", me);
        fprintf(out,"\n");
-               fprintf(out,"OPTIONS:\n");
-               fprintf(out,"  -f <filename>  Use this option to specify the name of the file\n");
-               fprintf(out,"     to create.\n");
-               fprintf(out,"  -h <host>  Allows you to specify connection to a database on a\n");
+               fprintf(out,"OPTIONS:\n");
+               fprintf(out,"  -f <filename>  Use this option to specify the name of the file\n");
+               fprintf(out,"     to create.\n");
+               fprintf(out,"  -h <host>  Allows you to specify connection to a database on a\n");
        fprintf(out,"     machine other than the default.\n");
-               fprintf(out,"  -p <port>  Allows you to specify a database port other than the default.\n");
-               fprintf(out,"  -P <password>  Connect to the database with the specified password.\n");
-               fprintf(out,"  -u <user>  Connect to the database as the specified user.\n");
+               fprintf(out,"  -p <port>  Allows you to specify a database port other than the default.\n");
+               fprintf(out,"  -P <password>  Connect to the database with the specified password.\n");
+               fprintf(out,"  -u <user>  Connect to the database as the specified user.\n");
        fprintf(out,"  -g <geometry_column> Specify the geometry column to be exported.\n");
        fprintf(out,"  -b Use a binary cursor.\n");
        fprintf(out,"  -r Raw mode. Do not assume table has been created by \n");
        fprintf(out,"     the loader. This would not unescape attribute names\n");
        fprintf(out,"     and will not skip the 'gid' attribute.\n");
        fprintf(out,"  -k Keep postgresql identifiers case.\n");
-        fprintf(out,"  -? Display this help screen.\n");
-               fprintf(out,"\n");
-               exit (status);
+               fprintf(out,"  -? Display this help screen.\n");
+               fprintf(out,"\n");
+               exit (status);
 }
 
 /* Parse command line parameters */
@@ -2345,15 +2345,15 @@ parse_commandline(int ARGC, char **ARGV)
 {
        int c, curindex;
        char buf[2048];
-        
-        if ( ARGC == 1 ) {
-                usage(ARGV[0], 0, stdout);
-        }
+
+               if ( ARGC == 1 ) {
+                               usage(ARGV[0], 0, stdout);
+               }
 
        memset(buf, 0, 2048); /* just in case... */
 
        /* Parse command line */
-        while ((c = pgis_getopt(ARGC, ARGV, "bf:h:du:p:P:g:rk")) != EOF){
+               while ((c = pgis_getopt(ARGC, ARGV, "bf:h:du:p:P:g:rk")) != EOF){
                switch (c) {
                        case 'b':
                                binary = 1;
@@ -2362,21 +2362,21 @@ parse_commandline(int ARGC, char **ARGV)
                                shp_file = optarg;
                                break;
                        case 'h':
-                               snprintf(buf + strlen(buf), 255, "host=%s ", optarg);   
+                               snprintf(buf + strlen(buf), 255, "host=%s ", optarg);
                                break;
                        case 'd':
                                dswitchprovided = 1;
                                outtype = 'z';
-                               break;            
+                               break;
                        case 'r':
                                includegid = 1;
                                unescapedattrs = 1;
-                               break;            
+                               break;
                        case 'u':
                                snprintf(buf + strlen(buf), 255, "user=%s ", optarg);
                                break;
                        case 'p':
-                               snprintf(buf + strlen(buf), 255, "port=%s ", optarg);   
+                               snprintf(buf + strlen(buf), 255, "port=%s ", optarg);
                                break;
                        case 'P':
                                snprintf(buf + strlen(buf), 255, "password=%s ", optarg);
@@ -2388,27 +2388,27 @@ parse_commandline(int ARGC, char **ARGV)
                                keep_fieldname_case = 1;
                                break;
                        case '?':
-                                usage(ARGV[0], 0, stdout);
+                                                               usage(ARGV[0], 0, stdout);
                        default:
                                return 0;
                }
-        }
+               }
 
-        curindex=0;
-        for (; optind<ARGC; optind++){
-                if (curindex == 0) {
-                       snprintf(buf + strlen(buf), 255, "dbname=%s", ARGV[optind]);
-                }else if(curindex == 1){
+               curindex=0;
+               for (; optind<ARGC; optind++){
+                               if (curindex == 0) {
+                               snprintf(buf + strlen(buf), 255, "dbname=%s", ARGV[optind]);
+                               }else if(curindex == 1){
                        parse_table(ARGV[optind]);
 
-                }
-                curindex++;
-        }
-        if (curindex < 2) return 0;
-       
+                               }
+                               curindex++;
+               }
+               if (curindex < 2) return 0;
+
        /* Copy the buffer result to the connection string */
-       strncpy(conn_string, buf, 2048);        
-       
+       strncpy(conn_string, buf, 2048);
+
        return 1;
 }
 
@@ -2557,7 +2557,7 @@ initialize(void)
                        if ( ! geo_col_name )
                        {
                                geom_fld = mainscan_nflds;
-                               type_ary[mainscan_nflds]=9; 
+                               type_ary[mainscan_nflds]=9;
                                geo_col_name = fname;
                                mainscan_flds[mainscan_nflds++] = fname;
                        }
@@ -2569,7 +2569,7 @@ initialize(void)
                        else if (!strcmp(geo_col_name, fname))
                        {
                                geom_fld = mainscan_nflds;
-                               type_ary[mainscan_nflds]=9; 
+                               type_ary[mainscan_nflds]=9;
                                mainscan_flds[mainscan_nflds++] = fname;
                        }
 
@@ -2577,7 +2577,7 @@ initialize(void)
                }
 
 
-               /* 
+               /*
                 * Everything else (non geometries) will be
                 * a DBF attribute.
                 */
@@ -2604,7 +2604,7 @@ initialize(void)
                strncpy(field_name, ptr, 10);
                field_name[10] = 0;
 
-               /* 
+               /*
                 * make sure the fields all have unique names,
                 */
                tmpint=1;
@@ -2639,7 +2639,7 @@ initialize(void)
                /* int2 type */
                if ( type == 21 )
                {
-                       /* 
+                       /*
                         * Longest text representation for
                         * an int2 type (16bit) is 6 bytes
                         * (-32768)
@@ -2659,7 +2659,7 @@ initialize(void)
                /* int4 type */
                if ( type == 23 )
                {
-                       /* 
+                       /*
                         * Longest text representation for
                         * an int4 type (32bit) is 11 bytes
                         * (-2147483648)
@@ -2679,7 +2679,7 @@ initialize(void)
                /* int8 type */
                if ( type == 20 )
                {
-                       /* 
+                       /*
                         * Longest text representation for
                         * an int8 type (64bit) is 20 bytes
                         * (-9223372036854775808)
@@ -2695,10 +2695,10 @@ initialize(void)
                        mainscan_flds[mainscan_nflds++] = fname;
                        continue;
                }
-               
+
                /*
                 * double or numeric types:
-                *    700: float4
+                *    700: float4
                 *    701: float8
                 *   1700: numeric
                 *
@@ -2762,7 +2762,7 @@ initialize(void)
                }
 
                /*
-                * For variable-sized fields we'll use either 
+                * For variable-sized fields we'll use either
                 * maximum allowed size (atttypmod) or max actual
                 * attribute value in table.
                 */
@@ -2848,7 +2848,7 @@ initialize(void)
                                else if (outtype == 'm') outshptype=SHPT_ARCM;
                                else outshptype=SHPT_ARC;
                                break;
-                               
+
                        case POLYGONTYPE:
                        case MULTIPOLYGONTYPE:
                                if (outtype == 'z') outshptype=SHPT_POLYGONZ;
@@ -2879,7 +2879,7 @@ initialize(void)
                shp = SHPCreate(shp_file, outshptype);
        }
 
-       /* 
+       /*
         * Ok. Now we should have an array of allocate strings
         * representing the fields we'd like to be returned by
         * main scan query.
@@ -2901,7 +2901,7 @@ initialize(void)
                /* this is the geometry */
                if ( type_ary[i] == 9 )
                {
-                       if ( big_endian ) 
+                       if ( big_endian )
                        {
 
 
@@ -2988,7 +2988,7 @@ initialize(void)
        return 1;
 }
 
-/* 
+/*
  * Return the maximum octet_length from given table.
  * Return -1 on error.
  */
@@ -3005,14 +3005,14 @@ getMaxFieldSize(PGconn *conn, char *schema, char *table, char *fname)
        if ( schema )
        {
                query = (char *)malloc(strlen(fname)+strlen(table)+
-                       strlen(schema)+40); 
+                       strlen(schema)+40);
                sprintf(query,
                        "select max(octet_length(\"%s\")) from \"%s\".\"%s\"",
                        fname, schema, table);
        }
        else
        {
-               query = (char *)malloc(strlen(fname)+strlen(table)+40); 
+               query = (char *)malloc(strlen(fname)+strlen(table)+40);
                sprintf(query,
                        "select max(octet_length(\"%s\")) from \"%s\"",
                        fname, table);
@@ -3049,7 +3049,7 @@ HexDecode(const char *hex)
        const char *hexptr;
        byte byt;
        int len;
-       
+
        len = strlen(hex)/2;
        ret = (byte *)malloc(len);
        if ( ! ret )  {
@@ -3130,7 +3130,7 @@ is_bigendian(void)
  *
  * The following functions might go in a wkb lib
  *
- * Right now they work on a binary representation, they 
+ * Right now they work on a binary representation, they
  * might work on an exadecimal representation of it as returned
  * by text cursors by postgis.
  *
@@ -3148,7 +3148,7 @@ dump_wkb(byte *wkb)
        else if ( byteOrder == 1 ) printf("ByteOrder: NDR\n");
        else printf("ByteOrder: unknown (%d)\n", byteOrder);
 
-       type = popint(&wkb); 
+       type = popint(&wkb);
        if ( type&WKBZOFFSET ) printf ("Has Z!\n");
        if ( type&WKBMOFFSET ) printf ("Has M!\n");
        type &= ~WKBZOFFSET; /* strip Z flag */
@@ -3253,17 +3253,17 @@ parse_table(char *spec)
                usrquery = spec;
 
                /*
-                * encode pid in table name to reduce 
+                * encode pid in table name to reduce
                 * clashes probability (see bug#115)
                 */
                sprintf(temptablename,
                        "__pgsql2shp%lu_tmp_table",
                        (long)getpid());
-               table = temptablename; 
+               table = temptablename;
        }
        else
        {
-               table = spec;
+                       table = spec;
                if ( (ptr=strchr(table, '.')) )
                {
                        *ptr = '\0';
@@ -3282,7 +3282,7 @@ create_usrquerytable(void)
        query = malloc(strlen(table)+strlen(usrquery)+32);
        sprintf(query, "CREATE TEMP TABLE \"%s\" AS %s", table, usrquery);
 
-        printf("Preparing table for user query... ");
+               printf("Preparing table for user query... ");
        fflush(stdout);
        res = PQexec(conn, query);
        free(query);
@@ -3312,7 +3312,7 @@ nullDBFValue(char fieldType)
                        return "00000000";
 
                case FTLogical:
-                       /* NULL boolean fields have value "?" */ 
+                       /* NULL boolean fields have value "?" */
                        return "?";
 
                default:
@@ -3321,9 +3321,9 @@ nullDBFValue(char fieldType)
        }
 }
 
-/* 
+/*
  * Make appropriate formatting of a DBF value based on type.
- * Might return untouched input or pointer to static private 
+ * Might return untouched input or pointer to static private
  * buffer: use return value right away.
  */
 static const char *
@@ -3361,9 +3361,9 @@ goodDBFValue(const char *in, char fieldType)
 
 int projFileCreate(const char * pszFilename, char *schema, char *table, char *geo_col_name)
 {
-    FILE       *fp;
-    char       *pszFullname, *pszBasename;
-    int                i, result;
+       FILE    *fp;
+       char    *pszFullname, *pszBasename;
+       int             i, result;
        char *srtext;
        char *query;
        char *esc_schema;
@@ -3372,7 +3372,7 @@ int projFileCreate(const char * pszFilename, char *schema, char *table, char *ge
        int error;
        PGresult *res;
        int size;
-       
+
        /***********
        *** I'm multiplying by 2 instead of 3 because I am too lazy to figure out how many characters to add
        *** after escaping if any **/
@@ -3389,13 +3389,13 @@ int projFileCreate(const char * pszFilename, char *schema, char *table, char *ge
        /** make our address space large enough to hold query with table/schema **/
        query = (char *) malloc(size);
        if ( ! query ) return 0; /* out of virtual memory */
-       
+
        /**************************************************
         * Get what kind of spatial ref is the selected geometry field
         * We first check the geometry_columns table for a match and then if no match do a distinct against the table
         * NOTE: COALESCE does a short-circuit check returning the faster query result and skipping the second if first returns something
-        *      Escaping quotes in the schema and table in query may not be necessary except to prevent malicious attacks 
-        *      or should someone be crazy enough to have quotes or other weird character in their table, column or schema names 
+        *      Escaping quotes in the schema and table in query may not be necessary except to prevent malicious attacks
+        *      or should someone be crazy enough to have quotes or other weird character in their table, column or schema names
         **************************************************/
        if ( schema )
        {
@@ -3403,9 +3403,9 @@ int projFileCreate(const char * pszFilename, char *schema, char *table, char *ge
                PQescapeStringConn(conn, esc_schema, schema, strlen(schema), &error);
                sprintf(query, "SELECT COALESCE((SELECT sr.srtext "
                                " FROM  geometry_columns As gc INNER JOIN spatial_ref_sys sr ON sr.srid = gc.srid "
-                               " WHERE gc.f_table_schema = '%s' AND gc.f_table_name = '%s' AND gc.f_geometry_column = '%s' LIMIT 1),  " 
+                               " WHERE gc.f_table_schema = '%s' AND gc.f_table_name = '%s' AND gc.f_geometry_column = '%s' LIMIT 1),  "
                                " (SELECT CASE WHEN COUNT(DISTINCT sr.srid) > 1 THEN 'm' ELSE MAX(sr.srtext) END As srtext "
-                       " FROM \"%s\".\"%s\" As g INNER JOIN spatial_ref_sys sr ON sr.srid = ST_SRID(g.\"%s\")) , ' ') As srtext ", 
+                       " FROM \"%s\".\"%s\" As g INNER JOIN spatial_ref_sys sr ON sr.srid = ST_SRID(g.\"%s\")) , ' ') As srtext ",
                                esc_schema, esc_table,esc_geo_col_name, schema, table, geo_col_name);
                free(esc_schema);
        }
@@ -3415,7 +3415,7 @@ int projFileCreate(const char * pszFilename, char *schema, char *table, char *ge
                                " FROM  geometry_columns As gc INNER JOIN spatial_ref_sys sr ON sr.srid = gc.srid "
                                " WHERE gc.f_table_name = '%s' AND gc.f_geometry_column = '%s' AND pg_table_is_visible((gc.f_table_schema || '.' || gc.f_table_name)::regclass) LIMIT 1),  "
                                " (SELECT CASE WHEN COUNT(DISTINCT sr.srid) > 1 THEN 'm' ELSE MAX(sr.srtext) END as srtext "
-                       " FROM \"%s\" As g INNER JOIN spatial_ref_sys sr ON sr.srid = ST_SRID(g.\"%s\")), ' ') As srtext ", 
+                       " FROM \"%s\" As g INNER JOIN spatial_ref_sys sr ON sr.srid = ST_SRID(g.\"%s\")), ' ') As srtext ",
                                esc_table, esc_geo_col_name, table, geo_col_name);
        }
 
@@ -3424,7 +3424,7 @@ int projFileCreate(const char * pszFilename, char *schema, char *table, char *ge
        free(esc_geo_col_name);
 
        res = PQexec(conn, query);
-       
+
        if ( ! res || PQresultStatus(res) != PGRES_TUPLES_OK ) {
                printf( "Error: %s", PQerrorMessage(conn));
                return 0;
@@ -3434,36 +3434,36 @@ int projFileCreate(const char * pszFilename, char *schema, char *table, char *ge
        {
                srtext = PQgetvalue(res, i, 0);
                if (strcmp(srtext,"m") == 0){
-                       printf("ERROR: Mixed set of spatial references.\n");    
+                       printf("ERROR: Mixed set of spatial references.\n");
                        PQclear(res);
                        return 0;
                }
                else {
                        if (srtext[0] == ' '){
-                               printf("ERROR: Cannot determine spatial reference (empty table or unknown spatial ref).\n");
+                               printf("WARNING: Can not determine spatial reference (empty table or unknown spatial ref).\n");
                                PQclear(res);
                                return 0;
                        }
-                       else {  
+                       else {
                                /* -------------------------------------------------------------------- */
                                /*      Compute the base (layer) name.  If there is any extension       */
                                /*      on the passed in filename we will strip it off.                 */
                                /* -------------------------------------------------------------------- */
                                        pszBasename = (char *) malloc(strlen(pszFilename)+5);
                                        strcpy( pszBasename, pszFilename );
-                                       for( i = strlen(pszBasename)-1; 
+                                       for( i = strlen(pszBasename)-1;
                                         i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/'
                                                   && pszBasename[i] != '\\';
                                         i-- ) {}
-                               
+
                                        if( pszBasename[i] == '.' )
                                                pszBasename[i] = '\0';
-                               
+
                                        pszFullname = (char *) malloc(strlen(pszBasename) + 5);
                                        sprintf( pszFullname, "%s.prj", pszBasename );
                                        free( pszBasename );
-                                       
-                               
+
+
                                /* -------------------------------------------------------------------- */
                                /*      Create the file.                                                */
                                /* -------------------------------------------------------------------- */