From: Sandro Santilli Date: Fri, 4 Apr 2014 11:47:12 +0000 (+0000) Subject: Fix type detection in tables with null geometries (#2700) X-Git-Tag: 2.2.0rc1~1158 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=957e1835035379e4b56b0def4455b3cdab412266;p=postgis Fix type detection in tables with null geometries (#2700) Includes testcase git-svn-id: http://svn.osgeo.org/postgis/trunk@12421 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/loader/pgsql2shp-core.c b/loader/pgsql2shp-core.c index 382c759d3..3a8dc29d1 100644 --- a/loader/pgsql2shp-core.c +++ b/loader/pgsql2shp-core.c @@ -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 index 000000000..0d64ead77 --- /dev/null +++ b/regress/dumper/null3d.dmp @@ -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 index 000000000..b07eb81b1 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 index 000000000..2a7c13cbb 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 index 000000000..346787e8e Binary files /dev/null and b/regress/dumper/null3d_expected.shx differ diff --git a/regress/run_test.pl b/regress/run_test.pl index 81879a0c8..129362566 100755 --- a/regress/run_test.pl +++ b/regress/run_test.pl @@ -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). ##################################################################