[postgis-tickets] r15379 - Fix check for empty or null geometry and more strict precision reducing

bjorn at wololo.org bjorn at wololo.org
Sun Apr 30 14:36:43 PDT 2017


Author: bjornharrtell
Date: 2017-04-30 14:36:42 -0700 (Sun, 30 Apr 2017)
New Revision: 15379

Modified:
   trunk/postgis/mvt.c
Log:
Fix check for empty or null geometry and more strict precision reducing

Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c	2017-04-28 21:07:50 UTC (rev 15378)
+++ trunk/postgis/mvt.c	2017-04-30 21:36:42 UTC (rev 15379)
@@ -468,17 +468,17 @@
 	POSTGIS_DEBUGF(3, "parse_values n_tags %d", ctx->feature->n_tags);
 }
 
-static int max_dim(LWCOLLECTION *lwcoll)
+static int max_type(LWCOLLECTION *lwcoll)
 {
-	int i, dim = 1;
+	int i, max = POINTTYPE;
 	for (i = 0; i < lwcoll->ngeoms; i++) {
 		uint8_t type = lwcoll->geoms[i]->type;
 		if (type == POLYGONTYPE || type == MULTIPOLYGONTYPE)
-			return 3;
+			return POLYGONTYPE;
 		else if (type == LINETYPE || type == MULTILINETYPE)
-			dim = 2;
+			max = LINETYPE;
 	}
-	return dim;
+	return max;
 }
 
 /**
@@ -551,20 +551,21 @@
 
 	LWGEOM *lwgeom_out = lwgeom_grid(lwgeom, &grid);
 
-	if (lwgeom_out == NULL)
-		lwgeom_out = lwgeom_grid(lwgeom_centroid(lwgeom), &grid);
+	if (lwgeom_out == NULL || lwgeom_is_empty(lwgeom_out))
+		return NULL;
 
 	lwgeom_force_clockwise(lwgeom_out);
 	lwgeom_out = lwgeom_make_valid(lwgeom_out);
 
 	if (lwgeom_out->type == COLLECTIONTYPE) {
-		LWCOLLECTION *lwcoll = (LWCOLLECTION*) lwgeom_out;
+		LWCOLLECTION *lwcoll = lwgeom_as_lwcollection(lwgeom_out);
 		lwgeom_out = lwcollection_as_lwgeom(
-			lwcollection_extract(lwcoll, max_dim(lwcoll)));
-		lwgeom_out = lwgeom_homogenize(lwgeom_out);
+			lwcollection_extract(lwcoll, max_type(lwcoll)));
+		//lwgeom_out = lwgeom_homogenize(lwgeom_out);
+		// TODO: might not be valid here... may want to union?
 	}
 
-	if (lwgeom == NULL || lwgeom_is_empty(lwgeom))
+	if (lwgeom_out == NULL || lwgeom_is_empty(lwgeom_out))
 		return NULL;
 
 	return lwgeom_out;



More information about the postgis-tickets mailing list