From 50e08323002510e2bf6382ade6a35dbbc265f082 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 28 Feb 2018 22:20:14 +0000 Subject: [PATCH] Fix space-indented astyle call git-svn-id: http://svn.osgeo.org/postgis/trunk@16438 b70326c6-7e19-0410-871a-916f4a2858ee --- topology/postgis_topology.c | 1917 +++++++++++++++++++++-------------- 1 file changed, 1144 insertions(+), 773 deletions(-) diff --git a/topology/postgis_topology.c b/topology/postgis_topology.c index 587f8daf3..c39bac16c 100644 --- a/topology/postgis_topology.c +++ b/topology/postgis_topology.c @@ -58,7 +58,8 @@ LWT_BE_IFACE* be_iface; * Private data we'll use for this backend */ #define MAXERRLEN 256 -struct LWT_BE_DATA_T { +struct LWT_BE_DATA_T +{ char lastErrorMsg[MAXERRLEN]; /* * This flag will need to be set to false @@ -76,7 +77,8 @@ struct LWT_BE_DATA_T { LWT_BE_DATA be_data; -struct LWT_BE_TOPOLOGY_T { +struct LWT_BE_TOPOLOGY_T +{ LWT_BE_DATA* be_data; char *name; int id; @@ -89,20 +91,20 @@ struct LWT_BE_TOPOLOGY_T { /* utility funx */ static void cberror(const LWT_BE_DATA* be, const char *fmt, ...) - __attribute__ (( format(printf, 2, 3) )); +__attribute__ (( format(printf, 2, 3) )); static void cberror(const LWT_BE_DATA* be_in, const char *fmt, ...) { LWT_BE_DATA *be = (LWT_BE_DATA*)be_in;/*const cast*/ - va_list ap; + va_list ap; - va_start(ap, fmt); + va_start(ap, fmt); - vsnprintf (be->lastErrorMsg, MAXERRLEN, fmt, ap); - be->lastErrorMsg[MAXERRLEN-1]='\0'; + vsnprintf (be->lastErrorMsg, MAXERRLEN, fmt, ap); + be->lastErrorMsg[MAXERRLEN-1]='\0'; - va_end(ap); + va_end(ap); } static void @@ -112,7 +114,8 @@ _lwtype_upper_name(int type, char *buf, size_t buflen) snprintf(buf, buflen, "%s", lwtype_name(type)); buf[buflen-1] = '\0'; ptr = buf; - while (*ptr) { + while (*ptr) + { *ptr = toupper(*ptr); ++ptr; } @@ -172,8 +175,8 @@ cb_loadTopologyByName(const LWT_BE_DATA* be, const char *name) argtypes[0] = CSTRINGOID; sql = - "SELECT id,srid,precision,null::geometry " - "FROM topology.topology WHERE name = $1::varchar"; + "SELECT id,srid,precision,null::geometry " + "FROM topology.topology WHERE name = $1::varchar"; if ( ! plan ) /* prepare on first call */ { plan = SPI_prepare(sql, 1, argtypes); @@ -191,23 +194,27 @@ cb_loadTopologyByName(const LWT_BE_DATA* be, const char *name) values[0] = CStringGetDatum(name); spi_result = SPI_execute_plan(plan, values, NULL, !be->data_changed, 1); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(be, "unexpected return (%d) from query execution: %s", spi_result, sql); - return NULL; + if ( spi_result != SPI_OK_SELECT ) + { + cberror(be, "unexpected return (%d) from query execution: %s", spi_result, sql); + return NULL; } if ( ! SPI_processed ) { - if ( be->topoLoadFailMessageFlavor == 1 ) { + if ( be->topoLoadFailMessageFlavor == 1 ) + { cberror(be, "No topology with name \"%s\" in topology.topology", name); - } else { - cberror(be, "SQL/MM Spatial exception - invalid topology name"); } - return NULL; + else + { + cberror(be, "SQL/MM Spatial exception - invalid topology name"); + } + return NULL; } if ( SPI_processed > 1 ) { - cberror(be, "multiple topologies named '%s' were found", name); - return NULL; + cberror(be, "multiple topologies named '%s' were found", name); + return NULL; } topo = palloc(sizeof(LWT_BE_TOPOLOGY)); @@ -215,16 +222,18 @@ cb_loadTopologyByName(const LWT_BE_DATA* be, const char *name) topo->name = pstrdup(name); dat = SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull); - if ( isnull ) { - cberror(be, "Topology '%s' has null identifier", name); + if ( isnull ) + { + cberror(be, "Topology '%s' has null identifier", name); SPI_freetuptable(SPI_tuptable); return NULL; } topo->id = DatumGetInt32(dat); dat = SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 2, &isnull); - if ( isnull ) { - cberror(be, "Topology '%s' has null SRID", name); + if ( isnull ) + { + cberror(be, "Topology '%s' has null SRID", name); SPI_freetuptable(SPI_tuptable); return NULL; } @@ -237,10 +246,13 @@ cb_loadTopologyByName(const LWT_BE_DATA* be, const char *name) } dat = SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 3, &isnull); - if ( isnull ) { - lwnotice("Topology '%s' has null precision, taking as 0", name); + if ( isnull ) + { + lwnotice("Topology '%s' has null precision, taking as 0", name); topo->precision = 0; /* TODO: should this be -1 instead ? */ - } else { + } + else + { topo->precision = DatumGetFloat8(dat); } @@ -252,8 +264,8 @@ cb_loadTopologyByName(const LWT_BE_DATA* be, const char *name) #endif POSTGIS_DEBUGF(1, "cb_loadTopologyByName: topo '%s' has " - "id %d, srid %d, precision %g", - name, topo->id, topo->srid, topo->precision); + "id %d, srid %d, precision %g", + name, topo->id, topo->srid, topo->precision); SPI_freetuptable(SPI_tuptable); @@ -291,37 +303,45 @@ addEdgeFields(StringInfo str, int fields, int fullEdgeData) { const char *sep = ""; - if ( fields & LWT_COL_EDGE_EDGE_ID ) { + if ( fields & LWT_COL_EDGE_EDGE_ID ) + { appendStringInfoString(str, "edge_id"); sep = ","; } - if ( fields & LWT_COL_EDGE_START_NODE ) { + if ( fields & LWT_COL_EDGE_START_NODE ) + { appendStringInfo(str, "%sstart_node", sep); sep = ","; } - if ( fields & LWT_COL_EDGE_END_NODE ) { + if ( fields & LWT_COL_EDGE_END_NODE ) + { appendStringInfo(str, "%send_node", sep); sep = ","; } - if ( fields & LWT_COL_EDGE_FACE_LEFT ) { + if ( fields & LWT_COL_EDGE_FACE_LEFT ) + { appendStringInfo(str, "%sleft_face", sep); sep = ","; } - if ( fields & LWT_COL_EDGE_FACE_RIGHT ) { + if ( fields & LWT_COL_EDGE_FACE_RIGHT ) + { appendStringInfo(str, "%sright_face", sep); sep = ","; } - if ( fields & LWT_COL_EDGE_NEXT_LEFT ) { + if ( fields & LWT_COL_EDGE_NEXT_LEFT ) + { appendStringInfo(str, "%snext_left_edge", sep); if ( fullEdgeData ) appendStringInfoString(str, ", abs_next_left_edge"); sep = ","; } - if ( fields & LWT_COL_EDGE_NEXT_RIGHT ) { + if ( fields & LWT_COL_EDGE_NEXT_RIGHT ) + { appendStringInfo(str, "%snext_right_edge", sep); if ( fullEdgeData ) appendStringInfoString(str, ", abs_next_right_edge"); sep = ","; } - if ( fields & LWT_COL_EDGE_GEOM ) { + if ( fields & LWT_COL_EDGE_GEOM ) + { appendStringInfo(str, "%sgeom", sep); } } @@ -335,36 +355,43 @@ addEdgeValues(StringInfo str, const LWT_ISO_EDGE *edge, int fields, int fullEdge const char *sep = ""; appendStringInfoChar(str, '('); - if ( fields & LWT_COL_EDGE_EDGE_ID ) { + if ( fields & LWT_COL_EDGE_EDGE_ID ) + { if ( edge->edge_id != -1 ) appendStringInfo(str, "%" LWTFMT_ELEMID, edge->edge_id); else appendStringInfoString(str, "DEFAULT"); sep = ","; } - if ( fields & LWT_COL_EDGE_START_NODE ) { + if ( fields & LWT_COL_EDGE_START_NODE ) + { appendStringInfo(str, "%s%" LWTFMT_ELEMID, sep, edge->start_node); sep = ","; } - if ( fields & LWT_COL_EDGE_END_NODE ) { + if ( fields & LWT_COL_EDGE_END_NODE ) + { appendStringInfo(str, "%s%" LWTFMT_ELEMID, sep, edge->end_node); sep = ","; } - if ( fields & LWT_COL_EDGE_FACE_LEFT ) { + if ( fields & LWT_COL_EDGE_FACE_LEFT ) + { appendStringInfo(str, "%s%" LWTFMT_ELEMID, sep, edge->face_left); sep = ","; } - if ( fields & LWT_COL_EDGE_FACE_RIGHT ) { + if ( fields & LWT_COL_EDGE_FACE_RIGHT ) + { appendStringInfo(str, "%s%" LWTFMT_ELEMID, sep, edge->face_right); sep = ","; } - if ( fields & LWT_COL_EDGE_NEXT_LEFT ) { + if ( fields & LWT_COL_EDGE_NEXT_LEFT ) + { appendStringInfo(str, "%s%" LWTFMT_ELEMID, sep, edge->next_left); if ( fullEdgeData ) appendStringInfo(str, ",%" LWTFMT_ELEMID, ABS(edge->next_left)); sep = ","; } - if ( fields & LWT_COL_EDGE_NEXT_RIGHT ) { + if ( fields & LWT_COL_EDGE_NEXT_RIGHT ) + { appendStringInfo(str, "%s%" LWTFMT_ELEMID, sep, edge->next_right); if ( fullEdgeData ) appendStringInfo(str, ",%" LWTFMT_ELEMID, ABS(edge->next_right)); @@ -372,19 +399,23 @@ addEdgeValues(StringInfo str, const LWT_ISO_EDGE *edge, int fields, int fullEdge } if ( fields & LWT_COL_EDGE_GEOM ) { - if ( edge->geom ) { + if ( edge->geom ) + { hexewkb = lwgeom_to_hexwkb(lwline_as_lwgeom(edge->geom), - WKB_EXTENDED, &hexewkb_size); + WKB_EXTENDED, &hexewkb_size); appendStringInfo(str, "%s'%s'::geometry", sep, hexewkb); lwfree(hexewkb); - } else { + } + else + { appendStringInfo(str, "%snull", sep); } } appendStringInfoChar(str, ')'); } -enum UpdateType { +enum UpdateType +{ updSet, updSel, updNot @@ -402,68 +433,78 @@ addEdgeUpdate(StringInfo str, const LWT_ISO_EDGE* edge, int fields, switch (updType) { - case updSet: - op = "="; - sep1 = ","; - break; - case updSel: - op = "="; - sep1 = " AND "; - break; - case updNot: - default: - op = "!="; - sep1 = " AND "; - break; - } - - if ( fields & LWT_COL_EDGE_EDGE_ID ) { + case updSet: + op = "="; + sep1 = ","; + break; + case updSel: + op = "="; + sep1 = " AND "; + break; + case updNot: + default: + op = "!="; + sep1 = " AND "; + break; + } + + if ( fields & LWT_COL_EDGE_EDGE_ID ) + { appendStringInfoString(str, "edge_id "); appendStringInfo(str, "%s %" LWTFMT_ELEMID, op, edge->edge_id); sep = sep1; } - if ( fields & LWT_COL_EDGE_START_NODE ) { + if ( fields & LWT_COL_EDGE_START_NODE ) + { appendStringInfo(str, "%sstart_node ", sep); appendStringInfo(str, "%s %" LWTFMT_ELEMID, op, edge->start_node); sep = sep1; } - if ( fields & LWT_COL_EDGE_END_NODE ) { + if ( fields & LWT_COL_EDGE_END_NODE ) + { appendStringInfo(str, "%send_node", sep); appendStringInfo(str, "%s %" LWTFMT_ELEMID, op, edge->end_node); sep = sep1; } - if ( fields & LWT_COL_EDGE_FACE_LEFT ) { + if ( fields & LWT_COL_EDGE_FACE_LEFT ) + { appendStringInfo(str, "%sleft_face", sep); appendStringInfo(str, "%s %" LWTFMT_ELEMID, op, edge->face_left); sep = sep1; } - if ( fields & LWT_COL_EDGE_FACE_RIGHT ) { + if ( fields & LWT_COL_EDGE_FACE_RIGHT ) + { appendStringInfo(str, "%sright_face", sep); appendStringInfo(str, "%s %" LWTFMT_ELEMID, op, edge->face_right); sep = sep1; } - if ( fields & LWT_COL_EDGE_NEXT_LEFT ) { + if ( fields & LWT_COL_EDGE_NEXT_LEFT ) + { appendStringInfo(str, "%snext_left_edge", sep); appendStringInfo(str, "%s %" LWTFMT_ELEMID, op, edge->next_left); sep = sep1; - if ( fullEdgeData ) { + if ( fullEdgeData ) + { appendStringInfo(str, "%s abs_next_left_edge", sep); appendStringInfo(str, "%s %" LWTFMT_ELEMID, op, ABS(edge->next_left)); } } - if ( fields & LWT_COL_EDGE_NEXT_RIGHT ) { + if ( fields & LWT_COL_EDGE_NEXT_RIGHT ) + { appendStringInfo(str, "%snext_right_edge", sep); appendStringInfo(str, "%s %" LWTFMT_ELEMID, op, edge->next_right); sep = sep1; - if ( fullEdgeData ) { + if ( fullEdgeData ) + { appendStringInfo(str, "%s abs_next_right_edge", sep); appendStringInfo(str, "%s %" LWTFMT_ELEMID, op, ABS(edge->next_right)); } } - if ( fields & LWT_COL_EDGE_GEOM ) { + if ( fields & LWT_COL_EDGE_GEOM ) + { appendStringInfo(str, "%sgeom", sep); hexewkb = lwgeom_to_hexwkb(lwline_as_lwgeom(edge->geom), - WKB_EXTENDED, &hexewkb_size); + WKB_EXTENDED, &hexewkb_size); appendStringInfo(str, "%s'%s'::geometry", op, hexewkb); lwfree(hexewkb); } @@ -481,39 +522,45 @@ addNodeUpdate(StringInfo str, const LWT_ISO_NODE* node, int fields, switch (updType) { - case updSet: - op = "="; - sep1 = ","; - break; - case updSel: - op = "="; - sep1 = " AND "; - break; - case updNot: - default: - op = "!="; - sep1 = " AND "; - break; - } - - if ( fields & LWT_COL_NODE_NODE_ID ) { + case updSet: + op = "="; + sep1 = ","; + break; + case updSel: + op = "="; + sep1 = " AND "; + break; + case updNot: + default: + op = "!="; + sep1 = " AND "; + break; + } + + if ( fields & LWT_COL_NODE_NODE_ID ) + { appendStringInfoString(str, "node_id "); appendStringInfo(str, "%s %" LWTFMT_ELEMID, op, node->node_id); sep = sep1; } - if ( fields & LWT_COL_NODE_CONTAINING_FACE ) { + if ( fields & LWT_COL_NODE_CONTAINING_FACE ) + { appendStringInfo(str, "%scontaining_face %s", sep, op); - if ( node->containing_face != -1 ) { + if ( node->containing_face != -1 ) + { appendStringInfo(str, "%" LWTFMT_ELEMID, node->containing_face); - } else { + } + else + { appendStringInfoString(str, "null::int"); } sep = sep1; } - if ( fields & LWT_COL_NODE_GEOM ) { + if ( fields & LWT_COL_NODE_GEOM ) + { appendStringInfo(str, "%sgeom", sep); hexewkb = lwgeom_to_hexwkb(lwpoint_as_lwgeom(node->geom), - WKB_EXTENDED, &hexewkb_size); + WKB_EXTENDED, &hexewkb_size); appendStringInfo(str, "%s'%s'::geometry", op, hexewkb); lwfree(hexewkb); } @@ -524,15 +571,18 @@ addNodeFields(StringInfo str, int fields) { const char *sep = ""; - if ( fields & LWT_COL_NODE_NODE_ID ) { + if ( fields & LWT_COL_NODE_NODE_ID ) + { appendStringInfoString(str, "node_id"); sep = ","; } - if ( fields & LWT_COL_NODE_CONTAINING_FACE ) { + if ( fields & LWT_COL_NODE_CONTAINING_FACE ) + { appendStringInfo(str, "%scontaining_face", sep); sep = ","; } - if ( fields & LWT_COL_NODE_GEOM ) { + if ( fields & LWT_COL_NODE_GEOM ) + { appendStringInfo(str, "%sgeom", sep); } } @@ -542,11 +592,13 @@ addFaceFields(StringInfo str, int fields) { const char *sep = ""; - if ( fields & LWT_COL_FACE_FACE_ID ) { + if ( fields & LWT_COL_FACE_FACE_ID ) + { appendStringInfoString(str, "face_id"); sep = ","; } - if ( fields & LWT_COL_FACE_MBR ) { + if ( fields & LWT_COL_FACE_MBR ) + { appendStringInfo(str, "%smbr", sep); sep = ","; } @@ -562,7 +614,8 @@ addNodeValues(StringInfo str, const LWT_ISO_NODE *node, int fields) appendStringInfoChar(str, '('); - if ( fields & LWT_COL_NODE_NODE_ID ) { + if ( fields & LWT_COL_NODE_NODE_ID ) + { if ( node->node_id != -1 ) appendStringInfo(str, "%" LWTFMT_ELEMID, node->node_id); else @@ -570,19 +623,24 @@ addNodeValues(StringInfo str, const LWT_ISO_NODE *node, int fields) sep = ","; } - if ( fields & LWT_COL_NODE_CONTAINING_FACE ) { + if ( fields & LWT_COL_NODE_CONTAINING_FACE ) + { if ( node->containing_face != -1 ) appendStringInfo(str, "%s%" LWTFMT_ELEMID, sep, node->containing_face); else appendStringInfo(str, "%snull::int", sep); } - if ( fields & LWT_COL_NODE_GEOM ) { - if ( node->geom ) { + if ( fields & LWT_COL_NODE_GEOM ) + { + if ( node->geom ) + { hexewkb = lwgeom_to_hexwkb(lwpoint_as_lwgeom(node->geom), - WKB_EXTENDED, &hexewkb_size); + WKB_EXTENDED, &hexewkb_size); appendStringInfo(str, "%s'%s'::geometry", sep, hexewkb); lwfree(hexewkb); - } else { + } + else + { appendStringInfo(str, "%snull::geometry", sep); } } @@ -599,12 +657,17 @@ addFaceValues(StringInfo str, LWT_ISO_FACE *face, int srid) else appendStringInfoString(str, "(DEFAULT"); - if ( face->mbr ) {{ - char *hexbox; - hexbox = _box2d_to_hexwkb(face->mbr, srid); - appendStringInfo(str, ",ST_Envelope('%s'::geometry))", hexbox); - lwfree(hexbox); - }} else { + if ( face->mbr ) + { + { + char *hexbox; + hexbox = _box2d_to_hexwkb(face->mbr, srid); + appendStringInfo(str, ",ST_Envelope('%s'::geometry))", hexbox); + lwfree(hexbox); + } + } + else + { appendStringInfoString(str, ",null::geometry)"); } } @@ -620,106 +683,140 @@ fillEdgeFields(LWT_ISO_EDGE* edge, HeapTuple row, TupleDesc rowdesc, int fields) int colno = 0; POSTGIS_DEBUGF(2, "fillEdgeFields: got %d atts and fields %x", - rowdesc->natts, fields); + rowdesc->natts, fields); - if ( fields & LWT_COL_EDGE_EDGE_ID ) { + if ( fields & LWT_COL_EDGE_EDGE_ID ) + { dat = SPI_getbinval(row, rowdesc, ++colno, &isnull); - if ( isnull ) { + if ( isnull ) + { lwpgwarning("Found edge with NULL edge_id"); edge->edge_id = -1; - } else { + } + else + { val = DatumGetInt32(dat); POSTGIS_DEBUGF(2, "fillEdgeFields: colno%d (edge_id)" - " has int32 val of %d", - colno, val); + " has int32 val of %d", + colno, val); edge->edge_id = val; } } - if ( fields & LWT_COL_EDGE_START_NODE ) { + if ( fields & LWT_COL_EDGE_START_NODE ) + { dat = SPI_getbinval(row, rowdesc, ++colno, &isnull); - if ( isnull ) { + if ( isnull ) + { lwpgwarning("Found edge with NULL start_node"); edge->start_node = -1; - } else { + } + else + { val = DatumGetInt32(dat); POSTGIS_DEBUGF(2, "fillEdgeFields: colno%d (start_node)" - " has int32 val of %d", colno, val); + " has int32 val of %d", colno, val); edge->start_node = val; } } - if ( fields & LWT_COL_EDGE_END_NODE ) { + if ( fields & LWT_COL_EDGE_END_NODE ) + { dat = SPI_getbinval(row, rowdesc, ++colno, &isnull); - if ( isnull ) { + if ( isnull ) + { lwpgwarning("Found edge with NULL end_node"); edge->end_node = -1; - } else { + } + else + { val = DatumGetInt32(dat); POSTGIS_DEBUGF(2, "fillEdgeFields: colno%d (end_node)" - " has int32 val of %d", colno, val); + " has int32 val of %d", colno, val); edge->end_node = val; } } - if ( fields & LWT_COL_EDGE_FACE_LEFT ) { + if ( fields & LWT_COL_EDGE_FACE_LEFT ) + { dat = SPI_getbinval(row, rowdesc, ++colno, &isnull); - if ( isnull ) { + if ( isnull ) + { lwpgwarning("Found edge with NULL face_left"); edge->face_left = -1; - } else { + } + else + { val = DatumGetInt32(dat); POSTGIS_DEBUGF(2, "fillEdgeFields: colno%d (face_left)" - " has int32 val of %d", colno, val); + " has int32 val of %d", colno, val); edge->face_left = val; } } - if ( fields & LWT_COL_EDGE_FACE_RIGHT ) { + if ( fields & LWT_COL_EDGE_FACE_RIGHT ) + { dat = SPI_getbinval(row, rowdesc, ++colno, &isnull); - if ( isnull ) { + if ( isnull ) + { lwpgwarning("Found edge with NULL face_right"); edge->face_right = -1; - } else { + } + else + { val = DatumGetInt32(dat); POSTGIS_DEBUGF(2, "fillEdgeFields: colno%d (face_right)" - " has int32 val of %d", colno, val); + " has int32 val of %d", colno, val); edge->face_right = val; } } - if ( fields & LWT_COL_EDGE_NEXT_LEFT ) { + if ( fields & LWT_COL_EDGE_NEXT_LEFT ) + { dat = SPI_getbinval(row, rowdesc, ++colno, &isnull); - if ( isnull ) { + if ( isnull ) + { lwpgwarning("Found edge with NULL next_left"); edge->next_left = -1; - } else { + } + else + { val = DatumGetInt32(dat); POSTGIS_DEBUGF(2, "fillEdgeFields: colno%d (next_left)" - " has int32 val of %d", colno, val); + " has int32 val of %d", colno, val); edge->next_left = val; } } - if ( fields & LWT_COL_EDGE_NEXT_RIGHT ) { + if ( fields & LWT_COL_EDGE_NEXT_RIGHT ) + { dat = SPI_getbinval(row, rowdesc, ++colno, &isnull); - if ( isnull ) { + if ( isnull ) + { lwpgwarning("Found edge with NULL next_right"); edge->next_right = -1; - } else { + } + else + { val = DatumGetInt32(dat); POSTGIS_DEBUGF(2, "fillEdgeFields: colno%d (next_right)" - " has int32 val of %d", colno, val); + " has int32 val of %d", colno, val); edge->next_right = val; } } - if ( fields & LWT_COL_EDGE_GEOM ) { + if ( fields & LWT_COL_EDGE_GEOM ) + { dat = SPI_getbinval(row, rowdesc, ++colno, &isnull); - if ( ! isnull ) {{ - MemoryContext oldcontext = CurrentMemoryContext; - geom = (GSERIALIZED *)PG_DETOAST_DATUM(dat); - lwg = lwgeom_from_gserialized(geom); - MemoryContextSwitchTo( TopMemoryContext ); - edge->geom = lwgeom_as_lwline(lwgeom_clone_deep(lwg)); - MemoryContextSwitchTo( oldcontext ); /* switch back */ - lwgeom_free(lwg); - if ( DatumGetPointer(dat) != (Pointer)geom ) pfree(geom); /* IF_COPY */ - }} else { + if ( ! isnull ) + { + { + MemoryContext oldcontext = CurrentMemoryContext; + geom = (GSERIALIZED *)PG_DETOAST_DATUM(dat); + lwg = lwgeom_from_gserialized(geom); + MemoryContextSwitchTo( TopMemoryContext ); + edge->geom = lwgeom_as_lwline(lwgeom_clone_deep(lwg)); + MemoryContextSwitchTo( oldcontext ); /* switch back */ + lwgeom_free(lwg); + if ( DatumGetPointer(dat) != (Pointer)geom ) pfree(geom); /* IF_COPY */ + } + } + else + { lwpgwarning("Found edge with NULL geometry !"); edge->geom = NULL; } @@ -735,24 +832,30 @@ fillNodeFields(LWT_ISO_NODE* node, HeapTuple row, TupleDesc rowdesc, int fields) LWGEOM *lwg; int colno = 0; - if ( fields & LWT_COL_NODE_NODE_ID ) { + if ( fields & LWT_COL_NODE_NODE_ID ) + { dat = SPI_getbinval(row, rowdesc, ++colno, &isnull); node->node_id = DatumGetInt32(dat); } - if ( fields & LWT_COL_NODE_CONTAINING_FACE ) { + if ( fields & LWT_COL_NODE_CONTAINING_FACE ) + { dat = SPI_getbinval(row, rowdesc, ++colno, &isnull); if ( isnull ) node->containing_face = -1; else node->containing_face = DatumGetInt32(dat); } - if ( fields & LWT_COL_NODE_GEOM ) { + if ( fields & LWT_COL_NODE_GEOM ) + { dat = SPI_getbinval(row, rowdesc, ++colno, &isnull); - if ( ! isnull ) { + if ( ! isnull ) + { geom = (GSERIALIZED *)PG_DETOAST_DATUM(dat); lwg = lwgeom_from_gserialized(geom); node->geom = lwgeom_as_lwpoint(lwgeom_clone_deep(lwg)); lwgeom_free(lwg); if ( DatumGetPointer(dat) != (Pointer)geom ) pfree(geom); /* IF_COPY */ - } else { + } + else + { lwpgnotice("Found node with NULL geometry !"); node->geom = NULL; } @@ -769,26 +872,34 @@ fillFaceFields(LWT_ISO_FACE* face, HeapTuple row, TupleDesc rowdesc, int fields) const GBOX *box; int colno = 0; - if ( fields & LWT_COL_FACE_FACE_ID ) { + if ( fields & LWT_COL_FACE_FACE_ID ) + { dat = SPI_getbinval(row, rowdesc, ++colno, &isnull); face->face_id = DatumGetInt32(dat); } - if ( fields & LWT_COL_FACE_MBR ) { + if ( fields & LWT_COL_FACE_MBR ) + { dat = SPI_getbinval(row, rowdesc, ++colno, &isnull); - if ( ! isnull ) { + if ( ! isnull ) + { /* NOTE: this is a geometry of which we want to take (and clone) the BBOX */ geom = (GSERIALIZED *)PG_DETOAST_DATUM(dat); g = lwgeom_from_gserialized(geom); box = lwgeom_get_bbox(g); - if ( box ) { + if ( box ) + { face->mbr = gbox_clone(box); - } else { + } + else + { lwpgnotice("Found face with EMPTY MBR !"); face->mbr = NULL; } lwgeom_free(g); if ( DatumGetPointer(dat) != (Pointer)geom ) pfree(geom); - } else { + } + else + { /* NOTE: perfectly fine for universe face */ POSTGIS_DEBUG(1, "Found face with NULL MBR"); face->mbr = NULL; @@ -811,10 +922,10 @@ getNotNullInt32( HeapTuple row, TupleDesc desc, int col, int32 *val ) static LWT_ISO_EDGE* cb_getEdgeById(const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, int* numelems, int fields) + const LWT_ELEMID* ids, int* numelems, int fields) { LWT_ISO_EDGE *edges; - int spi_result; + int spi_result; MemoryContext oldcontext = CurrentMemoryContext; StringInfoData sqldata; StringInfo sql = &sqldata; @@ -826,7 +937,8 @@ cb_getEdgeById(const LWT_BE_TOPOLOGY* topo, appendStringInfo(sql, " FROM \"%s\".edge_data", topo->name); appendStringInfoString(sql, " WHERE edge_id IN ("); // add all identifiers here - for (i=0; i<*numelems; ++i) { + for (i=0; i<*numelems; ++i) + { appendStringInfo(sql, "%s%" LWTFMT_ELEMID, (i?",":""), ids[i]); } appendStringInfoString(sql, ")"); @@ -834,16 +946,19 @@ cb_getEdgeById(const LWT_BE_TOPOLOGY* topo, spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, *numelems); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); + if ( spi_result != SPI_OK_SELECT ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - *numelems = -1; return NULL; + *numelems = -1; + return NULL; } pfree(sqldata.data); POSTGIS_DEBUGF(1, "cb_getEdgeById: edge query returned %d rows", SPI_processed); *numelems = SPI_processed; - if ( ! SPI_processed ) { + if ( ! SPI_processed ) + { return NULL; } @@ -861,10 +976,10 @@ cb_getEdgeById(const LWT_BE_TOPOLOGY* topo, static LWT_ISO_EDGE* cb_getEdgeByNode(const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, int* numelems, int fields) + const LWT_ELEMID* ids, int* numelems, int fields) { LWT_ISO_EDGE *edges; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; @@ -877,12 +992,14 @@ cb_getEdgeByNode(const LWT_BE_TOPOLOGY* topo, appendStringInfo(sql, " FROM \"%s\".edge_data", topo->name); appendStringInfoString(sql, " WHERE start_node IN ("); // add all identifiers here - for (i=0; i<*numelems; ++i) { + for (i=0; i<*numelems; ++i) + { appendStringInfo(sql, "%s%" LWTFMT_ELEMID, (i?",":""), ids[i]); } appendStringInfoString(sql, ") OR end_node IN ("); // add all identifiers here - for (i=0; i<*numelems; ++i) { + for (i=0; i<*numelems; ++i) + { appendStringInfo(sql, "%s%" LWTFMT_ELEMID, (i?",":""), ids[i]); } appendStringInfoString(sql, ")"); @@ -892,16 +1009,19 @@ cb_getEdgeByNode(const LWT_BE_TOPOLOGY* topo, spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); + if ( spi_result != SPI_OK_SELECT ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - *numelems = -1; return NULL; + *numelems = -1; + return NULL; } pfree(sqldata.data); POSTGIS_DEBUGF(1, "cb_getEdgeByNode: edge query returned %d rows", SPI_processed); *numelems = SPI_processed; - if ( ! SPI_processed ) { + if ( ! SPI_processed ) + { return NULL; } @@ -919,11 +1039,11 @@ cb_getEdgeByNode(const LWT_BE_TOPOLOGY* topo, static LWT_ISO_EDGE* cb_getEdgeByFace(const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, int* numelems, int fields, - const GBOX *box) + const LWT_ELEMID* ids, int* numelems, int fields, + const GBOX *box) { LWT_ISO_EDGE *edges; - int spi_result; + int spi_result; MemoryContext oldcontext = CurrentMemoryContext; StringInfoData sqldata; StringInfo sql = &sqldata; @@ -943,8 +1063,8 @@ cb_getEdgeByFace(const LWT_BE_TOPOLOGY* topo, appendStringInfoString(sql, "SELECT "); addEdgeFields(sql, fields, 0); appendStringInfo(sql, " FROM \"%s\".edge_data" - " WHERE ( left_face = ANY($1) " - " OR right_face = ANY ($1) )", + " WHERE ( left_face = ANY($1) " + " OR right_face = ANY ($1) )", topo->name); values[0] = PointerGetDatum(array_ids); @@ -970,16 +1090,19 @@ cb_getEdgeByFace(const LWT_BE_TOPOLOGY* topo, pfree(array_ids); /* not needed anymore */ if ( gser ) pfree(gser); /* not needed anymore */ MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); + if ( spi_result != SPI_OK_SELECT ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - *numelems = -1; return NULL; + *numelems = -1; + return NULL; } pfree(sqldata.data); POSTGIS_DEBUGF(1, "cb_getEdgeByFace: edge query returned %d rows", SPI_processed); *numelems = SPI_processed; - if ( ! SPI_processed ) { + if ( ! SPI_processed ) + { return NULL; } @@ -997,10 +1120,10 @@ cb_getEdgeByFace(const LWT_BE_TOPOLOGY* topo, static LWT_ISO_FACE* cb_getFacesById(const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, int* numelems, int fields) + const LWT_ELEMID* ids, int* numelems, int fields) { LWT_ISO_FACE *faces; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; int i; @@ -1012,7 +1135,8 @@ cb_getFacesById(const LWT_BE_TOPOLOGY* topo, appendStringInfo(sql, " FROM \"%s\".face", topo->name); appendStringInfoString(sql, " WHERE face_id IN ("); // add all identifiers here - for (i=0; i<*numelems; ++i) { + for (i=0; i<*numelems; ++i) + { appendStringInfo(sql, "%s%" LWTFMT_ELEMID, (i?",":""), ids[i]); } appendStringInfoString(sql, ")"); @@ -1022,16 +1146,19 @@ cb_getFacesById(const LWT_BE_TOPOLOGY* topo, spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); + if ( spi_result != SPI_OK_SELECT ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - *numelems = -1; return NULL; + *numelems = -1; + return NULL; } pfree(sqldata.data); POSTGIS_DEBUGF(1, "cb_getFaceById: face query returned %d rows", SPI_processed); *numelems = SPI_processed; - if ( ! SPI_processed ) { + if ( ! SPI_processed ) + { return NULL; } @@ -1049,10 +1176,10 @@ cb_getFacesById(const LWT_BE_TOPOLOGY* topo, static LWT_ELEMID* cb_getRingEdges(const LWT_BE_TOPOLOGY* topo, - LWT_ELEMID edge, int* numelems, int limit) + LWT_ELEMID edge, int* numelems, int limit) { LWT_ELEMID *edges; - int spi_result; + int spi_result; TupleDesc rowdesc; StringInfoData sqldata; StringInfo sql = &sqldata; @@ -1061,18 +1188,19 @@ cb_getRingEdges(const LWT_BE_TOPOLOGY* topo, initStringInfo(sql); appendStringInfo(sql, "WITH RECURSIVE edgering AS ( " - "SELECT %" LWTFMT_ELEMID - " as signed_edge_id, edge_id, next_left_edge, next_right_edge " - "FROM \"%s\".edge_data WHERE edge_id = %" LWTFMT_ELEMID " UNION " - "SELECT CASE WHEN " - "p.signed_edge_id < 0 THEN p.next_right_edge ELSE p.next_left_edge END, " - "e.edge_id, e.next_left_edge, e.next_right_edge " - "FROM \"%s\".edge_data e, edgering p WHERE " - "e.edge_id = CASE WHEN p.signed_edge_id < 0 THEN " - "abs(p.next_right_edge) ELSE abs(p.next_left_edge) END ) " - "SELECT * FROM edgering", - edge, topo->name, ABS(edge), topo->name); - if ( limit ) { + "SELECT %" LWTFMT_ELEMID + " as signed_edge_id, edge_id, next_left_edge, next_right_edge " + "FROM \"%s\".edge_data WHERE edge_id = %" LWTFMT_ELEMID " UNION " + "SELECT CASE WHEN " + "p.signed_edge_id < 0 THEN p.next_right_edge ELSE p.next_left_edge END, " + "e.edge_id, e.next_left_edge, e.next_right_edge " + "FROM \"%s\".edge_data e, edgering p WHERE " + "e.edge_id = CASE WHEN p.signed_edge_id < 0 THEN " + "abs(p.next_right_edge) ELSE abs(p.next_left_edge) END ) " + "SELECT * FROM edgering", + edge, topo->name, ABS(edge), topo->name); + if ( limit ) + { ++limit; /* so we know if we hit it */ appendStringInfo(sql, " LIMIT %d", limit); } @@ -1080,22 +1208,26 @@ cb_getRingEdges(const LWT_BE_TOPOLOGY* topo, POSTGIS_DEBUGF(1, "cb_getRingEdges query (limit %d): %s", limit, sql->data); spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, limit); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); + if ( spi_result != SPI_OK_SELECT ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - *numelems = -1; return NULL; + *numelems = -1; + return NULL; } pfree(sqldata.data); POSTGIS_DEBUGF(1, "cb_getRingEdges: edge query returned %d rows", SPI_processed); *numelems = SPI_processed; - if ( ! SPI_processed ) { + if ( ! SPI_processed ) + { return NULL; } if ( limit && SPI_processed == limit ) { cberror(topo->be_data, "Max traversing limit hit: %d", limit-1); - *numelems = -1; return NULL; + *numelems = -1; + return NULL; } edges = palloc( sizeof(LWT_ELEMID) * SPI_processed ); @@ -1107,15 +1239,17 @@ cb_getRingEdges(const LWT_BE_TOPOLOGY* topo, Datum dat; int32 val; dat = SPI_getbinval(row, rowdesc, 1, &isnull); - if ( isnull ) { + if ( isnull ) + { lwfree(edges); cberror(topo->be_data, "Found edge with NULL edge_id"); - *numelems = -1; return NULL; + *numelems = -1; + return NULL; } val = DatumGetInt32(dat); edges[i] = val; POSTGIS_DEBUGF(1, "Component %d in ring of edge %" LWTFMT_ELEMID - " is edge %d", i, edge, val); + " is edge %d", i, edge, val); } SPI_freetuptable(SPI_tuptable); @@ -1125,10 +1259,10 @@ cb_getRingEdges(const LWT_BE_TOPOLOGY* topo, static LWT_ISO_NODE* cb_getNodeById(const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, int* numelems, int fields) + const LWT_ELEMID* ids, int* numelems, int fields) { LWT_ISO_NODE *nodes; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; @@ -1141,23 +1275,27 @@ cb_getNodeById(const LWT_BE_TOPOLOGY* topo, appendStringInfo(sql, " FROM \"%s\".node", topo->name); appendStringInfoString(sql, " WHERE node_id IN ("); // add all identifiers here - for (i=0; i<*numelems; ++i) { + for (i=0; i<*numelems; ++i) + { appendStringInfo(sql, "%s%" LWTFMT_ELEMID, (i?",":""), ids[i]); } appendStringInfoString(sql, ")"); POSTGIS_DEBUGF(1, "cb_getNodeById query: %s", sql->data); spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, *numelems); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); + if ( spi_result != SPI_OK_SELECT ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - *numelems = -1; return NULL; + *numelems = -1; + return NULL; } pfree(sqldata.data); POSTGIS_DEBUGF(1, "cb_getNodeById: edge query returned %d rows", SPI_processed); *numelems = SPI_processed; - if ( ! SPI_processed ) { + if ( ! SPI_processed ) + { return NULL; } @@ -1175,11 +1313,11 @@ cb_getNodeById(const LWT_BE_TOPOLOGY* topo, static LWT_ISO_NODE* cb_getNodeByFace(const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, int* numelems, int fields, - const GBOX *box) + const LWT_ELEMID* ids, int* numelems, int fields, + const GBOX *box) { LWT_ISO_NODE *nodes; - int spi_result; + int spi_result; MemoryContext oldcontext = CurrentMemoryContext; StringInfoData sqldata; StringInfo sql = &sqldata; @@ -1192,7 +1330,8 @@ cb_getNodeByFace(const LWT_BE_TOPOLOGY* topo, appendStringInfo(sql, " FROM \"%s\".node", topo->name); appendStringInfoString(sql, " WHERE containing_face IN ("); // add all identifiers here - for (i=0; i<*numelems; ++i) { + for (i=0; i<*numelems; ++i) + { appendStringInfo(sql, "%s%" LWTFMT_ELEMID, (i?",":""), ids[i]); } appendStringInfoString(sql, ")"); @@ -1206,16 +1345,19 @@ cb_getNodeByFace(const LWT_BE_TOPOLOGY* topo, POSTGIS_DEBUGF(1, "data_changed is %d", topo->be_data->data_changed); spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); + if ( spi_result != SPI_OK_SELECT ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - *numelems = -1; return NULL; + *numelems = -1; + return NULL; } pfree(sqldata.data); POSTGIS_DEBUGF(1, "cb_getNodeByFace: edge query returned %d rows", SPI_processed); *numelems = SPI_processed; - if ( ! SPI_processed ) { + if ( ! SPI_processed ) + { return NULL; } @@ -1233,11 +1375,11 @@ cb_getNodeByFace(const LWT_BE_TOPOLOGY* topo, static LWT_ISO_EDGE* cb_getEdgeWithinDistance2D(const LWT_BE_TOPOLOGY* topo, - const LWPOINT* pt, double dist, int* numelems, - int fields, int limit) + const LWPOINT* pt, double dist, int* numelems, + int fields, int limit) { LWT_ISO_EDGE *edges; - int spi_result; + int spi_result; int elems_requested = limit; size_t hexewkb_size; char *hexewkb; @@ -1247,41 +1389,53 @@ cb_getEdgeWithinDistance2D(const LWT_BE_TOPOLOGY* topo, int i; initStringInfo(sql); - if ( elems_requested == -1 ) { + if ( elems_requested == -1 ) + { appendStringInfoString(sql, "SELECT EXISTS ( SELECT 1"); - } else { + } + else + { appendStringInfoString(sql, "SELECT "); addEdgeFields(sql, fields, 0); } appendStringInfo(sql, " FROM \"%s\".edge_data", topo->name); // TODO: use binary cursor here ? hexewkb = lwgeom_to_hexwkb(lwpoint_as_lwgeom(pt), WKB_EXTENDED, &hexewkb_size); - if ( dist ) { + if ( dist ) + { appendStringInfo(sql, " WHERE ST_DWithin('%s'::geometry, geom, %g)", hexewkb, dist); - } else { + } + else + { appendStringInfo(sql, " WHERE ST_Within('%s'::geometry, geom)", hexewkb); } lwfree(hexewkb); - if ( elems_requested == -1 ) { + if ( elems_requested == -1 ) + { appendStringInfoString(sql, ")"); - } else if ( elems_requested > 0 ) { + } + else if ( elems_requested > 0 ) + { appendStringInfo(sql, " LIMIT %d", elems_requested); } POSTGIS_DEBUGF(1, "cb_getEdgeWithinDistance2D: query is: %s", sql->data); spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, limit >= 0 ? limit : 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); + if ( spi_result != SPI_OK_SELECT ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - *numelems = -1; return NULL; + *numelems = -1; + return NULL; } pfree(sqldata.data); POSTGIS_DEBUGF(1, "cb_getEdgeWithinDistance2D: edge query " - "(limited by %d) returned %d rows", - elems_requested, SPI_processed); + "(limited by %d) returned %d rows", + elems_requested, SPI_processed); *numelems = SPI_processed; - if ( ! SPI_processed ) { + if ( ! SPI_processed ) + { return NULL; } @@ -1316,12 +1470,12 @@ cb_getEdgeWithinDistance2D(const LWT_BE_TOPOLOGY* topo, static LWT_ISO_NODE* cb_getNodeWithinDistance2D(const LWT_BE_TOPOLOGY* topo, - const LWPOINT* pt, double dist, int* numelems, - int fields, int limit) + const LWPOINT* pt, double dist, int* numelems, + int fields, int limit) { MemoryContext oldcontext = CurrentMemoryContext; LWT_ISO_NODE *nodes; - int spi_result; + int spi_result; size_t hexewkb_size; char *hexewkb; StringInfoData sqldata; @@ -1330,12 +1484,16 @@ cb_getNodeWithinDistance2D(const LWT_BE_TOPOLOGY* topo, int i; initStringInfo(sql); - if ( elems_requested == -1 ) { + if ( elems_requested == -1 ) + { appendStringInfoString(sql, "SELECT EXISTS ( SELECT 1"); - } else { + } + else + { appendStringInfoString(sql, "SELECT "); if ( fields ) addNodeFields(sql, fields); - else { + else + { lwpgwarning("liblwgeom-topo invoked 'getNodeWithinDistance2D' " "backend callback with limit=%d and no fields", elems_requested); @@ -1345,33 +1503,43 @@ cb_getNodeWithinDistance2D(const LWT_BE_TOPOLOGY* topo, appendStringInfo(sql, " FROM \"%s\".node", topo->name); // TODO: use binary cursor here ? hexewkb = lwgeom_to_hexwkb(lwpoint_as_lwgeom(pt), WKB_EXTENDED, &hexewkb_size); - if ( dist ) { + if ( dist ) + { appendStringInfo(sql, " WHERE ST_DWithin(geom, '%s'::geometry, %g)", hexewkb, dist); - } else { + } + else + { appendStringInfo(sql, " WHERE ST_Equals(geom, '%s'::geometry)", hexewkb); } lwfree(hexewkb); - if ( elems_requested == -1 ) { + if ( elems_requested == -1 ) + { appendStringInfoString(sql, ")"); - } else if ( elems_requested > 0 ) { + } + else if ( elems_requested > 0 ) + { appendStringInfo(sql, " LIMIT %d", elems_requested); } spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, limit >= 0 ? limit : 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", + if ( spi_result != SPI_OK_SELECT ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - *numelems = -1; return NULL; + *numelems = -1; + return NULL; } pfree(sqldata.data); POSTGIS_DEBUGF(1, "cb_getNodeWithinDistance2D: node query " - "(limited by %d) returned %d rows", - elems_requested, SPI_processed); - if ( ! SPI_processed ) { - *numelems = 0; return NULL; + "(limited by %d) returned %d rows", + elems_requested, SPI_processed); + if ( ! SPI_processed ) + { + *numelems = 0; + return NULL; } if ( elems_requested == -1 ) @@ -1407,10 +1575,10 @@ cb_getNodeWithinDistance2D(const LWT_BE_TOPOLOGY* topo, static int cb_insertNodes( const LWT_BE_TOPOLOGY* topo, - LWT_ISO_NODE* nodes, int numelems ) + LWT_ISO_NODE* nodes, int numelems ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; int i; @@ -1419,7 +1587,8 @@ cb_insertNodes( const LWT_BE_TOPOLOGY* topo, appendStringInfo(sql, "INSERT INTO \"%s\".node (", topo->name); addNodeFields(sql, LWT_COL_NODE_ALL); appendStringInfoString(sql, ") VALUES "); - for ( i=0; idata, false, numelems); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_INSERT_RETURNING ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", + if ( spi_result != SPI_OK_INSERT_RETURNING ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return 0; + return 0; } pfree(sqldata.data); if ( SPI_processed ) topo->be_data->data_changed = true; - if ( SPI_processed != numelems ) { + if ( SPI_processed != numelems ) + { cberror(topo->be_data, "processed " UINT64_FORMAT " rows, expected %d", - (uint64)SPI_processed, numelems); + (uint64)SPI_processed, numelems); return 0; } @@ -1452,7 +1623,7 @@ cb_insertNodes( const LWT_BE_TOPOLOGY* topo, { if ( nodes[i].node_id != -1 ) continue; fillNodeFields(&nodes[i], SPI_tuptable->vals[i], - SPI_tuptable->tupdesc, LWT_COL_NODE_NODE_ID); + SPI_tuptable->tupdesc, LWT_COL_NODE_NODE_ID); } SPI_freetuptable(SPI_tuptable); @@ -1462,10 +1633,10 @@ cb_insertNodes( const LWT_BE_TOPOLOGY* topo, static int cb_insertEdges( const LWT_BE_TOPOLOGY* topo, - LWT_ISO_EDGE* edges, int numelems ) + LWT_ISO_EDGE* edges, int numelems ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; int i; @@ -1476,7 +1647,8 @@ cb_insertEdges( const LWT_BE_TOPOLOGY* topo, appendStringInfo(sql, "INSERT INTO \"%s\".edge_data (", topo->name); addEdgeFields(sql, LWT_COL_EDGE_ALL, 1); appendStringInfoString(sql, ") VALUES "); - for ( i=0; ibe_data, "unexpected return (%d) from query execution: %s", + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return -1; + return -1; } pfree(sqldata.data); if ( SPI_processed ) topo->be_data->data_changed = true; POSTGIS_DEBUGF(1, "cb_insertEdges query processed %d rows", SPI_processed); - if ( SPI_processed != numelems ) { + if ( SPI_processed != numelems ) + { cberror(topo->be_data, "processed " UINT64_FORMAT " rows, expected %d", (uint64)SPI_processed, numelems); return -1; @@ -1510,7 +1683,7 @@ cb_insertEdges( const LWT_BE_TOPOLOGY* topo, { if ( edges[i].edge_id != -1 ) continue; fillEdgeFields(&edges[i], SPI_tuptable->vals[i], - SPI_tuptable->tupdesc, LWT_COL_EDGE_EDGE_ID); + SPI_tuptable->tupdesc, LWT_COL_EDGE_EDGE_ID); } } @@ -1521,10 +1694,10 @@ cb_insertEdges( const LWT_BE_TOPOLOGY* topo, static int cb_insertFaces( const LWT_BE_TOPOLOGY* topo, - LWT_ISO_FACE* faces, int numelems ) + LWT_ISO_FACE* faces, int numelems ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; int i; @@ -1534,7 +1707,8 @@ cb_insertFaces( const LWT_BE_TOPOLOGY* topo, appendStringInfo(sql, "INSERT INTO \"%s\".face (", topo->name); addFaceFields(sql, LWT_COL_FACE_ALL); appendStringInfoString(sql, ") VALUES "); - for ( i=0; isrid); @@ -1547,15 +1721,16 @@ cb_insertFaces( const LWT_BE_TOPOLOGY* topo, MemoryContextSwitchTo( oldcontext ); /* switch back */ if ( spi_result != ( needsFaceIdReturn ? SPI_OK_INSERT_RETURNING : SPI_OK_INSERT ) ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return -1; + return -1; } pfree(sqldata.data); if ( SPI_processed ) topo->be_data->data_changed = true; POSTGIS_DEBUGF(1, "cb_insertFaces query processed %d rows", SPI_processed); - if ( SPI_processed != numelems ) { + if ( SPI_processed != numelems ) + { cberror(topo->be_data, "processed " UINT64_FORMAT " rows, expected %d", (uint64)SPI_processed, numelems); return -1; @@ -1568,7 +1743,7 @@ cb_insertFaces( const LWT_BE_TOPOLOGY* topo, { if ( faces[i].face_id != -1 ) continue; fillFaceFields(&faces[i], SPI_tuptable->vals[i], - SPI_tuptable->tupdesc, LWT_COL_FACE_FACE_ID); + SPI_tuptable->tupdesc, LWT_COL_FACE_FACE_ID); } } @@ -1579,12 +1754,12 @@ cb_insertFaces( const LWT_BE_TOPOLOGY* topo, static int cb_updateEdges( const LWT_BE_TOPOLOGY* topo, - const LWT_ISO_EDGE* sel_edge, int sel_fields, - const LWT_ISO_EDGE* upd_edge, int upd_fields, - const LWT_ISO_EDGE* exc_edge, int exc_fields ) + const LWT_ISO_EDGE* sel_edge, int sel_fields, + const LWT_ISO_EDGE* upd_edge, int upd_fields, + const LWT_ISO_EDGE* exc_edge, int exc_fields ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; @@ -1592,11 +1767,13 @@ cb_updateEdges( const LWT_BE_TOPOLOGY* topo, appendStringInfo(sql, "UPDATE \"%s\".edge_data SET ", topo->name); addEdgeUpdate( sql, upd_edge, upd_fields, 1, updSet ); if ( exc_edge || sel_edge ) appendStringInfoString(sql, " WHERE "); - if ( sel_edge ) { + if ( sel_edge ) + { addEdgeUpdate( sql, sel_edge, sel_fields, 1, updSel ); if ( exc_edge ) appendStringInfoString(sql, " AND "); } - if ( exc_edge ) { + if ( exc_edge ) + { addEdgeUpdate( sql, exc_edge, exc_fields, 1, updNot ); } @@ -1606,10 +1783,10 @@ cb_updateEdges( const LWT_BE_TOPOLOGY* topo, MemoryContextSwitchTo( oldcontext ); /* switch back */ if ( spi_result != SPI_OK_UPDATE ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return -1; + return -1; } pfree(sqldata.data); @@ -1622,12 +1799,12 @@ cb_updateEdges( const LWT_BE_TOPOLOGY* topo, static int cb_updateNodes( const LWT_BE_TOPOLOGY* topo, - const LWT_ISO_NODE* sel_node, int sel_fields, - const LWT_ISO_NODE* upd_node, int upd_fields, - const LWT_ISO_NODE* exc_node, int exc_fields ) + const LWT_ISO_NODE* sel_node, int sel_fields, + const LWT_ISO_NODE* upd_node, int upd_fields, + const LWT_ISO_NODE* exc_node, int exc_fields ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; @@ -1635,11 +1812,13 @@ cb_updateNodes( const LWT_BE_TOPOLOGY* topo, appendStringInfo(sql, "UPDATE \"%s\".node SET ", topo->name); addNodeUpdate( sql, upd_node, upd_fields, 1, updSet ); if ( exc_node || sel_node ) appendStringInfoString(sql, " WHERE "); - if ( sel_node ) { + if ( sel_node ) + { addNodeUpdate( sql, sel_node, sel_fields, 1, updSel ); if ( exc_node ) appendStringInfoString(sql, " AND "); } - if ( exc_node ) { + if ( exc_node ) + { addNodeUpdate( sql, exc_node, exc_fields, 1, updNot ); } @@ -1649,10 +1828,10 @@ cb_updateNodes( const LWT_BE_TOPOLOGY* topo, MemoryContextSwitchTo( oldcontext ); /* switch back */ if ( spi_result != SPI_OK_UPDATE ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return -1; + return -1; } pfree(sqldata.data); @@ -1665,31 +1844,33 @@ cb_updateNodes( const LWT_BE_TOPOLOGY* topo, static int cb_updateNodesById( const LWT_BE_TOPOLOGY* topo, - const LWT_ISO_NODE* nodes, int numnodes, int fields ) + const LWT_ISO_NODE* nodes, int numnodes, int fields ) { MemoryContext oldcontext = CurrentMemoryContext; int i; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; const char *sep = ""; const char *sep1 = ","; - if ( ! fields ) { - cberror(topo->be_data, + if ( ! fields ) + { + cberror(topo->be_data, "updateNodesById callback called with no update fields!"); - return -1; + return -1; } POSTGIS_DEBUGF(1, "cb_updateNodesById got %d nodes to update" - " (fields:%d)", - numnodes, fields); + " (fields:%d)", + numnodes, fields); initStringInfo(sql); appendStringInfoString(sql, "WITH newnodes(node_id,"); addNodeFields(sql, fields); appendStringInfoString(sql, ") AS ( VALUES "); - for (i=0; iname); /* TODO: turn the following into a function */ - if ( fields & LWT_COL_NODE_NODE_ID ) { + if ( fields & LWT_COL_NODE_NODE_ID ) + { appendStringInfo(sql, "%snode_id = o.node_id", sep); sep = sep1; } - if ( fields & LWT_COL_NODE_CONTAINING_FACE ) { + if ( fields & LWT_COL_NODE_CONTAINING_FACE ) + { appendStringInfo(sql, "%scontaining_face = o.containing_face", sep); sep = sep1; } - if ( fields & LWT_COL_NODE_GEOM ) { + if ( fields & LWT_COL_NODE_GEOM ) + { appendStringInfo(sql, "%sgeom = o.geom", sep); } @@ -1717,10 +1901,10 @@ cb_updateNodesById( const LWT_BE_TOPOLOGY* topo, MemoryContextSwitchTo( oldcontext ); /* switch back */ if ( spi_result != SPI_OK_UPDATE ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return -1; + return -1; } pfree(sqldata.data); @@ -1733,30 +1917,31 @@ cb_updateNodesById( const LWT_BE_TOPOLOGY* topo, static int cb_updateFacesById( const LWT_BE_TOPOLOGY* topo, - const LWT_ISO_FACE* faces, int numfaces ) + const LWT_ISO_FACE* faces, int numfaces ) { MemoryContext oldcontext = CurrentMemoryContext; int i; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; initStringInfo(sql); appendStringInfoString(sql, "WITH newfaces(id,mbr) AS ( VALUES "); - for (i=0; imbr, topo->srid); if ( i ) appendStringInfoChar(sql, ','); appendStringInfo(sql, "(%" LWTFMT_ELEMID - ", ST_Envelope('%s'::geometry))", - face->face_id, hexbox); + ", ST_Envelope('%s'::geometry))", + face->face_id, hexbox); lwfree(hexbox); } appendStringInfo(sql, ") UPDATE \"%s\".face o SET mbr = i.mbr " - "FROM newfaces i WHERE o.face_id = i.id", - topo->name); + "FROM newfaces i WHERE o.face_id = i.id", + topo->name); POSTGIS_DEBUGF(1, "cb_updateFacesById query: %s", sql->data); @@ -1764,10 +1949,10 @@ cb_updateFacesById( const LWT_BE_TOPOLOGY* topo, MemoryContextSwitchTo( oldcontext ); /* switch back */ if ( spi_result != SPI_OK_UPDATE ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return -1; + return -1; } pfree(sqldata.data); @@ -1780,27 +1965,29 @@ cb_updateFacesById( const LWT_BE_TOPOLOGY* topo, static int cb_updateEdgesById( const LWT_BE_TOPOLOGY* topo, - const LWT_ISO_EDGE* edges, int numedges, int fields ) + const LWT_ISO_EDGE* edges, int numedges, int fields ) { MemoryContext oldcontext = CurrentMemoryContext; int i; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; const char *sep = ""; const char *sep1 = ","; - if ( ! fields ) { - cberror(topo->be_data, + if ( ! fields ) + { + cberror(topo->be_data, "updateEdgesById callback called with no update fields!"); - return -1; + return -1; } initStringInfo(sql); appendStringInfoString(sql, "WITH newedges(edge_id,"); addEdgeFields(sql, fields, 0); appendStringInfoString(sql, ") AS ( VALUES "); - for (i=0; iname); /* TODO: turn the following into a function */ - if ( fields & LWT_COL_EDGE_START_NODE ) { + if ( fields & LWT_COL_EDGE_START_NODE ) + { appendStringInfo(sql, "%sstart_node = o.start_node", sep); sep = sep1; } - if ( fields & LWT_COL_EDGE_END_NODE ) { + if ( fields & LWT_COL_EDGE_END_NODE ) + { appendStringInfo(sql, "%send_node = o.end_node", sep); sep = sep1; } - if ( fields & LWT_COL_EDGE_FACE_LEFT ) { + if ( fields & LWT_COL_EDGE_FACE_LEFT ) + { appendStringInfo(sql, "%sleft_face = o.left_face", sep); sep = sep1; } - if ( fields & LWT_COL_EDGE_FACE_RIGHT ) { + if ( fields & LWT_COL_EDGE_FACE_RIGHT ) + { appendStringInfo(sql, "%sright_face = o.right_face", sep); sep = sep1; } - if ( fields & LWT_COL_EDGE_NEXT_LEFT ) { + if ( fields & LWT_COL_EDGE_NEXT_LEFT ) + { appendStringInfo(sql, - "%snext_left_edge = o.next_left_edge, " - "abs_next_left_edge = abs(o.next_left_edge)", sep); + "%snext_left_edge = o.next_left_edge, " + "abs_next_left_edge = abs(o.next_left_edge)", sep); sep = sep1; } - if ( fields & LWT_COL_EDGE_NEXT_RIGHT ) { + if ( fields & LWT_COL_EDGE_NEXT_RIGHT ) + { appendStringInfo(sql, - "%snext_right_edge = o.next_right_edge, " - "abs_next_right_edge = abs(o.next_right_edge)", sep); + "%snext_right_edge = o.next_right_edge, " + "abs_next_right_edge = abs(o.next_right_edge)", sep); sep = sep1; } - if ( fields & LWT_COL_EDGE_GEOM ) { + if ( fields & LWT_COL_EDGE_GEOM ) + { appendStringInfo(sql, "%sgeom = o.geom", sep); } @@ -1848,10 +2042,10 @@ cb_updateEdgesById( const LWT_BE_TOPOLOGY* topo, MemoryContextSwitchTo( oldcontext ); /* switch back */ if ( spi_result != SPI_OK_UPDATE ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return -1; + return -1; } pfree(sqldata.data); @@ -1864,10 +2058,10 @@ cb_updateEdgesById( const LWT_BE_TOPOLOGY* topo, static int cb_deleteEdges( const LWT_BE_TOPOLOGY* topo, - const LWT_ISO_EDGE* sel_edge, int sel_fields ) + const LWT_ISO_EDGE* sel_edge, int sel_fields ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; @@ -1881,10 +2075,10 @@ cb_deleteEdges( const LWT_BE_TOPOLOGY* topo, MemoryContextSwitchTo( oldcontext ); /* switch back */ if ( spi_result != SPI_OK_DELETE ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return -1; + return -1; } pfree(sqldata.data); @@ -1899,7 +2093,7 @@ static LWT_ELEMID cb_getNextEdgeId( const LWT_BE_TOPOLOGY* topo ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; bool isnull; @@ -1908,20 +2102,22 @@ cb_getNextEdgeId( const LWT_BE_TOPOLOGY* topo ) initStringInfo(sql); appendStringInfo(sql, "SELECT nextval('\"%s\".edge_data_edge_id_seq')", - topo->name); + topo->name); spi_result = SPI_execute(sql->data, false, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", + if ( spi_result != SPI_OK_SELECT ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return -1; + return -1; } pfree(sqldata.data); if ( SPI_processed ) topo->be_data->data_changed = true; - if ( SPI_processed != 1 ) { + if ( SPI_processed != 1 ) + { cberror(topo->be_data, "processed " UINT64_FORMAT " rows, expected 1", (uint64)SPI_processed); return -1; @@ -1929,9 +2125,10 @@ cb_getNextEdgeId( const LWT_BE_TOPOLOGY* topo ) dat = SPI_getbinval( SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull ); - if ( isnull ) { - cberror(topo->be_data, "nextval for edge_id returned null"); - return -1; + if ( isnull ) + { + cberror(topo->be_data, "nextval for edge_id returned null"); + return -1; } edge_id = DatumGetInt64(dat); /* sequences return 64bit integers */ @@ -1942,26 +2139,30 @@ cb_getNextEdgeId( const LWT_BE_TOPOLOGY* topo ) static int cb_updateTopoGeomEdgeSplit ( const LWT_BE_TOPOLOGY* topo, - LWT_ELEMID split_edge, LWT_ELEMID new_edge1, LWT_ELEMID new_edge2 ) + LWT_ELEMID split_edge, LWT_ELEMID new_edge1, LWT_ELEMID new_edge2 ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; int i, ntopogeoms; const char *proj = "r.element_id, r.topogeo_id, r.layer_id, r.element_type"; initStringInfo(sql); - if ( new_edge2 == -1 ) { + if ( new_edge2 == -1 ) + { appendStringInfo(sql, "SELECT %s", proj); - } else { + } + else + { appendStringInfoString(sql, "DELETE"); } appendStringInfo( sql, " FROM \"%s\".relation r %s topology.layer l WHERE " - "l.topology_id = %d AND l.level = 0 AND l.layer_id = r.layer_id " - "AND abs(r.element_id) = %" LWTFMT_ELEMID " AND r.element_type = 2", - topo->name, (new_edge2 == -1 ? "," : "USING" ), topo->id, split_edge ); - if ( new_edge2 != -1 ) { + "l.topology_id = %d AND l.level = 0 AND l.layer_id = r.layer_id " + "AND abs(r.element_id) = %" LWTFMT_ELEMID " AND r.element_type = 2", + topo->name, (new_edge2 == -1 ? "," : "USING" ), topo->id, split_edge ); + if ( new_edge2 != -1 ) + { appendStringInfo(sql, " RETURNING %s", proj); } @@ -1969,11 +2170,12 @@ cb_updateTopoGeomEdgeSplit ( const LWT_BE_TOPOLOGY* topo, spi_result = SPI_execute(sql->data, new_edge2 == -1 ? !topo->be_data->data_changed : false, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != ( new_edge2 == -1 ? SPI_OK_SELECT : SPI_OK_DELETE_RETURNING ) ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", + if ( spi_result != ( new_edge2 == -1 ? SPI_OK_SELECT : SPI_OK_DELETE_RETURNING ) ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return 0; + return 0; } if ( spi_result == SPI_OK_DELETE_RETURNING && SPI_processed ) @@ -1997,43 +2199,48 @@ cb_updateTopoGeomEdgeSplit ( const LWT_BE_TOPOLOGY* topo, int layer_id; int element_type; - if ( ! getNotNullInt32( row, tdesc, 1, &element_id ) ) { + if ( ! getNotNullInt32( row, tdesc, 1, &element_id ) ) + { cberror(topo->be_data, - "unexpected null element_id in \"%s\".relation", - topo->name); + "unexpected null element_id in \"%s\".relation", + topo->name); return 0; } negate = ( element_id < 0 ); - if ( ! getNotNullInt32( row, tdesc, 2, &topogeo_id ) ) { + if ( ! getNotNullInt32( row, tdesc, 2, &topogeo_id ) ) + { cberror(topo->be_data, - "unexpected null topogeo_id in \"%s\".relation", - topo->name); + "unexpected null topogeo_id in \"%s\".relation", + topo->name); return 0; } - if ( ! getNotNullInt32( row, tdesc, 3, &layer_id ) ) { + if ( ! getNotNullInt32( row, tdesc, 3, &layer_id ) ) + { cberror(topo->be_data, - "unexpected null layer_id in \"%s\".relation", - topo->name); + "unexpected null layer_id in \"%s\".relation", + topo->name); return 0; } - if ( ! getNotNullInt32( row, tdesc, 4, &element_type ) ) { + if ( ! getNotNullInt32( row, tdesc, 4, &element_type ) ) + { cberror(topo->be_data, - "unexpected null element_type in \"%s\".relation", - topo->name); + "unexpected null element_type in \"%s\".relation", + topo->name); return 0; } if ( i ) appendStringInfoChar(sql, ','); appendStringInfo(sql, "(%d,%d,%" LWTFMT_ELEMID ",%d)", - topogeo_id, layer_id, negate ? -new_edge1 : new_edge1, element_type); - if ( new_edge2 != -1 ) { + topogeo_id, layer_id, negate ? -new_edge1 : new_edge1, element_type); + if ( new_edge2 != -1 ) + { resetStringInfo(sql); appendStringInfo(sql, - ",VALUES (%d,%d,%" LWTFMT_ELEMID ",%d", - topogeo_id, layer_id, negate ? -new_edge2 : new_edge2, element_type); + ",VALUES (%d,%d,%" LWTFMT_ELEMID ",%d", + topogeo_id, layer_id, negate ? -new_edge2 : new_edge2, element_type); } } @@ -2042,7 +2249,8 @@ cb_updateTopoGeomEdgeSplit ( const LWT_BE_TOPOLOGY* topo, POSTGIS_DEBUGF(1, "cb_updateTopoGeomEdgeSplit query: %s", sql->data); spi_result = SPI_execute(sql->data, false, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_INSERT ) { + if ( spi_result != SPI_OK_INSERT ) + { cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); @@ -2059,31 +2267,35 @@ cb_updateTopoGeomEdgeSplit ( const LWT_BE_TOPOLOGY* topo, static int cb_updateTopoGeomFaceSplit ( const LWT_BE_TOPOLOGY* topo, - LWT_ELEMID split_face, LWT_ELEMID new_face1, LWT_ELEMID new_face2 ) + LWT_ELEMID split_face, LWT_ELEMID new_face1, LWT_ELEMID new_face2 ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; int i, ntopogeoms; const char *proj = "r.element_id, r.topogeo_id, r.layer_id, r.element_type"; POSTGIS_DEBUGF(1, "cb_updateTopoGeomFaceSplit signalled " - "split of face %" LWTFMT_ELEMID " into %" - LWTFMT_ELEMID " and %" LWTFMT_ELEMID, - split_face, new_face1, new_face2); + "split of face %" LWTFMT_ELEMID " into %" + LWTFMT_ELEMID " and %" LWTFMT_ELEMID, + split_face, new_face1, new_face2); initStringInfo(sql); - if ( new_face2 == -1 ) { + if ( new_face2 == -1 ) + { appendStringInfo(sql, "SELECT %s", proj); - } else { + } + else + { appendStringInfoString(sql, "DELETE"); } appendStringInfo( sql, " FROM \"%s\".relation r %s topology.layer l WHERE " - "l.topology_id = %d AND l.level = 0 AND l.layer_id = r.layer_id " - "AND abs(r.element_id) = %" LWTFMT_ELEMID " AND r.element_type = 3", - topo->name, (new_face2 == -1 ? "," : "USING" ), topo->id, split_face ); - if ( new_face2 != -1 ) { + "l.topology_id = %d AND l.level = 0 AND l.layer_id = r.layer_id " + "AND abs(r.element_id) = %" LWTFMT_ELEMID " AND r.element_type = 3", + topo->name, (new_face2 == -1 ? "," : "USING" ), topo->id, split_face ); + if ( new_face2 != -1 ) + { appendStringInfo(sql, " RETURNING %s", proj); } @@ -2091,11 +2303,12 @@ cb_updateTopoGeomFaceSplit ( const LWT_BE_TOPOLOGY* topo, spi_result = SPI_execute(sql->data, new_face2 == -1 ? !topo->be_data->data_changed : false, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != ( new_face2 == -1 ? SPI_OK_SELECT : SPI_OK_DELETE_RETURNING ) ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", + if ( spi_result != ( new_face2 == -1 ? SPI_OK_SELECT : SPI_OK_DELETE_RETURNING ) ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return 0; + return 0; } if ( spi_result == SPI_OK_DELETE_RETURNING && SPI_processed ) @@ -2118,44 +2331,49 @@ cb_updateTopoGeomFaceSplit ( const LWT_BE_TOPOLOGY* topo, int layer_id; int element_type; - if ( ! getNotNullInt32( row, tdesc, 1, &element_id ) ) { + if ( ! getNotNullInt32( row, tdesc, 1, &element_id ) ) + { cberror(topo->be_data, - "unexpected null element_id in \"%s\".relation", - topo->name); + "unexpected null element_id in \"%s\".relation", + topo->name); return 0; } negate = ( element_id < 0 ); - if ( ! getNotNullInt32( row, tdesc, 2, &topogeo_id ) ) { + if ( ! getNotNullInt32( row, tdesc, 2, &topogeo_id ) ) + { cberror(topo->be_data, - "unexpected null topogeo_id in \"%s\".relation", - topo->name); + "unexpected null topogeo_id in \"%s\".relation", + topo->name); return 0; } - if ( ! getNotNullInt32( row, tdesc, 3, &layer_id ) ) { + if ( ! getNotNullInt32( row, tdesc, 3, &layer_id ) ) + { cberror(topo->be_data, - "unexpected null layer_id in \"%s\".relation", - topo->name); + "unexpected null layer_id in \"%s\".relation", + topo->name); return 0; } - if ( ! getNotNullInt32( row, tdesc, 4, &element_type ) ) { + if ( ! getNotNullInt32( row, tdesc, 4, &element_type ) ) + { cberror(topo->be_data, - "unexpected null element_type in \"%s\".relation", - topo->name); + "unexpected null element_type in \"%s\".relation", + topo->name); return 0; } if ( i ) appendStringInfoChar(sql, ','); appendStringInfo(sql, - "(%d,%d,%" LWTFMT_ELEMID ",%d)", - topogeo_id, layer_id, negate ? -new_face1 : new_face1, element_type); + "(%d,%d,%" LWTFMT_ELEMID ",%d)", + topogeo_id, layer_id, negate ? -new_face1 : new_face1, element_type); - if ( new_face2 != -1 ) { + if ( new_face2 != -1 ) + { appendStringInfo(sql, - ",(%d,%d,%" LWTFMT_ELEMID ",%d)", - topogeo_id, layer_id, negate ? -new_face2 : new_face2, element_type); + ",(%d,%d,%" LWTFMT_ELEMID ",%d)", + topogeo_id, layer_id, negate ? -new_face2 : new_face2, element_type); } } @@ -2164,7 +2382,8 @@ cb_updateTopoGeomFaceSplit ( const LWT_BE_TOPOLOGY* topo, POSTGIS_DEBUGF(1, "cb_updateTopoGeomFaceSplit query: %s", sql->data); spi_result = SPI_execute(sql->data, false, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_INSERT ) { + if ( spi_result != SPI_OK_INSERT ) + { cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); @@ -2182,10 +2401,10 @@ cb_updateTopoGeomFaceSplit ( const LWT_BE_TOPOLOGY* topo, static int cb_checkTopoGeomRemEdge ( const LWT_BE_TOPOLOGY* topo, - LWT_ELEMID rem_edge, LWT_ELEMID face_left, LWT_ELEMID face_right ) + LWT_ELEMID rem_edge, LWT_ELEMID face_left, LWT_ELEMID face_right ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; const char *tg_id, *layer_id; @@ -2197,18 +2416,19 @@ cb_checkTopoGeomRemEdge ( const LWT_BE_TOPOLOGY* topo, initStringInfo(sql); appendStringInfo( sql, "SELECT r.topogeo_id, r.layer_id, " - "l.schema_name, l.table_name, l.feature_column FROM " - "topology.layer l INNER JOIN \"%s\".relation r " - "ON (l.layer_id = r.layer_id) WHERE l.level = 0 AND " - "l.feature_type = 2 AND l.topology_id = %d" - " AND abs(r.element_id) = %" LWTFMT_ELEMID, - topo->name, topo->id, rem_edge ); + "l.schema_name, l.table_name, l.feature_column FROM " + "topology.layer l INNER JOIN \"%s\".relation r " + "ON (l.layer_id = r.layer_id) WHERE l.level = 0 AND " + "l.feature_type = 2 AND l.topology_id = %d" + " AND abs(r.element_id) = %" LWTFMT_ELEMID, + topo->name, topo->id, rem_edge ); POSTGIS_DEBUGF(1, "cb_checkTopoGeomRemEdge query 1: %s", sql->data); spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { + if ( spi_result != SPI_OK_SELECT ) + { cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); @@ -2229,8 +2449,8 @@ cb_checkTopoGeomRemEdge ( const LWT_BE_TOPOLOGY* topo, SPI_freetuptable(SPI_tuptable); cberror(topo->be_data, "TopoGeom %s in layer %s " - "(%s.%s.%s) cannot be represented " - "dropping edge %" LWTFMT_ELEMID, + "(%s.%s.%s) cannot be represented " + "dropping edge %" LWTFMT_ELEMID, tg_id, layer_id, schema_name, table_name, col_name, rem_edge); return 0; @@ -2240,8 +2460,8 @@ cb_checkTopoGeomRemEdge ( const LWT_BE_TOPOLOGY* topo, if ( face_left != face_right ) { POSTGIS_DEBUGF(1, "Deletion of edge %" LWTFMT_ELEMID " joins faces %" - LWTFMT_ELEMID " and %" LWTFMT_ELEMID, - rem_edge, face_left, face_right); + LWTFMT_ELEMID " and %" LWTFMT_ELEMID, + rem_edge, face_left, face_right); /* check if any topo_geom is defined only by one of the joined faces. In such case there would be no way to adapt @@ -2249,24 +2469,25 @@ cb_checkTopoGeomRemEdge ( const LWT_BE_TOPOLOGY* topo, */ initStringInfo(sql); appendStringInfo( sql, "SELECT t.* FROM ( SELECT r.topogeo_id, " - "r.layer_id, l.schema_name, l.table_name, l.feature_column, " - "array_agg(r.element_id) as elems FROM topology.layer l " - " INNER JOIN \"%s\".relation r ON (l.layer_id = r.layer_id) " - "WHERE l.level = 0 and l.feature_type = 3 " - "AND l.topology_id = %d" - " AND r.element_id = ANY (ARRAY[%" LWTFMT_ELEMID ",%" LWTFMT_ELEMID - "]::int4[]) group by r.topogeo_id, r.layer_id, l.schema_name, " - "l.table_name, l.feature_column ) t WHERE NOT t.elems @> ARRAY[%" - LWTFMT_ELEMID ",%" LWTFMT_ELEMID "]::int4[]", - - topo->name, topo->id, - face_left, face_right, face_left, face_right ); + "r.layer_id, l.schema_name, l.table_name, l.feature_column, " + "array_agg(r.element_id) as elems FROM topology.layer l " + " INNER JOIN \"%s\".relation r ON (l.layer_id = r.layer_id) " + "WHERE l.level = 0 and l.feature_type = 3 " + "AND l.topology_id = %d" + " AND r.element_id = ANY (ARRAY[%" LWTFMT_ELEMID ",%" LWTFMT_ELEMID + "]::int4[]) group by r.topogeo_id, r.layer_id, l.schema_name, " + "l.table_name, l.feature_column ) t WHERE NOT t.elems @> ARRAY[%" + LWTFMT_ELEMID ",%" LWTFMT_ELEMID "]::int4[]", + + topo->name, topo->id, + face_left, face_right, face_left, face_right ); POSTGIS_DEBUGF(1, "cb_checkTopoGeomRemEdge query 2: %s", sql->data); spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { + if ( spi_result != SPI_OK_SELECT ) + { cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); @@ -2287,9 +2508,9 @@ cb_checkTopoGeomRemEdge ( const LWT_BE_TOPOLOGY* topo, SPI_freetuptable(SPI_tuptable); cberror(topo->be_data, "TopoGeom %s in layer %s " - "(%s.%s.%s) cannot be represented " - "healing faces %" LWTFMT_ELEMID - " and %" LWTFMT_ELEMID, + "(%s.%s.%s) cannot be represented " + "healing faces %" LWTFMT_ELEMID + " and %" LWTFMT_ELEMID, tg_id, layer_id, schema_name, table_name, col_name, face_right, face_left); return 0; @@ -2301,10 +2522,10 @@ cb_checkTopoGeomRemEdge ( const LWT_BE_TOPOLOGY* topo, static int cb_checkTopoGeomRemNode ( const LWT_BE_TOPOLOGY* topo, - LWT_ELEMID rem_node, LWT_ELEMID edge1, LWT_ELEMID edge2 ) + LWT_ELEMID rem_node, LWT_ELEMID edge1, LWT_ELEMID edge2 ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; const char *tg_id, *layer_id; @@ -2314,23 +2535,24 @@ cb_checkTopoGeomRemNode ( const LWT_BE_TOPOLOGY* topo, initStringInfo(sql); appendStringInfo( sql, "SELECT t.* FROM ( SELECT r.topogeo_id, " - "r.layer_id, l.schema_name, l.table_name, l.feature_column, " - "array_agg(abs(r.element_id)) as elems FROM topology.layer l " - " INNER JOIN \"%s\".relation r ON (l.layer_id = r.layer_id) " - "WHERE l.level = 0 and l.feature_type = 2 " - "AND l.topology_id = %d" - " AND abs(r.element_id) = ANY (ARRAY[%" LWTFMT_ELEMID ",%" LWTFMT_ELEMID - "]::int4[]) group by r.topogeo_id, r.layer_id, l.schema_name, " - "l.table_name, l.feature_column ) t WHERE NOT t.elems @> ARRAY[%" - LWTFMT_ELEMID ",%" LWTFMT_ELEMID "]::int4[]", - topo->name, topo->id, - edge1, edge2, edge1, edge2 ); + "r.layer_id, l.schema_name, l.table_name, l.feature_column, " + "array_agg(abs(r.element_id)) as elems FROM topology.layer l " + " INNER JOIN \"%s\".relation r ON (l.layer_id = r.layer_id) " + "WHERE l.level = 0 and l.feature_type = 2 " + "AND l.topology_id = %d" + " AND abs(r.element_id) = ANY (ARRAY[%" LWTFMT_ELEMID ",%" LWTFMT_ELEMID + "]::int4[]) group by r.topogeo_id, r.layer_id, l.schema_name, " + "l.table_name, l.feature_column ) t WHERE NOT t.elems @> ARRAY[%" + LWTFMT_ELEMID ",%" LWTFMT_ELEMID "]::int4[]", + topo->name, topo->id, + edge1, edge2, edge1, edge2 ); POSTGIS_DEBUGF(1, "cb_checkTopoGeomRemNode query 1: %s", sql->data); spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { + if ( spi_result != SPI_OK_SELECT ) + { cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); @@ -2351,9 +2573,9 @@ cb_checkTopoGeomRemNode ( const LWT_BE_TOPOLOGY* topo, SPI_freetuptable(SPI_tuptable); cberror(topo->be_data, "TopoGeom %s in layer %s " - "(%s.%s.%s) cannot be represented " - "healing edges %" LWTFMT_ELEMID - " and %" LWTFMT_ELEMID, + "(%s.%s.%s) cannot be represented " + "healing edges %" LWTFMT_ELEMID + " and %" LWTFMT_ELEMID, tg_id, layer_id, schema_name, table_name, col_name, edge1, edge2); return 0; @@ -2367,10 +2589,10 @@ cb_checkTopoGeomRemNode ( const LWT_BE_TOPOLOGY* topo, static int cb_updateTopoGeomFaceHeal ( const LWT_BE_TOPOLOGY* topo, - LWT_ELEMID face1, LWT_ELEMID face2, LWT_ELEMID newface ) + LWT_ELEMID face1, LWT_ELEMID face2, LWT_ELEMID newface ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; @@ -2384,16 +2606,17 @@ cb_updateTopoGeomFaceHeal ( const LWT_BE_TOPOLOGY* topo, initStringInfo(sql); /* this query can be optimized */ appendStringInfo( sql, "DELETE FROM \"%s\".relation r " - "USING topology.layer l WHERE l.level = 0 AND l.feature_type = 3" - " AND l.topology_id = %d AND l.layer_id = r.layer_id " - " AND abs(r.element_id) IN ( %" LWTFMT_ELEMID ",%" LWTFMT_ELEMID ")" - " AND abs(r.element_id) != %" LWTFMT_ELEMID, - topo->name, topo->id, face1, face2, newface ); + "USING topology.layer l WHERE l.level = 0 AND l.feature_type = 3" + " AND l.topology_id = %d AND l.layer_id = r.layer_id " + " AND abs(r.element_id) IN ( %" LWTFMT_ELEMID ",%" LWTFMT_ELEMID ")" + " AND abs(r.element_id) != %" LWTFMT_ELEMID, + topo->name, topo->id, face1, face2, newface ); POSTGIS_DEBUGF(1, "cb_updateTopoGeomFaceHeal query: %s", sql->data); spi_result = SPI_execute(sql->data, false, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_DELETE ) { + if ( spi_result != SPI_OK_DELETE ) + { cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); @@ -2406,15 +2629,16 @@ cb_updateTopoGeomFaceHeal ( const LWT_BE_TOPOLOGY* topo, initStringInfo(sql); /* delete face1 */ appendStringInfo( sql, "DELETE FROM \"%s\".relation r " - "USING topology.layer l WHERE l.level = 0 AND l.feature_type = 3" - " AND l.topology_id = %d AND l.layer_id = r.layer_id " - " AND abs(r.element_id) = %" LWTFMT_ELEMID, - topo->name, topo->id, face1 ); + "USING topology.layer l WHERE l.level = 0 AND l.feature_type = 3" + " AND l.topology_id = %d AND l.layer_id = r.layer_id " + " AND abs(r.element_id) = %" LWTFMT_ELEMID, + topo->name, topo->id, face1 ); POSTGIS_DEBUGF(1, "cb_updateTopoGeomFaceHeal query 1: %s", sql->data); spi_result = SPI_execute(sql->data, false, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_DELETE ) { + if ( spi_result != SPI_OK_DELETE ) + { cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); @@ -2425,15 +2649,16 @@ cb_updateTopoGeomFaceHeal ( const LWT_BE_TOPOLOGY* topo, initStringInfo(sql); /* update face2 to newface */ appendStringInfo( sql, "UPDATE \"%s\".relation r " - "SET element_id = %" LWTFMT_ELEMID " FROM topology.layer l " - "WHERE l.level = 0 AND l.feature_type = 3 AND l.topology_id = %d" - " AND l.layer_id = r.layer_id AND r.element_id = %" LWTFMT_ELEMID, - topo->name, newface, topo->id, face2 ); + "SET element_id = %" LWTFMT_ELEMID " FROM topology.layer l " + "WHERE l.level = 0 AND l.feature_type = 3 AND l.topology_id = %d" + " AND l.layer_id = r.layer_id AND r.element_id = %" LWTFMT_ELEMID, + topo->name, newface, topo->id, face2 ); POSTGIS_DEBUGF(1, "cb_updateTopoGeomFaceHeal query 2: %s", sql->data); spi_result = SPI_execute(sql->data, false, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_UPDATE ) { + if ( spi_result != SPI_OK_UPDATE ) + { cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); @@ -2447,10 +2672,10 @@ cb_updateTopoGeomFaceHeal ( const LWT_BE_TOPOLOGY* topo, static int cb_updateTopoGeomEdgeHeal ( const LWT_BE_TOPOLOGY* topo, - LWT_ELEMID edge1, LWT_ELEMID edge2, LWT_ELEMID newedge ) + LWT_ELEMID edge1, LWT_ELEMID edge2, LWT_ELEMID newedge ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; @@ -2462,16 +2687,17 @@ cb_updateTopoGeomEdgeHeal ( const LWT_BE_TOPOLOGY* topo, initStringInfo(sql); /* this query can be optimized */ appendStringInfo( sql, "DELETE FROM \"%s\".relation r " - "USING topology.layer l WHERE l.level = 0 AND l.feature_type = 2" - " AND l.topology_id = %d AND l.layer_id = r.layer_id " - " AND abs(r.element_id) IN ( %" LWTFMT_ELEMID ",%" LWTFMT_ELEMID ")" - " AND abs(r.element_id) != %" LWTFMT_ELEMID, - topo->name, topo->id, edge1, edge2, newedge ); + "USING topology.layer l WHERE l.level = 0 AND l.feature_type = 2" + " AND l.topology_id = %d AND l.layer_id = r.layer_id " + " AND abs(r.element_id) IN ( %" LWTFMT_ELEMID ",%" LWTFMT_ELEMID ")" + " AND abs(r.element_id) != %" LWTFMT_ELEMID, + topo->name, topo->id, edge1, edge2, newedge ); POSTGIS_DEBUGF(1, "cb_updateTopoGeomEdgeHeal query: %s", sql->data); spi_result = SPI_execute(sql->data, false, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_DELETE ) { + if ( spi_result != SPI_OK_DELETE ) + { cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); @@ -2484,15 +2710,16 @@ cb_updateTopoGeomEdgeHeal ( const LWT_BE_TOPOLOGY* topo, initStringInfo(sql); /* delete edge1 */ appendStringInfo( sql, "DELETE FROM \"%s\".relation r " - "USING topology.layer l WHERE l.level = 0 AND l.feature_type = 2" - " AND l.topology_id = %d AND l.layer_id = r.layer_id " - " AND abs(r.element_id) = %" LWTFMT_ELEMID, - topo->name, topo->id, edge2 ); + "USING topology.layer l WHERE l.level = 0 AND l.feature_type = 2" + " AND l.topology_id = %d AND l.layer_id = r.layer_id " + " AND abs(r.element_id) = %" LWTFMT_ELEMID, + topo->name, topo->id, edge2 ); POSTGIS_DEBUGF(1, "cb_updateTopoGeomEdgeHeal query 1: %s", sql->data); spi_result = SPI_execute(sql->data, false, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_DELETE ) { + if ( spi_result != SPI_OK_DELETE ) + { cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); @@ -2503,16 +2730,17 @@ cb_updateTopoGeomEdgeHeal ( const LWT_BE_TOPOLOGY* topo, initStringInfo(sql); /* update edge2 to newedge */ appendStringInfo( sql, "UPDATE \"%s\".relation r " - "SET element_id = %" LWTFMT_ELEMID " *(element_id/%" LWTFMT_ELEMID - ") FROM topology.layer l " - "WHERE l.level = 0 AND l.feature_type = 2 AND l.topology_id = %d" - " AND l.layer_id = r.layer_id AND abs(r.element_id) = %" LWTFMT_ELEMID, - topo->name, newedge, edge1, topo->id, edge1 ); + "SET element_id = %" LWTFMT_ELEMID " *(element_id/%" LWTFMT_ELEMID + ") FROM topology.layer l " + "WHERE l.level = 0 AND l.feature_type = 2 AND l.topology_id = %d" + " AND l.layer_id = r.layer_id AND abs(r.element_id) = %" LWTFMT_ELEMID, + topo->name, newedge, edge1, topo->id, edge1 ); POSTGIS_DEBUGF(1, "cb_updateTopoGeomEdgeHeal query 2: %s", sql->data); spi_result = SPI_execute(sql->data, false, 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_UPDATE ) { + if ( spi_result != SPI_OK_UPDATE ) + { cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); @@ -2528,7 +2756,7 @@ static LWT_ELEMID cb_getFaceContainingPoint( const LWT_BE_TOPOLOGY* topo, const LWPOINT* pt ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; bool isnull; @@ -2541,7 +2769,8 @@ cb_getFaceContainingPoint( const LWT_BE_TOPOLOGY* topo, const LWPOINT* pt ) initStringInfo(sql); pts = geometry_serialize(lwpoint_as_lwgeom(pt)); - if ( ! pts ) { + if ( ! pts ) + { cberror(topo->be_data, "%s:%d: could not serialize query point", __FILE__, __LINE__); return -2; @@ -2561,24 +2790,27 @@ cb_getFaceContainingPoint( const LWT_BE_TOPOLOGY* topo, const LWPOINT* pt ) !topo->be_data->data_changed, 1); MemoryContextSwitchTo( oldcontext ); /* switch back */ pfree(pts); /* not needed anymore */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", + if ( spi_result != SPI_OK_SELECT ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return -2; + return -2; } pfree(sqldata.data); - if ( SPI_processed != 1 ) { - return -1; /* none found */ + if ( SPI_processed != 1 ) + { + return -1; /* none found */ } dat = SPI_getbinval( SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull ); - if ( isnull ) { + if ( isnull ) + { SPI_freetuptable(SPI_tuptable); - cberror(topo->be_data, "corrupted topology: face with NULL face_id"); - return -2; + cberror(topo->be_data, "corrupted topology: face with NULL face_id"); + return -2; } face_id = DatumGetInt32(dat); SPI_freetuptable(SPI_tuptable); @@ -2587,16 +2819,17 @@ cb_getFaceContainingPoint( const LWT_BE_TOPOLOGY* topo, const LWPOINT* pt ) static int cb_deleteFacesById( const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, int numelems ) + const LWT_ELEMID* ids, int numelems ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result, i; + int spi_result, i; StringInfoData sqldata; StringInfo sql = &sqldata; initStringInfo(sql); appendStringInfo(sql, "DELETE FROM \"%s\".face WHERE face_id IN (", topo->name); - for (i=0; ibe_data, "unexpected return (%d) from query execution: %s", + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return -1; + return -1; } pfree(sqldata.data); @@ -2624,17 +2857,18 @@ cb_deleteFacesById( const LWT_BE_TOPOLOGY* topo, static int cb_deleteNodesById( const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, int numelems ) + const LWT_ELEMID* ids, int numelems ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result, i; + int spi_result, i; StringInfoData sqldata; StringInfo sql = &sqldata; initStringInfo(sql); appendStringInfo(sql, "DELETE FROM \"%s\".node WHERE node_id IN (", - topo->name); - for (i=0; iname); + for (i=0; ibe_data, "unexpected return (%d) from query execution: %s", + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - return -1; + return -1; } pfree(sqldata.data); @@ -2662,10 +2896,10 @@ cb_deleteNodesById( const LWT_BE_TOPOLOGY* topo, static LWT_ISO_NODE* cb_getNodeWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, - int* numelems, int fields, int limit ) + int* numelems, int fields, int limit ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; int i; @@ -2675,36 +2909,45 @@ cb_getNodeWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, initStringInfo(sql); - if ( elems_requested == -1 ) { + if ( elems_requested == -1 ) + { appendStringInfoString(sql, "SELECT EXISTS ( SELECT 1"); - } else { + } + else + { appendStringInfoString(sql, "SELECT "); addNodeFields(sql, fields); } hexbox = _box2d_to_hexwkb(box, topo->srid); appendStringInfo(sql, " FROM \"%s\".node WHERE geom && '%s'::geometry", - topo->name, hexbox); + topo->name, hexbox); lwfree(hexbox); - if ( elems_requested == -1 ) { + if ( elems_requested == -1 ) + { appendStringInfoString(sql, ")"); - } else if ( elems_requested > 0 ) { + } + else if ( elems_requested > 0 ) + { appendStringInfo(sql, " LIMIT %d", elems_requested); } POSTGIS_DEBUGF(1,"cb_getNodeWithinBox2D: query is: %s", sql->data); spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, limit >= 0 ? limit : 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); + if ( spi_result != SPI_OK_SELECT ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - *numelems = -1; return NULL; + *numelems = -1; + return NULL; } pfree(sqldata.data); POSTGIS_DEBUGF(1, "cb_getNodeWithinBox2D: edge query " - "(limited by %d) returned %d rows", - elems_requested, SPI_processed); + "(limited by %d) returned %d rows", + elems_requested, SPI_processed); *numelems = SPI_processed; - if ( ! SPI_processed ) { + if ( ! SPI_processed ) + { return NULL; } @@ -2737,10 +2980,10 @@ cb_getNodeWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, static LWT_ISO_EDGE* cb_getEdgeWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, - int* numelems, int fields, int limit ) + int* numelems, int fields, int limit ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; int i; @@ -2750,40 +2993,50 @@ cb_getEdgeWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, initStringInfo(sql); - if ( elems_requested == -1 ) { + if ( elems_requested == -1 ) + { appendStringInfoString(sql, "SELECT EXISTS ( SELECT 1"); - } else { + } + else + { appendStringInfoString(sql, "SELECT "); addEdgeFields(sql, fields, 0); } appendStringInfo(sql, " FROM \"%s\".edge", topo->name); - if ( box ) { + if ( box ) + { hexbox = _box2d_to_hexwkb(box, topo->srid); appendStringInfo(sql, " WHERE geom && '%s'::geometry", hexbox); lwfree(hexbox); } - if ( elems_requested == -1 ) { + if ( elems_requested == -1 ) + { appendStringInfoString(sql, ")"); - } else if ( elems_requested > 0 ) { + } + else if ( elems_requested > 0 ) + { appendStringInfo(sql, " LIMIT %d", elems_requested); } POSTGIS_DEBUGF(1,"cb_getEdgeWithinBox2D: query is: %s", sql->data); spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, limit >= 0 ? limit : 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); + if ( spi_result != SPI_OK_SELECT ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - *numelems = -1; return NULL; + *numelems = -1; + return NULL; } pfree(sqldata.data); POSTGIS_DEBUGF(1, "cb_getEdgeWithinBox2D: edge query " - "(limited by %d) returned %d rows", - elems_requested, SPI_processed); + "(limited by %d) returned %d rows", + elems_requested, SPI_processed); *numelems = SPI_processed; - if ( ! SPI_processed ) { + if ( ! SPI_processed ) + { return NULL; } @@ -2816,10 +3069,10 @@ cb_getEdgeWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, static LWT_ISO_FACE* cb_getFaceWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, - int* numelems, int fields, int limit ) + int* numelems, int fields, int limit ) { MemoryContext oldcontext = CurrentMemoryContext; - int spi_result; + int spi_result; StringInfoData sqldata; StringInfo sql = &sqldata; int i; @@ -2829,36 +3082,45 @@ cb_getFaceWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, initStringInfo(sql); - if ( elems_requested == -1 ) { + if ( elems_requested == -1 ) + { appendStringInfoString(sql, "SELECT EXISTS ( SELECT 1"); - } else { + } + else + { appendStringInfoString(sql, "SELECT "); addFaceFields(sql, fields); } hexbox = _box2d_to_hexwkb(box, topo->srid); appendStringInfo(sql, " FROM \"%s\".face WHERE mbr && '%s'::geometry", - topo->name, hexbox); + topo->name, hexbox); lwfree(hexbox); - if ( elems_requested == -1 ) { + if ( elems_requested == -1 ) + { appendStringInfoString(sql, ")"); - } else if ( elems_requested > 0 ) { + } + else if ( elems_requested > 0 ) + { appendStringInfo(sql, " LIMIT %d", elems_requested); } POSTGIS_DEBUGF(1,"cb_getFaceWithinBox2D: query is: %s", sql->data); spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, limit >= 0 ? limit : 0); MemoryContextSwitchTo( oldcontext ); /* switch back */ - if ( spi_result != SPI_OK_SELECT ) { - cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); + if ( spi_result != SPI_OK_SELECT ) + { + cberror(topo->be_data, "unexpected return (%d) from query execution: %s", spi_result, sql->data); pfree(sqldata.data); - *numelems = -1; return NULL; + *numelems = -1; + return NULL; } pfree(sqldata.data); POSTGIS_DEBUGF(1, "cb_getFaceWithinBox2D: face query " - "(limited by %d) returned %d rows", - elems_requested, SPI_processed); + "(limited by %d) returned %d rows", + elems_requested, SPI_processed); *numelems = SPI_processed; - if ( ! SPI_processed ) { + if ( ! SPI_processed ) + { return NULL; } @@ -2892,45 +3154,46 @@ cb_getFaceWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, } -static LWT_BE_CALLBACKS be_callbacks = { - cb_lastErrorMessage, - NULL, /* createTopology */ - cb_loadTopologyByName, - cb_freeTopology, - cb_getNodeById, - cb_getNodeWithinDistance2D, - cb_insertNodes, - cb_getEdgeById, - cb_getEdgeWithinDistance2D, - cb_getNextEdgeId, - cb_insertEdges, - cb_updateEdges, - cb_getFacesById, - cb_getFaceContainingPoint, - cb_updateTopoGeomEdgeSplit, - cb_deleteEdges, - cb_getNodeWithinBox2D, - cb_getEdgeWithinBox2D, - cb_getEdgeByNode, - cb_updateNodes, - cb_updateTopoGeomFaceSplit, - cb_insertFaces, - cb_updateFacesById, - cb_getRingEdges, - cb_updateEdgesById, - cb_getEdgeByFace, - cb_getNodeByFace, - cb_updateNodesById, - cb_deleteFacesById, - cb_topoGetSRID, - cb_topoGetPrecision, - cb_topoHasZ, - cb_deleteNodesById, - cb_checkTopoGeomRemEdge, - cb_updateTopoGeomFaceHeal, - cb_checkTopoGeomRemNode, - cb_updateTopoGeomEdgeHeal, - cb_getFaceWithinBox2D +static LWT_BE_CALLBACKS be_callbacks = +{ + cb_lastErrorMessage, + NULL, /* createTopology */ + cb_loadTopologyByName, + cb_freeTopology, + cb_getNodeById, + cb_getNodeWithinDistance2D, + cb_insertNodes, + cb_getEdgeById, + cb_getEdgeWithinDistance2D, + cb_getNextEdgeId, + cb_insertEdges, + cb_updateEdges, + cb_getFacesById, + cb_getFaceContainingPoint, + cb_updateTopoGeomEdgeSplit, + cb_deleteEdges, + cb_getNodeWithinBox2D, + cb_getEdgeWithinBox2D, + cb_getEdgeByNode, + cb_updateNodes, + cb_updateTopoGeomFaceSplit, + cb_insertFaces, + cb_updateFacesById, + cb_getRingEdges, + cb_updateEdgesById, + cb_getEdgeByFace, + cb_getNodeByFace, + cb_updateNodesById, + cb_deleteFacesById, + cb_topoGetSRID, + cb_topoGetPrecision, + cb_topoHasZ, + cb_deleteNodesById, + cb_checkTopoGeomRemEdge, + cb_updateTopoGeomFaceHeal, + cb_checkTopoGeomRemNode, + cb_updateTopoGeomEdgeHeal, + cb_getFaceWithinBox2D }; static void @@ -3006,35 +3269,39 @@ Datum ST_ModEdgeSplit(PG_FUNCTION_ARGS) LWPOINT *pt; LWT_TOPOLOGY *topo; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); edge_id = PG_GETARG_INT32(1) ; geom = PG_GETARG_GSERIALIZED_P(2); lwgeom = lwgeom_from_gserialized(geom); pt = lwgeom_as_lwpoint(lwgeom); - if ( ! pt ) { + if ( ! pt ) + { lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 2); + PG_FREE_IF_COPY(geom, 2); lwpgerror("ST_ModEdgeSplit third argument must be a point geometry"); PG_RETURN_NULL(); } - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3047,7 +3314,8 @@ Datum ST_ModEdgeSplit(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom, 3); lwt_FreeTopology(topo); - if ( node_id == -1 ) { + if ( node_id == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3071,35 +3339,39 @@ Datum ST_NewEdgesSplit(PG_FUNCTION_ARGS) LWPOINT *pt; LWT_TOPOLOGY *topo; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); edge_id = PG_GETARG_INT32(1) ; geom = PG_GETARG_GSERIALIZED_P(2); lwgeom = lwgeom_from_gserialized(geom); pt = lwgeom_as_lwpoint(lwgeom); - if ( ! pt ) { + if ( ! pt ) + { lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 2); + PG_FREE_IF_COPY(geom, 2); lwpgerror("ST_NewEdgesSplit third argument must be a point geometry"); PG_RETURN_NULL(); } - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3112,7 +3384,8 @@ Datum ST_NewEdgesSplit(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom, 3); lwt_FreeTopology(topo); - if ( node_id == -1 ) { + if ( node_id == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3136,19 +3409,22 @@ Datum ST_AddIsoNode(PG_FUNCTION_ARGS) LWPOINT *pt; LWT_TOPOLOGY *topo; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(2) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(2) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); if ( PG_ARGISNULL(1) ) containing_face = -1; - else { + else + { containing_face = PG_GETARG_INT32(1); - if ( containing_face < 0 ) { + if ( containing_face < 0 ) + { lwpgerror("SQL/MM Spatial exception - not within face"); PG_RETURN_NULL(); } @@ -3157,27 +3433,31 @@ Datum ST_AddIsoNode(PG_FUNCTION_ARGS) geom = PG_GETARG_GSERIALIZED_P(2); lwgeom = lwgeom_from_gserialized(geom); pt = lwgeom_as_lwpoint(lwgeom); - if ( ! pt ) { + if ( ! pt ) + { lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 2); + PG_FREE_IF_COPY(geom, 2); lwpgerror("SQL/MM Spatial exception - invalid point"); PG_RETURN_NULL(); } - if ( lwpoint_is_empty(pt) ) { + if ( lwpoint_is_empty(pt) ) + { lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 2); + PG_FREE_IF_COPY(geom, 2); lwpgerror("SQL/MM Spatial exception - empty point"); PG_RETURN_NULL(); } - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3190,7 +3470,8 @@ Datum ST_AddIsoNode(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom, 2); lwt_FreeTopology(topo); - if ( node_id == -1 ) { + if ( node_id == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3223,12 +3504,13 @@ Datum ST_AddIsoEdge(PG_FUNCTION_ARGS) toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); start_node = PG_GETARG_INT32(1); end_node = PG_GETARG_INT32(2); - if ( start_node == end_node ) { + if ( start_node == end_node ) + { lwpgerror("Closed edges would not be isolated, try ST_AddEdgeNewFaces"); PG_RETURN_NULL(); } @@ -3236,21 +3518,24 @@ Datum ST_AddIsoEdge(PG_FUNCTION_ARGS) geom = PG_GETARG_GSERIALIZED_P(3); lwgeom = lwgeom_from_gserialized(geom); curve = lwgeom_as_lwline(lwgeom); - if ( ! curve ) { + if ( ! curve ) + { lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 3); + PG_FREE_IF_COPY(geom, 3); lwpgerror("SQL/MM Spatial exception - invalid curve"); PG_RETURN_NULL(); } - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3263,7 +3548,8 @@ Datum ST_AddIsoEdge(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom, 3); lwt_FreeTopology(topo); - if ( edge_id == -1 ) { + if ( edge_id == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3287,14 +3573,15 @@ Datum ST_AddEdgeModFace(PG_FUNCTION_ARGS) LWLINE *line; LWT_TOPOLOGY *topo; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) || PG_ARGISNULL(3) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) || PG_ARGISNULL(3) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); startnode_id = PG_GETARG_INT32(1) ; endnode_id = PG_GETARG_INT32(2) ; @@ -3302,21 +3589,24 @@ Datum ST_AddEdgeModFace(PG_FUNCTION_ARGS) geom = PG_GETARG_GSERIALIZED_P(3); lwgeom = lwgeom_from_gserialized(geom); line = lwgeom_as_lwline(lwgeom); - if ( ! line ) { + if ( ! line ) + { lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 3); + PG_FREE_IF_COPY(geom, 3); lwpgerror("ST_AddEdgeModFace fourth argument must be a line geometry"); PG_RETURN_NULL(); } - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3329,7 +3619,8 @@ Datum ST_AddEdgeModFace(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom, 3); lwt_FreeTopology(topo); - if ( edge_id == -1 ) { + if ( edge_id == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3353,14 +3644,15 @@ Datum ST_AddEdgeNewFaces(PG_FUNCTION_ARGS) LWLINE *line; LWT_TOPOLOGY *topo; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) || PG_ARGISNULL(3) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) || PG_ARGISNULL(3) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); startnode_id = PG_GETARG_INT32(1) ; endnode_id = PG_GETARG_INT32(2) ; @@ -3368,21 +3660,24 @@ Datum ST_AddEdgeNewFaces(PG_FUNCTION_ARGS) geom = PG_GETARG_GSERIALIZED_P(3); lwgeom = lwgeom_from_gserialized(geom); line = lwgeom_as_lwline(lwgeom); - if ( ! line ) { + if ( ! line ) + { lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 3); + PG_FREE_IF_COPY(geom, 3); lwpgerror("ST_AddEdgeModFace fourth argument must be a line geometry"); PG_RETURN_NULL(); } - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3395,7 +3690,8 @@ Datum ST_AddEdgeNewFaces(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom, 3); lwt_FreeTopology(topo); - if ( edge_id == -1 ) { + if ( edge_id == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3418,25 +3714,28 @@ Datum ST_GetFaceGeometry(PG_FUNCTION_ARGS) GSERIALIZED *geom; MemoryContext old_context; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); face_id = PG_GETARG_INT32(1) ; - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3447,7 +3746,8 @@ Datum ST_GetFaceGeometry(PG_FUNCTION_ARGS) POSTGIS_DEBUG(1, "lwt_GetFaceGeometry returned"); lwt_FreeTopology(topo); - if ( lwgeom == NULL ) { + if ( lwgeom == NULL ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3485,13 +3785,13 @@ Datum ST_GetFaceEdges(PG_FUNCTION_ARGS) LWT_TOPOLOGY *topo; FuncCallContext *funcctx; MemoryContext oldcontext, newcontext; - TupleDesc tupdesc; - HeapTuple tuple; - AttInMetadata *attinmeta; + TupleDesc tupdesc; + HeapTuple tuple; + AttInMetadata *attinmeta; FACEEDGESSTATE *state; char buf[64]; - char *values[2]; - Datum result; + char *values[2]; + Datum result; values[0] = buf; values[1] = &(buf[32]); @@ -3503,7 +3803,8 @@ Datum ST_GetFaceEdges(PG_FUNCTION_ARGS) funcctx = SRF_FIRSTCALL_INIT(); newcontext = funcctx->multi_call_memory_ctx; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } @@ -3514,7 +3815,8 @@ Datum ST_GetFaceEdges(PG_FUNCTION_ARGS) face_id = PG_GETARG_INT32(1) ; - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } @@ -3522,7 +3824,8 @@ Datum ST_GetFaceEdges(PG_FUNCTION_ARGS) topo = lwt_LoadTopology(be_iface, toponame); oldcontext = MemoryContextSwitchTo( newcontext ); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3533,7 +3836,8 @@ Datum ST_GetFaceEdges(PG_FUNCTION_ARGS) POSTGIS_DEBUGF(1, "lwt_GetFaceEdges returned %d", nelems); lwt_FreeTopology(topo); - if ( nelems < 0 ) { + if ( nelems < 0 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3582,14 +3886,14 @@ Datum ST_GetFaceEdges(PG_FUNCTION_ARGS) state->curr+1); } if ( snprintf(values[1], 32, "%" LWTFMT_ELEMID, - state->elems[state->curr]) >= 32 ) + state->elems[state->curr]) >= 32 ) { lwerror("Signed edge identifier does not fit 32 chars ?!: %" LWTFMT_ELEMID, state->elems[state->curr]); } POSTGIS_DEBUGF(1, "ST_GetFaceEdges: cur:%d, val0:%s, val1:%s", - state->curr, values[0], values[1]); + state->curr, values[0], values[1]); tuple = BuildTupleFromCStrings(funcctx->attinmeta, values); result = HeapTupleGetDatum(tuple); @@ -3613,35 +3917,39 @@ Datum ST_ChangeEdgeGeom(PG_FUNCTION_ARGS) LWLINE *line; LWT_TOPOLOGY *topo; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); edge_id = PG_GETARG_INT32(1) ; geom = PG_GETARG_GSERIALIZED_P(2); lwgeom = lwgeom_from_gserialized(geom); line = lwgeom_as_lwline(lwgeom); - if ( ! line ) { + if ( ! line ) + { lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 2); + PG_FREE_IF_COPY(geom, 2); lwpgerror("ST_ChangeEdgeGeom third argument must be a line geometry"); PG_RETURN_NULL(); } - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3654,7 +3962,8 @@ Datum ST_ChangeEdgeGeom(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom, 2); lwt_FreeTopology(topo); - if ( ret == -1 ) { + if ( ret == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3681,25 +3990,28 @@ Datum ST_RemoveIsoNode(PG_FUNCTION_ARGS) LWT_ELEMID node_id; LWT_TOPOLOGY *topo; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); node_id = PG_GETARG_INT32(1) ; - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3710,7 +4022,8 @@ Datum ST_RemoveIsoNode(PG_FUNCTION_ARGS) POSTGIS_DEBUG(1, "lwt_RemoveIsoNode returned"); lwt_FreeTopology(topo); - if ( ret == -1 ) { + if ( ret == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3722,7 +4035,7 @@ Datum ST_RemoveIsoNode(PG_FUNCTION_ARGS) SPI_finish(); if ( snprintf(buf, 64, "Isolated node %" LWTFMT_ELEMID - " removed", node_id) >= 64 ) + " removed", node_id) >= 64 ) { buf[63] = '\0'; } @@ -3741,25 +4054,28 @@ Datum ST_RemIsoEdge(PG_FUNCTION_ARGS) LWT_ELEMID node_id; LWT_TOPOLOGY *topo; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); node_id = PG_GETARG_INT32(1) ; - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3770,7 +4086,8 @@ Datum ST_RemIsoEdge(PG_FUNCTION_ARGS) POSTGIS_DEBUG(1, "lwt_RemIsoEdge returned"); lwt_FreeTopology(topo); - if ( ret == -1 ) { + if ( ret == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3782,7 +4099,7 @@ Datum ST_RemIsoEdge(PG_FUNCTION_ARGS) SPI_finish(); if ( snprintf(buf, 64, "Isolated edge %" LWTFMT_ELEMID - " removed", node_id) >= 64 ) + " removed", node_id) >= 64 ) { buf[63] = '\0'; } @@ -3805,28 +4122,31 @@ Datum ST_MoveIsoNode(PG_FUNCTION_ARGS) LWT_TOPOLOGY *topo; POINT2D p; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); node_id = PG_GETARG_INT32(1) ; geom = PG_GETARG_GSERIALIZED_P(2); lwgeom = lwgeom_from_gserialized(geom); pt = lwgeom_as_lwpoint(lwgeom); - if ( ! pt ) { + if ( ! pt ) + { lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 2); + PG_FREE_IF_COPY(geom, 2); lwpgerror("SQL/MM Spatial exception - invalid point"); PG_RETURN_NULL(); } - if ( ! getPoint2d_p(pt->point, 0, &p) ) { + if ( ! getPoint2d_p(pt->point, 0, &p) ) + { /* Do not let empty points in, see * https://trac.osgeo.org/postgis/ticket/3234 */ @@ -3836,14 +4156,16 @@ Datum ST_MoveIsoNode(PG_FUNCTION_ARGS) /* TODO: check point for NaN values ? */ - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3856,7 +4178,8 @@ Datum ST_MoveIsoNode(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom, 2); lwt_FreeTopology(topo); - if ( ret == -1 ) { + if ( ret == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3865,8 +4188,8 @@ Datum ST_MoveIsoNode(PG_FUNCTION_ARGS) SPI_finish(); if ( snprintf(buf, 64, "Isolated Node %" LWTFMT_ELEMID - " moved to location %g,%g", - node_id, p.x, p.y) >= 64 ) + " moved to location %g,%g", + node_id, p.x, p.y) >= 64 ) { buf[63] = '\0'; } @@ -3884,25 +4207,28 @@ Datum ST_RemEdgeModFace(PG_FUNCTION_ARGS) LWT_ELEMID node_id; LWT_TOPOLOGY *topo; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); node_id = PG_GETARG_INT32(1) ; - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3913,7 +4239,8 @@ Datum ST_RemEdgeModFace(PG_FUNCTION_ARGS) POSTGIS_DEBUG(1, "lwt_RemEdgeModFace returned"); lwt_FreeTopology(topo); - if ( ret == -1 ) { + if ( ret == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3935,25 +4262,28 @@ Datum ST_RemEdgeNewFace(PG_FUNCTION_ARGS) LWT_ELEMID node_id; LWT_TOPOLOGY *topo; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); node_id = PG_GETARG_INT32(1) ; - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -3965,7 +4295,8 @@ Datum ST_RemEdgeNewFace(PG_FUNCTION_ARGS) lwt_FreeTopology(topo); SPI_finish(); - if ( ret <= 0 ) { + if ( ret <= 0 ) + { /* error or no face created */ PG_RETURN_NULL(); } @@ -3984,26 +4315,29 @@ Datum ST_ModEdgeHeal(PG_FUNCTION_ARGS) LWT_ELEMID eid1, eid2; LWT_TOPOLOGY *topo; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); eid1 = PG_GETARG_INT32(1) ; eid2 = PG_GETARG_INT32(2) ; - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -4015,7 +4349,8 @@ Datum ST_ModEdgeHeal(PG_FUNCTION_ARGS) lwt_FreeTopology(topo); SPI_finish(); - if ( ret <= 0 ) { + if ( ret <= 0 ) + { /* error, should have sent message already */ PG_RETURN_NULL(); } @@ -4034,26 +4369,29 @@ Datum ST_NewEdgeHeal(PG_FUNCTION_ARGS) LWT_ELEMID eid1, eid2; LWT_TOPOLOGY *topo; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); eid1 = PG_GETARG_INT32(1) ; eid2 = PG_GETARG_INT32(2) ; - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -4065,7 +4403,8 @@ Datum ST_NewEdgeHeal(PG_FUNCTION_ARGS) lwt_FreeTopology(topo); SPI_finish(); - if ( ret <= 0 ) { + if ( ret <= 0 ) + { /* error, should have sent message already */ PG_RETURN_NULL(); } @@ -4089,14 +4428,15 @@ Datum GetNodeByPoint(PG_FUNCTION_ARGS) toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); geom = PG_GETARG_GSERIALIZED_P(1); lwgeom = lwgeom_from_gserialized(geom); pt = lwgeom_as_lwpoint(lwgeom); - if ( ! pt ) { + if ( ! pt ) + { lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 1); + PG_FREE_IF_COPY(geom, 1); lwpgerror("Node geometry must be a point"); PG_RETURN_NULL(); } @@ -4104,19 +4444,21 @@ Datum GetNodeByPoint(PG_FUNCTION_ARGS) tol = PG_GETARG_FLOAT8(2); if ( tol < 0 ) { - PG_FREE_IF_COPY(geom, 1); + PG_FREE_IF_COPY(geom, 1); lwpgerror("Tolerance must be >=0"); PG_RETURN_NULL(); } - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -4129,7 +4471,8 @@ Datum GetNodeByPoint(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom, 1); lwt_FreeTopology(topo); - if ( node_id == -1 ) { + if ( node_id == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -4155,14 +4498,15 @@ Datum GetEdgeByPoint(PG_FUNCTION_ARGS) toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); geom = PG_GETARG_GSERIALIZED_P(1); lwgeom = lwgeom_from_gserialized(geom); pt = lwgeom_as_lwpoint(lwgeom); - if ( ! pt ) { + if ( ! pt ) + { lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 1); + PG_FREE_IF_COPY(geom, 1); lwpgerror("Node geometry must be a point"); PG_RETURN_NULL(); } @@ -4170,19 +4514,21 @@ Datum GetEdgeByPoint(PG_FUNCTION_ARGS) tol = PG_GETARG_FLOAT8(2); if ( tol < 0 ) { - PG_FREE_IF_COPY(geom, 1); + PG_FREE_IF_COPY(geom, 1); lwpgerror("Tolerance must be >=0"); PG_RETURN_NULL(); } - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -4195,7 +4541,8 @@ Datum GetEdgeByPoint(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom, 1); lwt_FreeTopology(topo); - if ( node_id == -1 ) { + if ( node_id == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -4221,14 +4568,15 @@ Datum GetFaceByPoint(PG_FUNCTION_ARGS) toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); geom = PG_GETARG_GSERIALIZED_P(1); lwgeom = lwgeom_from_gserialized(geom); pt = lwgeom_as_lwpoint(lwgeom); - if ( ! pt ) { + if ( ! pt ) + { lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 1); + PG_FREE_IF_COPY(geom, 1); lwpgerror("Node geometry must be a point"); PG_RETURN_NULL(); } @@ -4236,19 +4584,21 @@ Datum GetFaceByPoint(PG_FUNCTION_ARGS) tol = PG_GETARG_FLOAT8(2); if ( tol < 0 ) { - PG_FREE_IF_COPY(geom, 1); + PG_FREE_IF_COPY(geom, 1); lwpgerror("Tolerance must be >=0"); PG_RETURN_NULL(); } - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } topo = lwt_LoadTopology(be_iface, toponame); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -4261,7 +4611,8 @@ Datum GetFaceByPoint(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom, 1); lwt_FreeTopology(topo); - if ( node_id == -1 ) { + if ( node_id == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -4287,30 +4638,34 @@ Datum TopoGeo_AddPoint(PG_FUNCTION_ARGS) toponame_text = PG_GETARG_TEXT_P(0); toponame = text_to_cstring(toponame_text); - PG_FREE_IF_COPY(toponame_text, 0); + PG_FREE_IF_COPY(toponame_text, 0); geom = PG_GETARG_GSERIALIZED_P(1); lwgeom = lwgeom_from_gserialized(geom); pt = lwgeom_as_lwpoint(lwgeom); - if ( ! pt ) {{ - char buf[32]; - _lwtype_upper_name(lwgeom_get_type(lwgeom), buf, 32); - lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 1); - lwpgerror("Invalid geometry type (%s) passed to TopoGeo_AddPoint" - ", expected POINT", buf ); - PG_RETURN_NULL(); - }} + if ( ! pt ) + { + { + char buf[32]; + _lwtype_upper_name(lwgeom_get_type(lwgeom), buf, 32); + lwgeom_free(lwgeom); + PG_FREE_IF_COPY(geom, 1); + lwpgerror("Invalid geometry type (%s) passed to TopoGeo_AddPoint" + ", expected POINT", buf ); + PG_RETURN_NULL(); + } + } tol = PG_GETARG_FLOAT8(2); if ( tol < 0 ) { - PG_FREE_IF_COPY(geom, 1); + PG_FREE_IF_COPY(geom, 1); lwpgerror("Tolerance must be >=0"); PG_RETURN_NULL(); } - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } @@ -4322,7 +4677,8 @@ Datum TopoGeo_AddPoint(PG_FUNCTION_ARGS) be_data.topoLoadFailMessageFlavor = pre; } pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -4335,7 +4691,8 @@ Datum TopoGeo_AddPoint(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom, 1); lwt_FreeTopology(topo); - if ( node_id == -1 ) { + if ( node_id == -1 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -4371,7 +4728,8 @@ Datum TopoGeo_AddLinestring(PG_FUNCTION_ARGS) funcctx = SRF_FIRSTCALL_INIT(); newcontext = funcctx->multi_call_memory_ctx; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } @@ -4383,15 +4741,18 @@ Datum TopoGeo_AddLinestring(PG_FUNCTION_ARGS) geom = PG_GETARG_GSERIALIZED_P(1); lwgeom = lwgeom_from_gserialized(geom); ln = lwgeom_as_lwline(lwgeom); - if ( ! ln ) {{ - char buf[32]; - _lwtype_upper_name(lwgeom_get_type(lwgeom), buf, 32); - lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 1); - lwpgerror("Invalid geometry type (%s) passed to " - "TopoGeo_AddLinestring, expected LINESTRING", buf); - PG_RETURN_NULL(); - }} + if ( ! ln ) + { + { + char buf[32]; + _lwtype_upper_name(lwgeom_get_type(lwgeom), buf, 32); + lwgeom_free(lwgeom); + PG_FREE_IF_COPY(geom, 1); + lwpgerror("Invalid geometry type (%s) passed to " + "TopoGeo_AddLinestring, expected LINESTRING", buf); + PG_RETURN_NULL(); + } + } tol = PG_GETARG_FLOAT8(2); if ( tol < 0 ) @@ -4401,7 +4762,8 @@ Datum TopoGeo_AddLinestring(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } @@ -4414,7 +4776,8 @@ Datum TopoGeo_AddLinestring(PG_FUNCTION_ARGS) } oldcontext = MemoryContextSwitchTo( newcontext ); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -4427,7 +4790,8 @@ Datum TopoGeo_AddLinestring(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom, 1); lwt_FreeTopology(topo); - if ( nelems < 0 ) { + if ( nelems < 0 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -4462,7 +4826,7 @@ Datum TopoGeo_AddLinestring(PG_FUNCTION_ARGS) id = state->elems[state->curr++]; POSTGIS_DEBUGF(1, "TopoGeo_AddLinestring: cur:%d, val:%" LWTFMT_ELEMID, - state->curr-1, id); + state->curr-1, id); result = Int32GetDatum((int32)id); @@ -4495,7 +4859,8 @@ Datum TopoGeo_AddPolygon(PG_FUNCTION_ARGS) funcctx = SRF_FIRSTCALL_INIT(); newcontext = funcctx->multi_call_memory_ctx; - if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) { + if ( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) + { lwpgerror("SQL/MM Spatial exception - null argument"); PG_RETURN_NULL(); } @@ -4507,15 +4872,18 @@ Datum TopoGeo_AddPolygon(PG_FUNCTION_ARGS) geom = PG_GETARG_GSERIALIZED_P(1); lwgeom = lwgeom_from_gserialized(geom); pol = lwgeom_as_lwpoly(lwgeom); - if ( ! pol ) {{ - char buf[32]; - _lwtype_upper_name(lwgeom_get_type(lwgeom), buf, 32); - lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 1); - lwpgerror("Invalid geometry type (%s) passed to " - "TopoGeo_AddPolygon, expected POLYGON", buf); - PG_RETURN_NULL(); - }} + if ( ! pol ) + { + { + char buf[32]; + _lwtype_upper_name(lwgeom_get_type(lwgeom), buf, 32); + lwgeom_free(lwgeom); + PG_FREE_IF_COPY(geom, 1); + lwpgerror("Invalid geometry type (%s) passed to " + "TopoGeo_AddPolygon, expected POLYGON", buf); + PG_RETURN_NULL(); + } + } tol = PG_GETARG_FLOAT8(2); if ( tol < 0 ) @@ -4525,7 +4893,8 @@ Datum TopoGeo_AddPolygon(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - if ( SPI_OK_CONNECT != SPI_connect() ) { + if ( SPI_OK_CONNECT != SPI_connect() ) + { lwpgerror("Could not connect to SPI"); PG_RETURN_NULL(); } @@ -4538,7 +4907,8 @@ Datum TopoGeo_AddPolygon(PG_FUNCTION_ARGS) } oldcontext = MemoryContextSwitchTo( newcontext ); pfree(toponame); - if ( ! topo ) { + if ( ! topo ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -4551,7 +4921,8 @@ Datum TopoGeo_AddPolygon(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom, 1); lwt_FreeTopology(topo); - if ( nelems < 0 ) { + if ( nelems < 0 ) + { /* should never reach this point, as lwerror would raise an exception */ SPI_finish(); PG_RETURN_NULL(); @@ -4586,7 +4957,7 @@ Datum TopoGeo_AddPolygon(PG_FUNCTION_ARGS) id = state->elems[state->curr++]; POSTGIS_DEBUGF(1, "TopoGeo_AddPolygon: cur:%d, val:%" LWTFMT_ELEMID, - state->curr-1, id); + state->curr-1, id); result = Int32GetDatum((int32)id); -- 2.40.0