]> granicus.if.org Git - postgis/commitdiff
Fix type detection in tables with null geometries (#2700)
authorSandro Santilli <strk@keybit.net>
Fri, 4 Apr 2014 11:47:12 +0000 (11:47 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 4 Apr 2014 11:47:12 +0000 (11:47 +0000)
Includes testcase

git-svn-id: http://svn.osgeo.org/postgis/trunk@12421 b70326c6-7e19-0410-871a-916f4a2858ee

loader/pgsql2shp-core.c
regress/dumper/null3d.dmp [new file with mode: 0644]
regress/dumper/null3d_expected.dbf [new file with mode: 0644]
regress/dumper/null3d_expected.shp [new file with mode: 0644]
regress/dumper/null3d_expected.shx [new file with mode: 0644]
regress/run_test.pl

index 382c759d350917cf0bfcfd221f1369665ee62feb..3a8dc29d17e26d92949d75032b4e003478dac1dd 100644 (file)
@@ -707,7 +707,7 @@ projFileCreate(SHPDUMPERSTATE *state)
 {
        FILE    *fp;
        char    *pszFullname, *pszBasename;
-       int     i, result;
+       int     i;
 
        char *pszFilename = state->shp_file;
        char *schema = state->schema;
@@ -833,7 +833,7 @@ projFileCreate(SHPDUMPERSTATE *state)
                                {
                                        return 0;
                                }
-                               result = fputs (srtext,fp);
+                               fputs (srtext, fp);
                                LWDEBUGF(3, "\n result %d proj SRText is %s .\n", result, srtext);
                                fclose( fp );
                                free( pszFullname );
@@ -944,6 +944,8 @@ getTableInfo(SHPDUMPERSTATE *state)
                {
                        geometry_type_from_string(PQgetvalue(res, i, 2), &type, &dummy, &dummy);
 
+                       if (!type) continue; /* skip null geometries */
+
                        /* We can always set typefound to that of the first column found */
                        if (!typefound)
                                typefound = type;
@@ -995,6 +997,24 @@ getTableInfo(SHPDUMPERSTATE *state)
 
                        /* Update the rowcount for each type */
                        state->rowcount += atoi(PQgetvalue(res, i, 0));
+
+                       /* Set up the dimension output type (note: regardless of how many rows
+                                the table metadata query returns, this value will be the same. But
+                                we'll choose to use the first value anyway) */
+                       tmpint = atoi(PQgetvalue(res, i, 1));
+                       switch (tmpint)
+                       {
+                       case 0:
+                               state->outtype = 's';
+                               break;
+                       case 1:
+                               state->outtype = 'm';
+                               break;
+                       default:
+                               state->outtype = 'z';
+                               break;
+                       }
+
                }
 
                /* Flag an error if the table contains incompatible geometry combinations */
@@ -1005,23 +1025,6 @@ getTableInfo(SHPDUMPERSTATE *state)
                        return SHPDUMPERERR;
                }
 
-               /* Set up the dimension output type (note: regardless of how many rows
-                  the table metadata query returns, this value will be the same. But
-                  we'll choose to use the first value anyway) */
-               tmpint = atoi(PQgetvalue(res, 0, 1));
-               switch (tmpint)
-               {
-               case 0:
-                       state->outtype = 's';
-                       break;
-               case 1:
-                       state->outtype = 'm';
-                       break;
-               default:
-                       state->outtype = 'z';
-                       break;
-               }
-
                /* Set up the shapefile output type based upon the dimension information */
                switch (typefound)
                {
diff --git a/regress/dumper/null3d.dmp b/regress/dumper/null3d.dmp
new file mode 100644 (file)
index 0000000..0d64ead
--- /dev/null
@@ -0,0 +1 @@
+SELECT null::geometry as g UNION ALL SELECT 'SRID=1;POINT(0 0 0 0)'::geometry;
diff --git a/regress/dumper/null3d_expected.dbf b/regress/dumper/null3d_expected.dbf
new file mode 100644 (file)
index 0000000..b07eb81
Binary files /dev/null and b/regress/dumper/null3d_expected.dbf differ
diff --git a/regress/dumper/null3d_expected.shp b/regress/dumper/null3d_expected.shp
new file mode 100644 (file)
index 0000000..2a7c13c
Binary files /dev/null and b/regress/dumper/null3d_expected.shp differ
diff --git a/regress/dumper/null3d_expected.shx b/regress/dumper/null3d_expected.shx
new file mode 100644 (file)
index 0000000..346787e
Binary files /dev/null and b/regress/dumper/null3d_expected.shx differ
index 81879a0c8b24b90aa2c9c2a301c85fce34d8b972..12936256658ab7a7918229c70e2c908c60c0477a 100755 (executable)
@@ -749,7 +749,7 @@ sub run_loader_and_check_output
 # $1 - Description of this run of the dumper, used for error messages.
 # $2 - Table name to dump from.
 # $3 - "Expected" .shp file to compare with.
-# $3 - If you pass true, this will run the loader even if neither
+# $4 - If you pass true, this will run the loader even if neither
 #      of the expected results files exists (though of course
 #      the results won't be compared with anything).
 ##################################################################