> What would be the easiest way to randomly generate points within a
> given geometry? I was hoping getInteriorPoint() would do so but it
> always returns the same point.
Be sure that if getInteriorPoint() had done what you want, somebody
would already have requested that it does return always the same point ;-)
Just joking. Don't know what you really need to achieve but here is how
I would do (not tested) :
env = geometry.getInternalEvelope()
// create a random point in the geometry envelope
x = env.getMinX() + Math.random()*env.getWidth();
y = env.getMinY() + Math.random()*env.getHeight();
test if (x, y) is inside your geometry, if not try another random point
pros : random aspect should be quite good
cons : quite expansive because of test inclusion
May be there is a more efficient solution by hacking
If each of your geometries occupy most of its bounding envelope I'd do
the simple method that Michaël suggests.
If a geometry only occupies a very small portion of its envelope a
better way is to stratify the random point generation by dividing up
the envelope into smaller, equal-sized rectangles, noting which of
these overlap the geometry. Then generate each point using the simple
algorithm within a randomly chosen rectangle.