]> granicus.if.org Git - postgis/commitdiff
Handle NULL geometry values in pgsql2shp
authorPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 29 Jul 2019 16:45:24 +0000 (16:45 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 29 Jul 2019 16:45:24 +0000 (16:45 +0000)
Closes #4209

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

NEWS
loader/pgsql2shp-core.c

diff --git a/NEWS b/NEWS
index 6ede78aa532ad27e65bdb412729fbe6d504b8236..879cacde5de26eacb3fc56b0ca72cf129a208519 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ PostGIS 2.3.10
   - #4327, Avoid pfree'ing the result of getenv (Raúl Marín)
   - #4406, Throw on invalid characters when decoding geohash (Raúl Marín)
   - #4466, Fix undefined behaviour in _postgis_gserialized_stats (Raúl Marín)
+  - #4209, Handle NULL geometry values in pgsql2shp (Paul Ramsey)
 
 
 PostGIS 2.3.9
index 97762b33e8c73d6eb0bd1b988a2efa18fd9fca27..3027edb655853734373d9f6941136a2b965b75f5 100644 (file)
@@ -887,15 +887,15 @@ getTableInfo(SHPDUMPERSTATE *state)
                {
                        query = malloc(150 + 4 * strlen(state->geo_col_name) + strlen(state->schema) + strlen(state->table));
 
-                       sprintf(query, "SELECT count(\"%s\"), max(ST_zmflag(\"%s\"::geometry)), geometrytype(\"%s\"::geometry) FROM \"%s\".\"%s\" GROUP BY geometrytype(\"%s\"::geometry)",
-                       state->geo_col_name, state->geo_col_name, state->geo_col_name, state->schema, state->table, state->geo_col_name);
+                       sprintf(query, "SELECT count(1), max(ST_zmflag(\"%s\"::geometry)), geometrytype(\"%s\"::geometry) FROM \"%s\".\"%s\" GROUP BY 3",
+                       state->geo_col_name, state->geo_col_name, state->schema, state->table);
                }
                else
                {
                        query = malloc(150 + 4 * strlen(state->geo_col_name) + strlen(state->table));
 
-                       sprintf(query, "SELECT count(\"%s\"), max(ST_zmflag(\"%s\"::geometry)), geometrytype(\"%s\"::geometry) FROM \"%s\" GROUP BY geometrytype(\"%s\"::geometry)",
-                       state->geo_col_name, state->geo_col_name, state->geo_col_name, state->table, state->geo_col_name);
+                       sprintf(query, "SELECT count(1), max(ST_zmflag(\"%s\"::geometry)), geometrytype(\"%s\"::geometry) FROM \"%s\" GROUP BY 3",
+                       state->geo_col_name, state->geo_col_name, state->table);
                }
        }
        else
@@ -955,9 +955,14 @@ getTableInfo(SHPDUMPERSTATE *state)
 
                for (i = 0; i < PQntuples(res); i++)
                {
-                       geometry_type_from_string(PQgetvalue(res, i, 2), &type, &dummy, &dummy);
+                       /* skip null geometries */
+                       if (PQgetisnull(res, i, 2))
+                       {
+                               state->rowcount += atoi(PQgetvalue(res, i, 0));
+                               continue;
+                       }
 
-                       if (!type) continue; /* skip null geometries */
+                       geometry_type_from_string(PQgetvalue(res, i, 2), &type, &dummy, &dummy);
 
                        /* We can always set typefound to that of the first column found */
                        if (!typefound)