[postgis-tickets] r17643 - Handle NULL geometry values in pgsql2shp

Paul Ramsey pramsey at cleverelephant.ca
Mon Jul 29 09:45:24 PDT 2019


Author: pramsey
Date: 2019-07-29 09:45:24 -0700 (Mon, 29 Jul 2019)
New Revision: 17643

Modified:
   branches/2.3/NEWS
   branches/2.3/loader/pgsql2shp-core.c
Log:
Handle NULL geometry values in pgsql2shp
Closes #4209


Modified: branches/2.3/NEWS
===================================================================
--- branches/2.3/NEWS	2019-07-29 16:45:15 UTC (rev 17642)
+++ branches/2.3/NEWS	2019-07-29 16:45:24 UTC (rev 17643)
@@ -9,6 +9,7 @@
   - #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

Modified: branches/2.3/loader/pgsql2shp-core.c
===================================================================
--- branches/2.3/loader/pgsql2shp-core.c	2019-07-29 16:45:15 UTC (rev 17642)
+++ branches/2.3/loader/pgsql2shp-core.c	2019-07-29 16:45:24 UTC (rev 17643)
@@ -887,15 +887,15 @@
 		{
 			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,10 +955,15 @@
 
 		for (i = 0; i < PQntuples(res); i++)
 		{
+			/* skip null geometries */
+			if (PQgetisnull(res, i, 2))
+			{
+				state->rowcount += atoi(PQgetvalue(res, i, 0));
+				continue;
+			}
+
 			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;



More information about the postgis-tickets mailing list