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

◆ _lwt_GetEqualEdge()

static LWT_ELEMID _lwt_GetEqualEdge ( LWT_TOPOLOGY topo,
LWLINE edge,
int *  forward 
)
static

Definition at line 5208 of file lwgeom_topo.c.

5209{
5210 LWT_ELEMID id;
5211 LWT_ISO_EDGE *edges;
5212 uint64_t num, i;
5213 const GBOX *qbox = lwgeom_get_bbox( lwline_as_lwgeom(edge) );
5214 GEOSGeometry *edgeg;
5215 const int flds = LWT_COL_EDGE_EDGE_ID|LWT_COL_EDGE_GEOM;
5216
5217 edges = lwt_be_getEdgeWithinBox2D( topo, qbox, &num, flds, 0 );
5218 if (num == UINT64_MAX)
5219 {
5221 return -1;
5222 }
5223 if ( num )
5224 {
5225 initGEOS(lwnotice, lwgeom_geos_error);
5226
5227 edgeg = LWGEOM2GEOS( lwline_as_lwgeom(edge), 0 );
5228 if ( ! edgeg )
5229 {
5230 _lwt_release_edges(edges, num);
5231 lwerror("Could not convert edge geometry to GEOS: %s", lwgeom_geos_errmsg);
5232 return -1;
5233 }
5234 for (i=0; i<num; ++i)
5235 {
5236 LWT_ISO_EDGE *e = &(edges[i]);
5237 LWGEOM *g = lwline_as_lwgeom(e->geom);
5238 GEOSGeometry *gg;
5239 int equals;
5240 gg = LWGEOM2GEOS( g, 0 );
5241 if ( ! gg )
5242 {
5243 GEOSGeom_destroy(edgeg);
5244 _lwt_release_edges(edges, num);
5245 lwerror("Could not convert edge geometry to GEOS: %s", lwgeom_geos_errmsg);
5246 return -1;
5247 }
5248 equals = GEOSEquals(gg, edgeg);
5249 GEOSGeom_destroy(gg);
5250 if ( equals == 2 )
5251 {
5252 GEOSGeom_destroy(edgeg);
5253 _lwt_release_edges(edges, num);
5254 lwerror("GEOSEquals exception: %s", lwgeom_geos_errmsg);
5255 return -1;
5256 }
5257 if ( equals )
5258 {
5259 id = e->edge_id;
5260 /* Check if direction also matches */
5261 if ( forward )
5262 {
5263 /* If input line is closed, we use winding order */
5264 if ( lwline_is_closed(edge) )
5265 {
5266 if ( ptarray_isccw(edge->points) == ptarray_isccw(e->geom->points) )
5267 {
5268 *forward = 1;
5269 }
5270 else
5271 {
5272 *forward = 0;
5273 }
5274 }
5275 else
5276 {
5277 /* Input line is not closed, checking fist point is enough */
5278 if (
5279 memcmp(
5280 getPoint_internal(edge->points, 0),
5282 sizeof(POINT2D)
5283 ) == 0
5284 )
5285 {
5286 *forward = 1;
5287 }
5288 else
5289 {
5290 *forward = 0;
5291 }
5292 }
5293 }
5294 GEOSGeom_destroy(edgeg);
5295 _lwt_release_edges(edges, num);
5296 return id;
5297 }
5298 }
5299 GEOSGeom_destroy(edgeg);
5300 _lwt_release_edges(edges, num);
5301 }
5302
5303 return 0;
5304}
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
void lwgeom_geos_error(const char *fmt,...)
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition lwgeom.c:367
const GBOX * lwgeom_get_bbox(const LWGEOM *lwgeom)
Get a non-empty geometry bounding box, computing and caching it if not already there.
Definition lwgeom.c:771
int lwline_is_closed(const LWLINE *line)
Definition lwline.c:455
int ptarray_isccw(const POINTARRAY *pa)
Definition ptarray.c:1182
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()
void lwnotice(const char *fmt,...) __attribute__((format(printf
Write a notice out to the notice handler.
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
void _lwt_release_edges(LWT_ISO_EDGE *edges, int num_edges)
LWT_ISO_EDGE * lwt_be_getEdgeWithinBox2D(const LWT_TOPOLOGY *topo, const GBOX *box, uint64_t *numelems, int fields, uint64_t limit)
static uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition lwinline.h:75
POINTARRAY * points
Definition liblwgeom.h:483
LWT_ELEMID edge_id

References _lwt_release_edges(), LWT_ISO_EDGE::edge_id, LWT_ISO_EDGE::geom, getPoint_internal(), lwerror(), LWGEOM2GEOS(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwgeom_get_bbox(), lwline_as_lwgeom(), lwline_is_closed(), lwnotice(), lwt_be_getEdgeWithinBox2D(), LWT_COL_EDGE_EDGE_ID, LWT_COL_EDGE_GEOM, PGTOPO_BE_ERROR, LWLINE::points, and ptarray_isccw().

Referenced by _lwt_AddLineEdge(), and _lwt_SnapEdgeToExistingNode().

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