PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ _lwt_MakeRingShell()

static LWPOLY * _lwt_MakeRingShell ( LWT_TOPOLOGY topo,
LWT_ELEMID signed_edge_ids,
uint64_t  num_signed_edge_ids 
)
static

Definition at line 1896 of file lwgeom_topo.c.

1897{
1898 LWT_ELEMID *edge_ids;
1899 uint64_t numedges, i, j;
1900 LWT_ISO_EDGE *ring_edges;
1901
1902 /* Construct a polygon using edges of the ring */
1903 numedges = 0;
1904 edge_ids = lwalloc(sizeof(LWT_ELEMID)*num_signed_edge_ids);
1905 for (i=0; i<num_signed_edge_ids; ++i) {
1906 int absid = llabs(signed_edge_ids[i]);
1907 int found = 0;
1908 /* Do not add the same edge twice */
1909 for (j=0; j<numedges; ++j) {
1910 if ( edge_ids[j] == absid ) {
1911 found = 1;
1912 break;
1913 }
1914 }
1915 if ( ! found ) edge_ids[numedges++] = absid;
1916 }
1917 i = numedges;
1918 ring_edges = lwt_be_getEdgeById(topo, edge_ids, &i,
1920 lwfree( edge_ids );
1921 if (i == UINT64_MAX)
1922 {
1924 return NULL;
1925 }
1926 else if ( i != numedges )
1927 {
1928 lwfree( signed_edge_ids );
1929 _lwt_release_edges(ring_edges, i);
1930 lwerror("Unexpected error: %" LWTFMT_ELEMID
1931 " edges found when expecting %" PRIu64, i, numedges);
1932 return NULL;
1933 }
1934
1935 /* Should now build a polygon with those edges, in the order
1936 * given by GetRingEdges.
1937 */
1938 POINTARRAY *pa = NULL;
1939 for ( i=0; i<num_signed_edge_ids; ++i )
1940 {
1941 LWT_ELEMID eid = signed_edge_ids[i];
1942 LWDEBUGF(2, "Edge %llu in ring is edge %" LWTFMT_ELEMID, i, eid);
1943 LWT_ISO_EDGE *edge = NULL;
1944 POINTARRAY *epa;
1945 for ( j=0; j<numedges; ++j )
1946 {
1947 if ( ring_edges[j].edge_id == llabs(eid) )
1948 {
1949 edge = &(ring_edges[j]);
1950 break;
1951 }
1952 }
1953 if ( edge == NULL )
1954 {
1955 _lwt_release_edges(ring_edges, numedges);
1956 lwerror("missing edge that was found in ring edges loop");
1957 return NULL;
1958 }
1959
1960 if ( pa == NULL )
1961 {
1962 pa = ptarray_clone_deep(edge->geom->points);
1963 if ( eid < 0 ) ptarray_reverse_in_place(pa);
1964 }
1965 else
1966 {
1967 if ( eid < 0 )
1968 {
1969 epa = ptarray_clone_deep(edge->geom->points);
1971 ptarray_append_ptarray(pa, epa, 0);
1972 ptarray_free(epa);
1973 }
1974 else
1975 {
1976 /* avoid a clone here */
1977 ptarray_append_ptarray(pa, edge->geom->points, 0);
1978 }
1979 }
1980 }
1981 _lwt_release_edges(ring_edges, numedges);
1982 POINTARRAY **points = lwalloc(sizeof(POINTARRAY*));
1983 points[0] = pa;
1984
1985 /* NOTE: the ring may very well have collapsed components,
1986 * which would make it topologically invalid
1987 */
1988 LWPOLY* shell = lwpoly_construct(0, 0, 1, points);
1989 return shell;
1990}
int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance)
Append a POINTARRAY, pa2 to the end of an existing POINTARRAY, pa1.
Definition ptarray.c:177
void * lwalloc(size_t size)
Definition lwutil.c:227
void lwfree(void *mem)
Definition lwutil.c:248
void ptarray_free(POINTARRAY *pa)
Definition ptarray.c:327
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition lwpoly.c:43
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
Definition ptarray.c:643
void ptarray_reverse_in_place(POINTARRAY *pa)
Definition ptarray.c:339
LWT_INT64 LWT_ELEMID
Identifier of topology element.
#define LWT_COL_EDGE_EDGE_ID
Edge fields.
#define LWT_COL_EDGE_GEOM
#define PGTOPO_BE_ERROR()
#define LWTFMT_ELEMID
#define LWDEBUGF(level, msg,...)
Definition lwgeom_log.h:106
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
LWT_ISO_EDGE * lwt_be_getEdgeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields)
void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
POINTARRAY * points
Definition liblwgeom.h:483

References _lwt_release_edges(), LWT_ISO_EDGE::geom, lwalloc(), LWDEBUGF, lwerror(), lwfree(), lwpoly_construct(), lwt_be_getEdgeById(), LWT_COL_EDGE_EDGE_ID, LWT_COL_EDGE_GEOM, LWTFMT_ELEMID, PGTOPO_BE_ERROR, LWLINE::points, ptarray_append_ptarray(), ptarray_clone_deep(), ptarray_free(), and ptarray_reverse_in_place().

Referenced by _lwt_AddFaceSplit(), and lwt_ChangeEdgeGeom().

Here is the call graph for this function:
Here is the caller graph for this function: