GEOSCoordSeq_setX(sq, i, p2d->x);
GEOSCoordSeq_setY(sq, i, p2d->y);
-
+
if ( dims == 3 )
GEOSCoordSeq_setZ(sq, i, p3d->z);
}
lwgeom_free(lwgeom_stroked);
return g;
}
-
+
switch (lwgeom->type)
{
LWPOINT *lwp = NULL;
LWPOLY *lwpoly = NULL;
LWLINE *lwl = NULL;
LWCOLLECTION *lwc = NULL;
-
+
case POINTTYPE:
lwp = (LWPOINT *)lwgeom;
-
+
if ( lwgeom_is_empty(lwgeom) )
{
g = GEOSGeom_createEmptyPolygon();
for (i=0; i<ngeoms; ++i)
{
GEOSGeometry* g;
-
+
if( lwgeom_is_empty(lwc->geoms[i]) )
continue;
-
+
g = LWGEOM2GEOS(lwc->geoms[i], 0);
if ( ! g )
{
initGEOS(lwnotice, lwgeom_geos_error);
geos_in = LWGEOM2GEOS(geom, 0);
-
+
if ( 0 == geos_in ) /* exception thrown at construction */
{
lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
lwgeom_geos_errmsg);
}
return geom_out;
-
+
}
LWGEOM*
lwerror("%s: only polygons supported", __func__);
return NULL;
}
-
+
if (npoints == 0 || lwgeom_is_empty(lwgeom))
{
return NULL;
// return lwmpoint_construct_empty(lwgeom_get_srid(poly), lwgeom_has_z(poly), lwgeom_has_m(poly));
}
-
+
if (!lwpoly->bbox)
{
lwgeom_calculate_gbox(lwgeom, &bbox);
lwerror("%s: zero area input polygon, TBD", __func__);
return NULL;
}
-
+
/* Gross up our test set a bit to increase odds of getting */
/* coverage in one pass */
sample_npoints = npoints * bbox_area / area;
-
+
/* We're going to generate points using a sample grid */
/* as described http://lin-ear-th-inking.blogspot.ca/2010/05/more-random-points-in-jts.html */
/* to try and get a more uniform "random" set of points */
sample_sqrt = lround(sqrt(sample_npoints));
if (sample_sqrt == 0)
sample_sqrt = 1;
-
+
/* Calculate the grids we're going to randomize within */
if (bbox_width > bbox_height)
{
sample_width = ceil((double)sample_npoints / (double)sample_height);
sample_cell_size = bbox_height / sample_height;
}
-
+
/* Prepare the polygon for fast true/false testing */
initGEOS(lwnotice, lwgeom_geos_error);
g = (GEOSGeometry *)LWGEOM2GEOS(lwgeom, 0);
return NULL;
}
gprep = GEOSPrepare(g);
-
+
/* Get an empty multi-point ready to return */
mpt = lwmpoint_construct_empty(srid, 0, 0);
-
+
/* Init random number generator */
srand(time(NULL));
}
}
shuffle(cells, sample_height*sample_width, 2*sizeof(int));
-
+
/* Start testing points */
while (npoints_generated < npoints)
{
gpt = GEOSGeom_createPoint(gseq);
contains = GEOSPreparedIntersects(gprep, gpt);
-
+
GEOSGeom_destroy(gpt);
if (contains == 2)
break;
}
}
-
+
/* Short-circuit check for ctrl-c occasionally */
npoints_tested++;
if (npoints_tested % 10000 == 0)
{
LW_ON_INTERRUPT(GEOSPreparedGeom_destroy(gprep); GEOSGeom_destroy(g); return NULL);
}
-
+
if (done) break;
}
if (done || iterations > 100) break;
}
-
+
GEOSPreparedGeom_destroy(gprep);
GEOSGeom_destroy(g);
lwfree(cells);
-
+
return mpt;
}
double area;
int i;
LWMPOINT *mpt = NULL;
-
+
if (lwgeom_get_type(lwgeom) != MULTIPOLYGONTYPE)
{
lwerror("%s: only multipolygons supported", __func__);
- return NULL;
+ return NULL;
}
if (npoints == 0 || lwgeom_is_empty(lwgeom))
{
return NULL;
}
-
+
area = lwgeom_area(lwgeom);
-
+
for (i = 0; i < lwmpoly->ngeoms; i++)
{
double sub_area = lwpoly_area(lwmpoly->geoms[i]);
}
}
}
-
+
return mpt;
}
return lwpoly_to_points((LWPOLY*)lwgeom, npoints);
default:
lwerror("%s: unsupported geometry type '%s'", __func__, lwtype_name(lwgeom_get_type(lwgeom)));
- return NULL;
+ return NULL;
}
}
}
return lwgeom_result;
-
+
#endif /* POSTGIS_GEOS_VERSION < 34 */
}