]> granicus.if.org Git - postgis/commitdiff
Handled 0-DBF-attributes corner case.
authorSandro Santilli <strk@keybit.net>
Wed, 6 Oct 2004 09:40:27 +0000 (09:40 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 6 Oct 2004 09:40:27 +0000 (09:40 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@944 b70326c6-7e19-0410-871a-916f4a2858ee

loader/shp2pgsql.c

index ac7d8f76a84f2377dccffafb12638726a81eff7c..c268d4a8a939bf843895fb2eee91ec7e29208646 100644 (file)
@@ -12,6 +12,9 @@
  * 
  **********************************************************************
  * $Log$
+ * Revision 1.66  2004/10/06 09:40:27  strk
+ * Handled 0-DBF-attributes corner case.
+ *
  * Revision 1.65  2004/09/20 17:13:31  strk
  * changed comments to better show shape type handling
  *
@@ -497,8 +500,8 @@ int ring_check(SHPObject* obj, char *schema, char *table, char *sr_id)
                }
        }
 
-       if (dump_format) printf("\tSRID=%s ;MULTIPOLYGON(",sr_id );
-       else printf(",GeometryFromText('MULTIPOLYGON(");
+       if (dump_format) printf("SRID=%s ;MULTIPOLYGON(",sr_id );
+       else printf("GeometryFromText('MULTIPOLYGON(");
 
        for(u=0; u < out_index; u++){
                Poly = Outer[u];
@@ -620,11 +623,11 @@ Insert_attributes(DBFHandle hDBFHandle, int row)
          }
  
                        if (dump_format) {
-            if ( i ) printf("\t");
                                printf("%s",make_good_string(val));
+                               if ( i ) printf("\t");
                        } else {
-            if ( i ) printf(",");
                                printf("'%s'",protect_quotes_string(val));
+                               if ( i ) printf(",");
                        }
                 }
        }
@@ -829,13 +832,14 @@ main (int ARGC, char **ARGV)
        types = (DBFFieldType *)malloc(num_fields*sizeof(int));
        widths = malloc(num_fields*sizeof(int));
        precisions = malloc(num_fields*sizeof(int));
-       col_names = malloc(num_fields * sizeof(char) * 32);
+       col_names = malloc((num_fields+2) * sizeof(char) * 32);
        if(opt != 'a'){
                strcpy(col_names, "(gid," );
        }else{
                strcpy(col_names, "(" );
        }
 
+       //fprintf(stderr, "Number of fields from DBF: %d\n", num_fields);
        for(j=0;j<num_fields;j++)
        {
                type = DBFGetFieldInfo(hDBFHandle, j, name, &field_width, &field_precision); 
@@ -899,10 +903,10 @@ main (int ARGC, char **ARGV)
                field_names[j] = malloc ( strlen(name)+3 );
                strcpy(field_names[j], name);
 
+               sprintf(col_names, "%s\"%s\",", col_names, name);
                if (j) strcat(col_names, ",");
-               sprintf(col_names, "%s\"%s\"", col_names, name);
        }
-       sprintf(col_names, "%s\"%s\")", col_names, geom);
+       sprintf(col_names, "%s\"%s\")", col_names, geom);
 
 
        SHPGetInfo( hSHPHandle, &num_entities, &phnshapetype, &padminbound[0], &padmaxbound[0]);
@@ -995,8 +999,8 @@ main (int ARGC, char **ARGV)
                // ---------- NULL SHAPE -----------------
                if (obj->nVertices == 0)
                {
-                       if (dump_format) printf("\t\\N\n\\.\n");
-                       else printf("NULL);\n");
+                       if (dump_format) printf("\\N\n\\.\n");
+                       else printf("NULL);\n");
                }
 
                 // --------- POLYGON / POLYGONM / POLYGONZ ------
@@ -1011,8 +1015,8 @@ main (int ARGC, char **ARGV)
                else if( obj->nSHPType == 1 || obj->nSHPType == 21 )
                {
 
-                       if (dump_format) printf("\tSRID=%s;POINT(",sr_id);
-                       else printf(",GeometryFromText('POINT (");
+                       if (dump_format) printf("SRID=%s;POINT(",sr_id);
+                       else printf("GeometryFromText('POINT (");
 
                        for (u=0;u<obj->nVertices; u++){
                                if (u>0) printf(",");
@@ -1039,16 +1043,16 @@ main (int ARGC, char **ARGV)
                                fprintf(stderr,
        "MULTILINESTRING %d as %d vertices, set to NULL\n",
        j, obj->nVertices);
-                               if (dump_format) printf("\t\\N\n");
-                               else printf(",NULL);\n");
+                               if (dump_format) printf("\\N\n");
+                               else printf("NULL);\n");
 
                                SHPDestroyObject(obj);
 
                                continue;
                        }
 
-                       if (dump_format) printf("\tSRID=%s;MULTILINESTRING(",sr_id);
-                       else printf(",GeometryFromText('MULTILINESTRING (");
+                       if (dump_format) printf("SRID=%s;MULTILINESTRING(",sr_id);
+                       else printf("GeometryFromText('MULTILINESTRING (");
 
                        //for each vertice write out the coordinates in the insert statement, when there is a new line 
                        //you must end the brackets and start new ones etc.
@@ -1087,8 +1091,8 @@ main (int ARGC, char **ARGV)
                //-------- MULTIPOINT / MULTIPOINTM ------------
                else if( obj->nSHPType == 8 || obj->nSHPType == 28 )
                {
-                       if (dump_format) printf("\tSRID=%s;MULTIPOINT(",sr_id);
-                       else printf(",GeometryFromText('MULTIPOINT ("); 
+                       if (dump_format) printf("SRID=%s;MULTIPOINT(",sr_id);
+                       else printf("GeometryFromText('MULTIPOINT ("); 
                        
                        for (u=0;u<obj->nVertices; u++){
                                if (u>0) printf(",");
@@ -1102,8 +1106,8 @@ main (int ARGC, char **ARGV)
                //---------- POINTZ ----------
                else if( obj->nSHPType == 11 )
                { 
-                       if (dump_format) printf("\tSRID=%s;POINT(",sr_id);
-                       else printf(",GeometryFromText('POINT ("); 
+                       if (dump_format) printf("SRID=%s;POINT(",sr_id);
+                       else printf("GeometryFromText('POINT ("); 
                        
                        for (u=0;u<obj->nVertices; u++){
                                if (u>0) printf(",");
@@ -1126,8 +1130,8 @@ main (int ARGC, char **ARGV)
                                fprintf(stderr,
        "MULTILINESTRING %d as %d vertices, set to NULL\n",
        j, obj->nVertices);
-                               if (dump_format) printf("\t\\N\n");
-                               else printf(",NULL);\n");
+                               if (dump_format) printf("\\N\n");
+                               else printf("NULL);\n");
 
                                SHPDestroyObject(obj);
                                continue;
@@ -1141,8 +1145,8 @@ main (int ARGC, char **ARGV)
                        else next_ring = -99;
 
                        if (dump_format)
-                               printf("\tSRID=%s;MULTILINESTRING(",sr_id);
-                       else printf(",GeometryFromText('MULTILINESTRING (");
+                               printf("SRID=%s;MULTILINESTRING(",sr_id);
+                       else printf("GeometryFromText('MULTILINESTRING (");
 
                        //for each vertice write out the coordinates in the insert statement, when there is a new line 
                        //you must end the brackets and start new ones etc.
@@ -1173,8 +1177,8 @@ main (int ARGC, char **ARGV)
                else if( obj->nSHPType == 18 )
                {
 
-                       if (dump_format) printf("\tSRID=%s;MULTIPOINT(",sr_id);
-                       else printf(",GeometryFromText('MULTIPOINT (");
+                       if (dump_format) printf("SRID=%s;MULTIPOINT(",sr_id);
+                       else printf("GeometryFromText('MULTIPOINT (");
 
                        for (u=0;u<obj->nVertices; u++){
                                if (u>0){