{
char* wkt = NULL;
size_t wkt_size = 0;
-
+
wkt = lwgeom_to_wkt(lwgeom, WKT_EXTENDED, 12, &wkt_size);
if ( ! wkt )
if ( ! p || ! p->point )
return LW_FALSE;
-
+
pt = getPoint2d_cp(p->point, 0);
center.x = cx;
if ( lwgeom_is_empty(lwgeom) ) return;
FLAGS_SET_BBOX(lwgeom->flags, 1);
-
+
if ( ! ( gbox || lwgeom->bbox ) )
{
lwgeom->bbox = gbox_new(lwgeom->flags);
- lwgeom_calculate_gbox(lwgeom, lwgeom->bbox);
+ lwgeom_calculate_gbox(lwgeom, lwgeom->bbox);
}
else if ( gbox && ! lwgeom->bbox )
{
lwgeom->bbox = gbox_clone(gbox);
}
-
+
if ( lwgeom_is_collection(lwgeom) )
{
int i;
if( FLAGS_GET_GEODETIC(lwgeom->flags) )
return lwgeom_calculate_gbox_geodetic(lwgeom, gbox);
else
- return lwgeom_calculate_gbox_cartesian(lwgeom, gbox);
+ return lwgeom_calculate_gbox_cartesian(lwgeom, gbox);
}
void
LWGEOM*
lwgeom_force_2d(const LWGEOM *geom)
-{
+{
return lwgeom_force_dims(geom, 0, 0);
}
LWGEOM*
lwgeom_force_3dz(const LWGEOM *geom)
-{
+{
return lwgeom_force_dims(geom, 1, 0);
}
LWGEOM*
lwgeom_force_3dm(const LWGEOM *geom)
-{
+{
return lwgeom_force_dims(geom, 0, 1);
}
LWGEOM*
lwgeom_force_4d(const LWGEOM *geom)
-{
+{
return lwgeom_force_dims(geom, 1, 1);
}
LWGEOM*
lwgeom_force_dims(const LWGEOM *geom, int hasz, int hasm)
-{
+{
switch(geom->type)
{
case POINTTYPE:
LWGEOM*
lwgeom_force_sfs(LWGEOM *geom, int version)
-{
+{
LWCOLLECTION *col;
int i;
LWGEOM *g;
return (LWGEOM *)geom;
}
}
-
+
/* SFS 1.1 version */
switch(geom->type)
}
col->type = COLLECTIONTYPE;
return lwmpoly_as_lwgeom((LWMPOLY*)geom);
-
+
case POLYHEDRALSURFACETYPE:
geom->type = COLLECTIONTYPE;
return (LWGEOM *)geom;
col->geoms[i] = lwgeom_force_sfs((LWGEOM*)col->geoms[i], version);
return lwcollection_as_lwgeom((LWCOLLECTION*)geom);
-
+
default:
return (LWGEOM *)geom;
}
LWPOLY *ply;
LWCOLLECTION *col;
int i;
-
+
FLAGS_SET_GEODETIC(geom->flags, value);
if ( geom->bbox )
FLAGS_SET_GEODETIC(geom->bbox->flags, value);
-
+
switch(geom->type)
{
case POINTTYPE:
lwgeom_is_closed(const LWGEOM *geom)
{
int type = geom->type;
-
+
if( lwgeom_is_empty(geom) )
return LW_FALSE;
-
+
/* Test linear types for closure */
switch (type)
{
case POLYHEDRALSURFACETYPE:
return lwpsurface_is_closed((LWPSURFACE*)geom);
}
-
+
/* Recurse into collections and see if anything is not closed */
if ( lwgeom_is_collection(geom) )
{
}
return LW_TRUE;
}
-
+
/* All non-linear non-collection types we will call closed */
return LW_TRUE;
}
if( ! lwgeom ) return;
LWDEBUGF(5,"freeing a %s",lwtype_name(lwgeom->type));
-
+
switch (lwgeom->type)
{
case POINTTYPE:
int lwgeom_count_vertices(const LWGEOM *geom)
{
int result = 0;
-
+
/* Null? Zero. */
if( ! geom ) return 0;
-
+
LWDEBUGF(4, "lwgeom_count_vertices got type %s",
lwtype_name(geom->type));
/* Null? Zero. */
if( ! geom ) return -1;
-
+
LWDEBUGF(4, "lwgeom_dimension got type %s",
lwtype_name(geom->type));
int lwgeom_count_rings(const LWGEOM *geom)
{
int result = 0;
-
+
/* Null? Empty? Zero. */
if( ! geom || lwgeom_is_empty(geom) )
return 0;
double lwgeom_area(const LWGEOM *geom)
{
int type = geom->type;
-
+
if ( type == POLYGONTYPE )
return lwpoly_area((LWPOLY*)geom);
else if ( type == CURVEPOLYTYPE )
{
if ( ! lwgeom )
return LW_FAILURE;
-
+
switch( lwgeom->type )
{
case POINTTYPE:
double height = clip->ymax - clip->ymin;
GBOX subbox1, subbox2;
LWGEOM *clipped1, *clipped2;
-
+
if ( geom->type == POLYHEDRALSURFACETYPE || geom->type == TINTYPE )
{
lwerror("%s: unsupported geometry type '%s'", __func__, lwtype_name(geom->type));
}
-
+
if ( width == 0.0 && height == 0.0 )
{
if ( geom->type == POINTTYPE )
{
lwcollection_add_lwgeom(col, lwgeom_clone_deep(geom));
- return 1;
+ return 1;
}
else
{
return 0;
}
}
-
+
/* Always just recurse into collections */
if ( lwgeom_is_collection(geom) && geom->type != MULTIPOINTTYPE )
{
}
return n;
}
-
+
/* But don't go too far. 2^50 ~= 10^15, that's enough subdivision */
/* Just add what's left */
if ( depth > maxdepth )
lwcollection_add_lwgeom(col, lwgeom_clone_deep(geom));
return 0;
}
-
+
nvertices = lwgeom_count_vertices(geom);
/* Skip empties entirely */
if ( nvertices == 0 )
{
return 0;
}
-
+
/* If it is under the vertex tolerance, just add it, we're done */
if ( nvertices < maxvertices )
{
lwcollection_add_lwgeom(col, lwgeom_clone_deep(geom));
return 1;
}
-
+
subbox1 = subbox2 = *clip;
if ( width > height )
{
{
subbox1.ymax = subbox2.ymin = (clip->ymin + clip->ymax)/2;
}
-
+
if ( height == 0 )
{
subbox1.ymax += FP_TOLERANCE;
subbox1.xmin -= FP_TOLERANCE;
subbox2.xmin -= FP_TOLERANCE;
}
-
+
clipped1 = lwgeom_clip_by_rect(geom, subbox1.xmin, subbox1.ymin, subbox1.xmax, subbox1.ymax);
clipped2 = lwgeom_clip_by_rect(geom, subbox2.xmin, subbox2.ymin, subbox2.xmax, subbox2.ymax);
-
+
++depth;
-
+
if ( clipped1 )
{
n += lwgeom_subdivide_recursive(clipped1, maxvertices, depth, col, &subbox1);
n += lwgeom_subdivide_recursive(clipped2, maxvertices, depth, col, &subbox2);
lwgeom_free(clipped2);
}
-
+
return n;
-
+
}
LWCOLLECTION *
static int minmaxvertices = 8;
LWCOLLECTION *col;
GBOX clip;
-
+
col = lwcollection_construct_empty(COLLECTIONTYPE, geom->srid, lwgeom_has_z(geom), lwgeom_has_m(geom));
if ( lwgeom_is_empty(geom) )
lwcollection_free(col);
lwerror("%s: cannot subdivide to fewer than %d vertices per output", __func__, minmaxvertices);
}
-
+
clip = *(lwgeom_get_bbox(geom));
lwgeom_subdivide_recursive(geom, maxvertices, startdepth, col, &clip);
lwgeom_set_srid((LWGEOM*)col, geom->srid);