* 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
LWT_BE_DATA be_data;
-struct LWT_BE_TOPOLOGY_T {
+struct LWT_BE_TOPOLOGY_T
+{
LWT_BE_DATA* be_data;
char *name;
int id;
/* 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
snprintf(buf, buflen, "%s", lwtype_name(type));
buf[buflen-1] = '\0';
ptr = buf;
- while (*ptr) {
+ while (*ptr)
+ {
*ptr = toupper(*ptr);
++ptr;
}
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);
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));
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;
}
}
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);
}
#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);
{
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);
}
}
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));
}
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
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);
}
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);
}
{
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);
}
}
{
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 = ",";
}
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
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);
}
}
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)");
}
}
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;
}
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;
}
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;
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;
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, ")");
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;
}
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;
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, ")");
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;
}
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;
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);
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;
}
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;
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, ")");
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;
}
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;
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);
}
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 );
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);
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;
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;
}
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;
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, ")");
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;
}
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;
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;
}
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;
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);
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 )
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;
appendStringInfo(sql, "INSERT INTO \"%s\".node (", topo->name);
addNodeFields(sql, LWT_COL_NODE_ALL);
appendStringInfoString(sql, ") VALUES ");
- for ( i=0; i<numelems; ++i ) {
+ for ( i=0; i<numelems; ++i )
+ {
if ( i ) appendStringInfoString(sql, ",");
// TODO: prepare and execute ?
addNodeValues(sql, &nodes[i], LWT_COL_NODE_ALL);
spi_result = SPI_execute(sql->data, 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;
}
{
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);
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;
appendStringInfo(sql, "INSERT INTO \"%s\".edge_data (", topo->name);
addEdgeFields(sql, LWT_COL_EDGE_ALL, 1);
appendStringInfoString(sql, ") VALUES ");
- for ( i=0; i<numelems; ++i ) {
+ for ( i=0; i<numelems; ++i )
+ {
if ( i ) appendStringInfoString(sql, ",");
// TODO: prepare and execute ?
addEdgeValues(sql, &edges[i], LWT_COL_EDGE_ALL, 1);
MemoryContextSwitchTo( oldcontext ); /* switch back */
if ( spi_result != ( needsEdgeIdReturn ? 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_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;
{
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);
}
}
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;
appendStringInfo(sql, "INSERT INTO \"%s\".face (", topo->name);
addFaceFields(sql, LWT_COL_FACE_ALL);
appendStringInfoString(sql, ") VALUES ");
- for ( i=0; i<numelems; ++i ) {
+ for ( i=0; i<numelems; ++i )
+ {
if ( i ) appendStringInfoString(sql, ",");
// TODO: prepare and execute ?
addFaceValues(sql, &faces[i], topo->srid);
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;
{
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);
}
}
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;
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 );
}
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);
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;
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 );
}
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);
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; i<numnodes; ++i) {
+ for (i=0; i<numnodes; ++i)
+ {
const LWT_ISO_NODE* node = &(nodes[i]);
if ( i ) appendStringInfoString(sql, ",");
addNodeValues(sql, node, LWT_COL_NODE_NODE_ID|fields);
appendStringInfo(sql, " ) UPDATE \"%s\".node n SET ", topo->name);
/* 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);
}
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);
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; i<numfaces; ++i) {
+ for (i=0; i<numfaces; ++i)
+ {
const LWT_ISO_FACE* face = &(faces[i]);
char *hexbox = _box2d_to_hexwkb(face->mbr, 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);
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);
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; i<numedges; ++i) {
+ for (i=0; i<numedges; ++i)
+ {
const LWT_ISO_EDGE* edge = &(edges[i]);
if ( i ) appendStringInfoString(sql, ",");
addEdgeValues(sql, edge, fields|LWT_COL_EDGE_EDGE_ID, 0);
appendStringInfo(sql, ") UPDATE \"%s\".edge_data e SET ", topo->name);
/* 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);
}
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);
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;
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);
cb_getNextEdgeId( const LWT_BE_TOPOLOGY* topo )
{
MemoryContext oldcontext = CurrentMemoryContext;
- int spi_result;
+ int spi_result;
StringInfoData sqldata;
StringInfo sql = &sqldata;
bool isnull;
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;
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 */
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);
}
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 )
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);
}
}
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);
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);
}
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 )
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);
}
}
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);
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;
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);
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;
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
*/
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);
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;
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;
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);
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;
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;
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);
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);
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);
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;
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);
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);
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);
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;
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;
!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);
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; i<numelems; ++i) {
+ for (i=0; i<numelems; ++i)
+ {
appendStringInfo(sql, "%s%" LWTFMT_ELEMID, (i?",":""), ids[i]);
}
appendStringInfoString(sql, ")");
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);
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; i<numelems; ++i) {
+ topo->name);
+ for (i=0; i<numelems; ++i)
+ {
appendStringInfo(sql, "%s%" LWTFMT_ELEMID, (i?",":""), ids[i]);
}
appendStringInfoString(sql, ")");
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);
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;
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;
}
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;
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;
}
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;
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;
}
}
-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
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();
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();
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();
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();
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();
}
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();
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();
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();
}
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();
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();
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) ;
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();
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();
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) ;
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();
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();
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();
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();
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]);
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();
}
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);
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();
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();
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);
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();
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();
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();
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();
SPI_finish();
if ( snprintf(buf, 64, "Isolated node %" LWTFMT_ELEMID
- " removed", node_id) >= 64 )
+ " removed", node_id) >= 64 )
{
buf[63] = '\0';
}
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();
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();
SPI_finish();
if ( snprintf(buf, 64, "Isolated edge %" LWTFMT_ELEMID
- " removed", node_id) >= 64 )
+ " removed", node_id) >= 64 )
{
buf[63] = '\0';
}
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
*/
/* 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();
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();
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';
}
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();
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();
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();
lwt_FreeTopology(topo);
SPI_finish();
- if ( ret <= 0 ) {
+ if ( ret <= 0 )
+ {
/* error or no face created */
PG_RETURN_NULL();
}
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();
lwt_FreeTopology(topo);
SPI_finish();
- if ( ret <= 0 ) {
+ if ( ret <= 0 )
+ {
/* error, should have sent message already */
PG_RETURN_NULL();
}
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();
lwt_FreeTopology(topo);
SPI_finish();
- if ( ret <= 0 ) {
+ if ( ret <= 0 )
+ {
/* error, should have sent message already */
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);
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();
}
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();
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();
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();
}
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();
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();
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();
}
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();
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();
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();
}
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();
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();
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();
}
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 )
PG_RETURN_NULL();
}
- if ( SPI_OK_CONNECT != SPI_connect() ) {
+ if ( SPI_OK_CONNECT != SPI_connect() )
+ {
lwpgerror("Could not connect to SPI");
PG_RETURN_NULL();
}
}
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();
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();
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);
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();
}
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 )
PG_RETURN_NULL();
}
- if ( SPI_OK_CONNECT != SPI_connect() ) {
+ if ( SPI_OK_CONNECT != SPI_connect() )
+ {
lwpgerror("Could not connect to SPI");
PG_RETURN_NULL();
}
}
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();
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();
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);