Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NaN, NaN] as a result of passing "Spain" geometry from TopoJSON #25

Closed
Kamilius opened this issue Feb 9, 2017 · 2 comments
Closed

Comments

@Kamilius
Copy link

Kamilius commented Feb 9, 2017

My task is to calculate center of each given continent/country/state based on topo.json coordinates I have for leaflet.
When I'm calculating this for Canada, US, GB, Sweden or even Italy - everything works great, but when I'm passing "Spain's" coordinates, polylabel returns value of [NaN, NaN].

In which cases polylabel can return this value and what is causing such behavior?

Only thing I've spotted here, is that first and last point is the same. Removing it prior to calculation didn't gave any results.

UPD: This also happens for a few other countries. Looking simply at coordinates is not making any sense for me, as I'm not familiar with polylabel's algorithm and principles yet.

Here is the data I'm trying to calculate center coordinates for:

[[-1.7945079745609398,43.38543254241482],[-1.7485686907125277,43.291246520623524],[-1.6394628915725526,43.25514187893686],[-1.559069144837835,43.284967452504105],[-1.4040240618494515,43.24258374269802],[-1.435607319495233,43.03537449475717],[-1.2748198260257944,43.04636286396616],[-0.9819568914921781,42.95688614326443],[-0.760874087971704,42.945897774055446],[-0.7292908303259189,42.876828024741826],[-0.5627609263754323,42.77322340077141],[-0.3072236599686491,42.83130478087604],[-0.16366339794236495,42.77793270186097],[-0.04020157259976287,42.68531644709953],[0.16939640995861183,42.726130389875756],[0.27563100385806294,42.668049009771124],[0.6431452746453452,42.683746680069675],[0.6575013008479758,42.83758384899546],[0.8125463838363594,42.83130478087604],[0.9216521829763344,42.78421176998039],[1.0680836502431426,42.77636293483111],[1.1341213707752367,42.716711787696624],[1.3178785061688778,42.71357225363692],[1.4298555105493769,42.5958397263978],[1.4068858686251708,42.48595603430796],[1.4470827419925278,42.43415372232275],[1.639453493107748,42.4671188299497],[1.7054912136398421,42.50322347163636],[1.9294452224008403,42.43729325638245],[1.9638996852871493,42.366653740038984],[2.0529070477434423,42.35252583677029],[2.1218159735160604,42.41060721687492],[2.2768610565044476,42.42787465420333],[2.4634893971386127,42.33996770053145],[2.641504122051206,42.3729328081584],[2.934367056584822,42.47025836400941],[3.1812907072700263,42.431014188263035],[3.1726770915484543,42.36351420597927],[3.3191085588152625,42.322700263203046],[3.2616844540047474,42.23950261062074],[3.1525786548647723,42.256770047949146],[3.1209953972189943,42.14060728773988],[3.2128739649158113,42.06839800436656],[3.2358436068400174,41.96636314742599],[3.1927755282321293,41.88787479593324],[3.069313702889527,41.79996784226137],[2.779321973596435,41.646130673335584],[2.4491333709359857,41.53467721421589],[2.2969594931881296,41.46560746490227],[2.1304295892376395,41.30392146082722],[2.0615206634650214,41.274095887259975],[1.538961309689352,41.187758700617955],[1.2173863227504746,41.10456104803564],[1.1858030651046967,41.06217733822956],[0.9905611087489525,41.04020059981159],[0.7149254056584873,40.815723914542346],[0.8728416938873984,40.70740998948236],[0.7838343314311054,40.66188674561656],[0.6000771960374607,40.613223967691056],[0.5483955017080007,40.57241002491483],[0.350282340111729,40.285142658451385],[0.20672207808544485,40.172119432301834],[0.14355556279388182,40.07950317754039],[0.06603302129968824,40.03084039961489],[-0.19524665558814647,39.715317226614054],[-0.3215796861712761,39.515956813822484],[-0.3014812494875976,39.321305702120476],[-0.21534509227182497,39.18159643646339],[-0.209602681790777,39.07799181249297],[-0.12059531933448042,38.950840683074716],[-0.008618314953977801,38.869212797522266],[0.1521691785154573,38.83153838880575],[0.2354341304907024,38.757759338402565],[-0.014360725435029309,38.6243291408649],[-0.0890120616886989,38.53485242016317],[-0.33019330189285157,38.47049197193912],[-0.41345825386809665,38.365317580938836],[-0.5196928477675478,38.299387365684936],[-0.5053368215649172,38.20834087795335],[-0.6087002102238408,38.17851530438611],[-0.6546394940722529,37.99014326080352],[-0.7178060093638159,37.94305024990787],[-0.8527526556685245,37.72328286572819],[-0.7034499831611889,37.61967824175776],[-0.9245327866816666,37.55531779353371],[-1.0680930487079472,37.58200383304124],[-1.1657140268858193,37.54432942432473],[-1.3236303151147304,37.563166628682986],[-1.470061782381542,37.483108510160385],[-1.487289013824693,37.43287596520503],[-1.6710461492183377,37.363806215891415],[-1.8117352060040943,37.20682951290592],[-1.8978713632198634,36.94938772000972],[-2.1275677824619166,36.73589940394945],[-2.20509032395611,36.73746917097931],[-2.3630066121850213,36.83636449386017],[-2.57547579998392,36.811248221382485],[-2.658740751959165,36.69508546117322],[-2.756361730137037,36.68095755790453],[-2.9315052498091028,36.751597074248],[-2.9860581493790903,36.73746917097931],[-3.227239389583243,36.75473660830771],[-3.4138677302174116,36.69508546117322],[-3.6004960708515803,36.74217847206887],[-3.729700306675234,36.724911034740465],[-3.838806105815209,36.751597074248],[-3.9622679311578146,36.72648080177032],[-4.057017704095159,36.746887773158434],[-4.226418813286173,36.71235289850163],[-4.4331455906040205,36.71078313147177],[-4.525024158300845,36.580492467993814],[-4.723137319897113,36.492585514321945],[-4.90402325005023,36.50671341759063],[-4.99590181774705,36.45648087263528],[-5.185401363621747,36.41095762876949],[-5.334704036129079,36.18805071053009],[-5.337575241369606,36.14095769963444],[-5.357673678053285,36.14095769963444],[-5.438067424788002,36.161364671022554],[-5.446681040509581,36.057760047052135],[-5.610339739219544,36.00752750209678],[-5.796968079853709,36.08601585358952],[-5.917558699955787,36.18491117647038],[-6.038149320057865,36.18962047755994],[-6.158739940159943,36.304213470739356],[-6.2190352502109825,36.40310879362021],[-6.2333912764136095,36.57578316690425],[-6.394178769883048,36.637004081068596],[-6.431504438009881,36.751597074248],[-6.359724306996739,36.78613194890481],[-6.500413363782499,36.9603760892187],[-6.744465809227179,37.101655121905644],[-7.02871512803922,37.20525974587606],[-7.413456630269657,37.192701609637226],[-7.4766231455612235,37.494096879369366],[-7.5283048398906836,37.56630616274269],[-7.42494145123176,37.74996890523572],[-7.335934088775463,37.81275958642991],[-7.269896368243376,37.94932931802729],[-7.123464900976565,38.04037580575888],[-7.022972717558169,38.021538601400614],[-6.948321381304499,38.197352508744366],[-7.126336106217092,38.19107344062495],[-7.166532979584449,38.2727013261774],[-7.358903730699669,38.44537569946144],[-7.269896368243376,38.73735236701445],[-7.05455597520395,38.855084894253565],[-7.066040796166053,38.90374767217907],[-6.974162228469233,39.01363136426892],[-7.037328743760796,39.10938715309006],[-7.166532979584449,39.11409645417963],[-7.244055521078643,39.19572433973208],[-7.249797931559694,39.27107315716512],[-7.327320473053888,39.34171267350859],[-7.312964446851261,39.45787543371785],[-7.39910060406703,39.493980075404515],[-7.5168200189285805,39.59287539828537],[-7.557016892295941,39.67921258492739],[-7.341676499256515,39.671363749778116],[-7.034457538520272,39.69020095413638],[-7.002874280874487,39.80322418028593],[-6.925351739380297,39.87229392959955],[-6.8794124555318845,40.008863661196926],[-7.043071154241847,40.181538034480965],[-6.896639686975039,40.25531708488414],[-6.796147503556639,40.355782174794854],[-6.8564428136076785,40.44211936143687],[-6.813374734999794,40.64775884234787],[-6.836344376924,40.84084018702002],[-6.942578970823451,41.01665409436377],[-6.8191171454808455,41.054328503080285],[-6.646844831049307,41.267816819140556],[-6.563579879074062,41.27095635320026],[-6.319527433629382,41.420084221036475],[-6.2046792240083555,41.57078185590255],[-6.365466717477791,41.66339811066399],[-6.554966263352487,41.67438647987297],[-6.577935905276689,41.73874692809702],[-6.523383005706702,41.86746782454513],[-6.655458446770883,41.93339803979903],[-7.051684769963426,41.941246874948305],[-7.143563337660247,41.988339885843956],[-7.249797931559694,41.86432829048542],[-7.588600149941723,41.82508411473904],[-7.723546796246428,41.898863165142224],[-8.047992988425829,41.81723527958977],[-8.18006842949001,41.81095621147035],[-8.23175012381947,41.88630502890339],[-8.108288298476868,42.01031662426192],[-8.191553250452113,42.06211893624713],[-8.220265302857367,42.15316542397872],[-8.346598333440497,42.10136311199351],[-8.625105241771486,42.05113056703815],[-8.751438272354616,41.96950268148569],[-8.877771302937745,41.9067120002915],[-8.897869739621424,42.10293287902336],[-8.843316840051436,42.1641537931877],[-8.757180682835667,42.40746768281521],[-8.866286481975642,42.415316517964484],[-8.823218403367758,42.56915368689027],[-8.903612150102475,42.62566529996504],[-8.969649870634566,42.5785722890694],[-9.070142054052965,42.5958397263978],[-9.029945180685605,42.7072931855175],[-9.11321013266085,42.76537456562213],[-9.141922185066104,42.92235126860762],[-9.225187137041349,42.93961870593603],[-9.251027984206079,43.016537290398915],[-9.216573521319773,43.15467678902615],[-9.05291482260981,43.19706049883223],[-8.969649870634566,43.286537219533955],[-8.843316840051436,43.33833953151917],[-8.6940141675441,43.29281628765338],[-8.507385826909935,43.33049069636989],[-8.444219311618369,43.37601394023569],[-8.214522892376316,43.42467671816119],[-8.33224230723787,43.47176972905684],[-8.309272665313664,43.54554877946002],[-8.085318656552662,43.657002238579715],[-8.059477809387932,43.70880455056493],[-7.775228490575891,43.743339425221734],[-7.542660866093314,43.7307812889829],[-7.3675173464212484,43.68054874402754],[-7.229699494876016,43.56909528490784],[-6.770306656391909,43.56909528490784],[-6.649716036289831,43.58008365411683],[-6.509026979504075,43.54711854648987],[-6.22190645545151,43.59578132441537],[-6.069732577703647,43.56909528490784],[-5.906073878993684,43.587932489266095],[-5.854392184664224,43.66328130669913],[-5.707960717397416,43.56909528490784],[-5.423711398585375,43.56124644975856],[-5.179658953140695,43.48903716638524],[-4.837985529518139,43.44979299063887],[-4.734622140859216,43.41682788301191],[-4.4331455906040205,43.40269997974322],[-4.18909314515934,43.40583951380293],[-3.827321284853106,43.49688600153451],[-3.718215485713131,43.48275809826582],[-3.5545567870031682,43.51729297292263],[-3.3908980882932056,43.42467671816119],[-3.11239117996222,43.35403720181772],[-2.9286340445685752,43.43723485440003],[-2.756361730137037,43.44979299063887],[-2.4835972322870994,43.371304639146125],[-2.368749022666073,43.31479302607134],[-2.098855730056659,43.30380465686236],[-1.7945079745609398,43.38543254241482]]

@Kamilius
Copy link
Author

Kamilius commented Feb 9, 2017

My bad. Seems working, when it is not an "array of arrays", but "array of array of arrays"

@Kamilius Kamilius closed this as completed Feb 9, 2017
@mourner
Copy link
Member

mourner commented Feb 9, 2017

Yes, since input is a polygon with an outer ring and holes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants