This little bit of code is quite useful. Thanks for writing it. I found a few cases where the irregular geometries of feature still confuse the code and place the "center point" outside of the geometry. I'm tracking down the reason as best I can and will submit whatever I find. If one of you guys has a quicker route to fixing this than myself I'd gladly take that as well.
I'll attach the GEOJSON that can be used to reproduce the error.
{"name":"dbo.ICOOR","type":"FeatureCollection"
,"features":[
{
"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-123.273625,49.3610850000001],[-123.274258,49.3612660000001],[-123.274735,49.3615070000001],[-123.275153,49.3618200000001],[-123.275551,49.3621840000001],[-123.275737,49.3624590000001],[-123.275855,49.3627650000001],[-123.275861,49.363161],[-123.275747,49.36373],[-123.275616,49.3642110000001],[-123.275515,49.3645940000001],[-123.275492,49.3652970000001],[-123.275571,49.365664],[-123.275692,49.365957],[-123.275861,49.3662830000001],[-123.275912,49.3665710000001],[-123.275873,49.366651],[-123.275788,49.366861],[-123.275402,49.3678840000001],[-123.274969,49.36884],[-123.274615,49.3694620000001],[-123.274245,49.369894],[-123.273793,49.3703180000001],[-123.273244,49.370706],[-123.272172,49.3712310000001],[-123.271774,49.3714650000001],[-123.270416,49.37244],[-123.269881,49.372918],[-123.269704,49.373143],[-123.269568,49.373548],[-123.269857,49.374645],[-123.269254,49.3769780000001],[-123.268865,49.37735],[-123.268584,49.3775890000001],[-123.268146,49.3780580000001],[-123.266609,49.3792130000001],[-123.266404,49.3795280000001],[-123.266175,49.38041],[-123.265683,49.381131],[-123.265409,49.3813930000001],[-123.265189,49.381537],[-123.264846,49.3817000000001],[-123.26402,49.381945],[-123.263704,49.3821070000001],[-123.263567,49.3822060000001],[-123.263004,49.382594],[-123.262497,49.3830090000001],[-123.260943,49.3836880000001],[-123.260792,49.383787],[-123.260148,49.38449],[-123.258927,49.3853740000001],[-123.256158,49.3881960000001],[-123.255899,49.388673],[-123.255725,49.3896810000001],[-123.255442,49.3909140000001],[-123.254923,49.3918590000001],[-123.25454,49.392391],[-123.254239,49.392724],[-123.253676,49.393175],[-123.251794,49.3944300000001],[-123.25141,49.3947370000001],[-123.250274,49.3958620000001],[-123.249319,49.3967850000001],[-123.248542,49.3975500000001],[-123.247974,49.398107],[-123.247079,49.399123],[-123.246589,49.3994760000001],[-123.246152,49.399776],[-123.245835,49.4000160000001],[-123.245701,49.4001950000001],[-123.244317,49.40112],[-123.243809,49.401526],[-123.243411,49.4019500000001],[-123.242975,49.4024890000001],[-123.242682,49.4028960000001],[-123.242316,49.403486],[-123.242146,49.403828],[-123.242058,49.404096],[-123.242061,49.4044870000001],[-123.242172,49.405069],[-123.242238,49.405353],[-123.242264,49.4056130000001],[-123.242234,49.4058910000001],[-123.241764,49.4068940000001],[-123.241679,49.407319],[-123.241601,49.407744],[-123.241536,49.408215],[-123.244232,49.408173],[-123.270444999,49.404594],[-123.288034999,49.3848850000001],[-123.29908,49.375297],[-123.292535,49.359316],[-123.278626,49.3433360000001],[-123.277399,49.332682],[-123.262672,49.325225],[-123.23281,49.33428],[-123.200085,49.3308180000001],[-123.168373999,49.3238880000001],[-123.168541,49.3252180000001],[-123.168093,49.327971],[-123.168086,49.3288900000001],[-123.168071,49.3299030000001],[-123.168059999,49.3306890000001],[-123.168061999,49.331625],[-123.168042999,49.3325980000001],[-123.168028,49.333602],[-123.168017,49.3341960000001],[-123.168012,49.3346320000001],[-123.168019999,49.3355250000001],[-123.167994,49.3364250000001],[-123.167985,49.337278],[-123.168019999,49.3382270000001],[-123.168000999,49.338779],[-123.168003999,49.3391280000001],[-123.167997,49.340024],[-123.167974,49.3409340010001],[-123.167980999,49.341038],[-123.16799,49.3418370000001],[-123.167951,49.3419180000001],[-123.167921999,49.3420180000001],[-123.167897,49.3421890000001],[-123.167872,49.342403],[-123.167857,49.34272],[-123.167846999,49.343146],[-123.167832,49.3436790000001],[-123.167825999,49.3439060000001],[-123.167823,49.344071],[-123.169233,49.3439450000001],[-123.170898,49.343805],[-123.172093,49.3437750000001],[-123.173445,49.343779],[-123.174346,49.343826],[-123.174979,49.3438770000001],[-123.175864,49.343965],[-123.176912,49.3441060000001],[-123.177676,49.344212],[-123.178424,49.3442930000001],[-123.178881,49.344322],[-123.180088,49.3443990000001],[-123.180892,49.344454],[-123.183843,49.3446250000001],[-123.184365,49.344663],[-123.184884,49.3447350000001],[-123.185302,49.3448270000001],[-123.18575,49.344954],[-123.186236,49.3451400000001],[-123.186726,49.34536],[-123.186884,49.3454390000001],[-123.186984,49.3455000000001],[-123.187256,49.3456620000001],[-123.188453,49.3463530000001],[-123.18909,49.346664],[-123.189654,49.346906],[-123.190154,49.3470590000001],[-123.190794,49.3471740000001],[-123.191209,49.3472110000001],[-123.191936,49.3472640000001],[-123.19271,49.347311],[-123.193393,49.3473320000001],[-123.194114,49.3473450000001],[-123.194774,49.3473530000001],[-123.195678,49.3473320000001],[-123.196919,49.347296],[-123.198029,49.347223],[-123.201019,49.3469940000001],[-123.208887,49.3462920000001],[-123.210389,49.3461810000001],[-123.211813,49.3461300000001],[-123.212968,49.3461380000001],[-123.214052,49.346168],[-123.215005,49.346215],[-123.216324,49.346303],[-123.218799,49.346456],[-123.219965,49.3465630000001],[-123.222048,49.3468930000001],[-123.226067,49.347905],[-123.227447,49.348235],[-123.228339,49.348419],[-123.23052,49.348756],[-123.231702,49.348895],[-123.232933,49.3490100000001],[-123.233671,49.3490610000001],[-123.234529,49.349071],[-123.235306,49.349052],[-123.236338,49.349022],[-123.237242,49.3489860000001],[-123.238815,49.3489500000001],[-123.240605,49.3490200000001],[-123.241229,49.349116],[-123.242498,49.3494590000001],[-123.243132,49.349697],[-123.24466,49.3503480000001],[-123.245512,49.3506840000001],[-123.246005,49.35085],[-123.246716,49.351028],[-123.247141,49.351096],[-123.248264,49.3511810000001],[-123.249486,49.351251],[-123.250037,49.351275],[-123.251496,49.351575],[-123.252554,49.352064],[-123.253178,49.352445],[-123.253504,49.352742],[-123.25377,49.3530620000001],[-123.253922,49.3534050000001],[-123.254148,49.354139],[-123.253527,49.357174],[-123.253524,49.357559],[-123.25372,49.3581780000001],[-123.253804,49.3583550000001],[-123.25433,49.359093],[-123.254732,49.3594780000001],[-123.255032,49.359722],[-123.255319,49.359922],[-123.255492,49.3600200000001],[-123.256348,49.360347],[-123.257288,49.3606980000001],[-123.258604,49.361204],[-123.259263,49.3614260000001],[-123.260125,49.3616170000001],[-123.260657,49.361722],[-123.262496,49.3619770000001],[-123.263399,49.3620230000001],[-123.263785,49.362019],[-123.265522,49.361878],[-123.267278,49.3616260000001],[-123.268055,49.361477],[-123.270194,49.361094],[-123.271137,49.360977],[-123.27196,49.360958],[-123.273625,49.3610850000001]]]},"properties":{"IAREA_ID":8472}}
]}
bug