Select to view content in your preferred language

Create random Map Points within  a polygon.

992
3
05-03-2010 09:42 AM
MarkMassy
New Contributor
Hi all,

I'm using the MarkerSymbol to add graphics to a map. I want to be able to create random MapPoints for the graphic and the points need to be within a polygon (e.g. a county). Any suggestions will be greatly appreciated.

Thanks.
Tags (2)
0 Kudos
3 Replies
EricPaitz
Esri Contributor
I am not 100% sure how to quickly guarantee that a random point will fall within a polygon but you could calculate a random X and a random Y number that will be within the Extent of your polygon. You can calculate a random X that is greater then XMIN and less then XMAX and the same for the Y coordinate. If you wanted to take it one more step then you can check to see if that random XY is also contained within the polygon but the worst case scenario is this loop could run for a very long time until it randomly generates a point that is within the extent and within the polygon. Based on some quick google searches I think to deal with the polygon you will have to get into more complicated math like point in polygon or the polygon fill algorithm.
0 Kudos
MarkMassy
New Contributor
Thanks for the quick reply. I thought about that and I also tried generating the points using the centroid of the polygon as a point of reference but some of the points were being placed outside the polygon. I'm thinking about generating random points using ArcMap and store the xy's in an XMLList from which I can select a point to place my graphic...
0 Kudos
EricPaitz
Esri Contributor
Another idea might be to use the minimal bounding rectangle instead of the minimum bounding rectangle, I think that is the correct terminology. Basically instead of using the smallest rectangle that can contain the polygon use the smallest rectangle that will fit inside the polygon. Then use its XMIN, YMIN, etc...to calculate random numbers.
0 Kudos