计算多边形对象中的地理坐标数

时间:2014-09-17 17:48:43

标签: xml xslt polygon wkt

我有一个XML文件,其中包含POLYGON对象来定义邻域的坐标:

<Quartier><Nom>Quartier 5-1</Nom>
<Superficie>44709524.0</Superficie>
<Perimetre>27807.3</Perimetre>
<Geometrie>POLYGON ((-71.2039023644186 46.9500526726309,-71.2056066189589 46.9517278606582,-71.2065885868913 46.9526930238232,-71.2067160444189 46.9528222050269,-71.2073515179154 46.9534663298479,-71.208529970279 46.954673482819,-71.2087929185864 46.9549437288865,-71.208957190317 46.9551088982664,-71.2091981906366 46.9553514810906,-71.2093005706068 46.9554541680139,-71.2095206011451 46.9556795893972,-71.2097420611575 46.9559066567862,-71.210075659718 46.9562486832074,-71.2102976916311 46.9564759168833,-71.2104100584777 46.9565902898503,-71.2106335817447 46.956817810484,-71.2108571734367 46.9570453932222,-71.2109688763618 46.9571590590553,-71.2111924172813 46.9573865604772,-71.2114157600494 46.9576138377819,-71.2115278643818 46.9577278694094,-71.2117513041143 46.957955307377,-71.2119749314722 46.9581828786769,-71.2120856779145 46.9582953978388,-71.2125873658461 46.9588061021346,-71.2130908456719 46.9593184303379,-71.2131998943966 46.959429402639,-71.2136470291047 46.9598843868516,-71.2140941845576 46.9603393691587,-71.2142088052421 46.9604560003082,-71.2142242658114 46.9604724028474,-71.2145635436786 46.9608320490211,-71.216883912568 46.9632541570492,-71.2227663041303 46.9693932493268,-71.2227688501682 46.9693959141107,-71.2228473074738 46.9694777786684,-71.2228565714774 46.9694874450317,-71.2229284822267 46.9694482175637,-71.2232417469729 46.9692773452847,-71.2234393171502 46.9691695735886,-71.2235550095985 46.9691064631592,-71.2238651784157 46.9689372730154,-71.2243318826606 46.9686826988644,-71.2246574927135 46.9685050784262,-71.2248079230579 46.9684230168484,-71.2253890544074 46.9681507471727,-71.2263606536575 46.9676955260581,-71.22657067869 46.9675971248737,-71.2266763765291 46.9675476049209,-71.2269934686283 46.9673990264902,-71.2273105590877 46.9672504561826,-71.2276276609259 46.9671018849192,-71.2279447477401 46.9669533038716,-71.2285788118161 46.9666562027965,-71.2285997182246 46.9666464078785,-71.2292128688481 46.9663590982337,-71.229846918836 46.9660619901833,-71.2301639934429 46.9659134120266,-71.2306369643586 46.965691778969,-71.2313184109759 46.965372436598,-71.2317473187445 46.9651687578307,-71.2324638546075 46.964828448171,-71.2326657690529 46.9647295658461,-71.2336297600395 46.9642574275552,-71.2339091287398 46.9641205956546,-71.2339624388095 46.9640944978932,-71.2341591915345 46.963998128949,-71.2346107555763 46.9637769584902,-71.2346599128518 46.9637537658211,-71.2349762805609 46.9636044680938,-71.2353222841664 46.96344118803,-71.2357166587087 46.963255087684,-71.2361110305071 46.963068985989,-71.2368998569823 46.9626967149922,-71.237649962423 46.9623427073348,-71.2378606474922 46.9622609239832,-71.2382628018901 46.9621048029016,-71.2385979941655 46.9619746795152,-71.2387851624507 46.9619020063466,-71.238933237859 46.9618445907959,-71.2392685335906 46.9617145817203,-71.2396038275656 46.9615845626736,-71.2397749049469 46.9615182261707,-71.2398135668443 46.9615032316307,-71.2399960670095 46.9614324578415,-71.2402743191411 46.9613245582294,-71.2404318148725 46.9612634813537,-71.240464019779 46.9612509933021,-71.2407246253753 46.9611499358529,-71.2407713379598 46.961131821208,-71.2409447911728 46.9610645589641,-71.2410030313599 46.9610419704935,-71.2415866987709 46.9608156261452,-71.2416222883141 46.9608018293906,-71.2416597432629 46.9607870489545,-71.2418999068578 46.9606922926103,-71.2422129403306 46.9605687884193,-71.2422825437138 46.9605413216739,-71.2428043059616 46.9603354608759,-71.2428385324305 46.9603219604625,-71.2433611920994 46.9601157404418,-71.2435502915105 46.9600411217289,-71.243750446313 46.9599621487068,-71.2439506135374 46.9598831662562,-71.2442436823622 46.9597675319199,-71.2448612581325 46.9595238576465,-71.2451614971876 46.9594053764912,-71.2456620018063 46.95920788146,-71.2461289575038 46.959023620338,-71.2463291046804 46.9589446428371,-71.2465370526788 46.9588625824085,-71.2469339725014 46.9587059520829,-71.2473256890312 46.9585513694826,-71.2478108102229 46.9583599298929,-71.2481598564361 46.9582221850861,-71.2485075679105 46.9580849607186,-71.2488746174263 46.9579401149871,-71.2493073028042 46.9577703779172,-71.2495512368574 46.9576746901525,-71.2495844926018 46.9576615449194,-71.2497279042171 46.9576048925623,-71.2497606517648 46.9575920564758,-71.2503979610397 46.957342447426,-71.2505260339267 46.9572921109571,-71.2511037115254 46.9570650734298,-71.2513102677888 46.95698318435,-71.2517296317818 46.9559956463722,-71.2518817797117 46.9556373727978,-71.2521613048067 46.9554928842786,-71.2527753052918 46.9551755117827,-71.2527802750674 46.9551729421823,-71.2533892852351 46.9548581271094,-71.2536963247109 46.9546994107128,-71.2540033623666 46.9545406934989,-71.2552706643559 46.9538855775516,-71.2556281690127 46.9537501290243,-71.256576901483 46.9533906732293,-71.2579260431943 46.9528794836933,-71.2580069218764 46.9528488380048,-71.2585761695978 46.9525989140387,-71.2588995380342 46.9524569522674,-71.2592228784803 46.9523149897633,-71.2595462303462 46.9521730262654,-71.2599260766436 46.9520062442327,-71.2608331830285 46.9515986657532,-71.2614754400616 46.9513100712509,-71.261939420089 46.9511015833081,-71.2622549967251 46.9509515402976,-71.2625181259701 46.9508264323262,-71.2627449820188 46.9507180194459,-71.2627934586679 46.9506948461474,-71.2632608957366 46.9504715130518,-71.2633752746822 46.9504172950892,-71.263691032538 46.9502676247276,-71.2639947964003 46.9501236471522,-71.2644557370896 46.9499051654625,-71.2649166608791 46.9496866820184,-71.2653776070487 46.9494681875613,-71.2657199605637 46.9493059010283,-71.2658405888893 46.9492517557418,-71.2664829782325 46.9489633839918,-71.2671144222786 46.9486799399009,-71.2674242546702 46.9485408514235,-71.267659604006 46.9484351966212,-71.2683618873177 46.9481199278539,-71.2683760415088 46.9481129867543,-71.2696266401797 46.9474993944303,-71.2696550299277 46.9475343067611,-71.2696841730619 46.9475209673948,-71.2697142822747 46.9475072077009,-71.2699022245657 46.9474244024515,-71.2699516611357 46.9474026320522,-71.2700514986946 46.9473585629228,-71.2701696797515 46.9473065885976,-71.2702117141295 46.9472880615307,-71.2702799363548 46.9471912352488,-71.2707029494015 46.9469916775273,-71.2711643337459 46.9467740023228,-71.2712427010111 46.9467370398228,-71.2715428854639 46.9465954142185,-71.2716254077021 46.9465560124724,-71.2720912502737 46.9463428555411,-71.2725563162949 46.946128937266,-71.2727025937794 46.9460616391033,-71.2730082370464 46.9459210433396,-71.2739515302839 46.9454870899652,-71.274320953495 46.9453171367073,-71.2744435024434 46.9452607562476,-71.2749441745735 46.9450286039449,-71.2768390405656 46.9441499855846,-71.2774619410846 46.9438611353384,-71.2780848348788 46.9435722817285,-71.2783898074652 46.9434308574154,-71.2786947784397 46.943289432296,-71.2790632649647 46.9431185524022,-71.2792705563183 46.9430224205719,-71.2794316956852 46.9429476087216,-71.2796703638417 46.9428368056394,-71.2800668865961 46.9426513196376,-71.2851387461703 46.940278408693,-71.2851414466898 46.9402771486957,-71.284928282797 46.9400635018603,-71.2849254831957 46.9400606782505,-71.2848935440458 46.9400286637828,-71.2848370508396 46.9399720420563,-71.2848342381144 46.9399692185342,-71.2816936784827 46.9368210764974,-71.2814562443163 46.9365830651084,-71.2812458262054 46.9363719564855,-71.277432532117 46.9325459030409,-71.2767237793732 46.9318347041331,-71.2764971279179 46.9316072966525,-71.2739179974931 46.9290194168539,-71.2727878365984 46.9278853125096,-71.2721458418495 46.9272410699036,-71.271661387917 46.9267548962447,-71.2715757033261 46.9266689030002,-71.2709600014088 46.9260521578401,-71.2642493616317 46.9189463925217,-71.2640768784491 46.9187636965839,-71.2632099237849 46.9178455561383,-71.2624063534214 46.9169944677578,-71.2618752571136 46.9164319505373,-71.2621261360447 46.9163148677962,-71.2619460996137 46.9161187334843,-71.2611306246626 46.915230308758,-71.2609817445418 46.9150680885275,-71.2588087480752 46.9127005207831,-71.2566283981412 46.9103247100107,-71.2569088382522 46.9102049422262,-71.2567122848709 46.9100002093315,-71.2536751931141 46.9068366209816,-71.248131100456 46.9010603372841,-71.246155159809 46.8990013200914,-71.2459070260227 46.8990972810579,-71.245672053329 46.8988304980062,-71.2454852473158 46.8986183770329,-71.2450514482421 46.8981257943499,-71.244473371358 46.8975397324513,-71.2432843607762 46.8963225708135,-71.2428248209641 46.8958525114026,-71.242364557276 46.8953817171145,-71.2418420382694 46.8948297641322,-71.2413917212957 46.8942957295293,-71.2393533111146 46.8921210983703,-71.2388642212236 46.8915992960709,-71.2380614938313 46.8906913695125,-71.2382312735934 46.8905792066212,-71.2373903439538 46.8896395217809,-71.2371174412761 46.8893345599711,-71.2356301247825 46.8876724821217,-71.2350441732167 46.8870176366843,-71.2348172207591 46.8870814110361,-71.2339659981352 46.8861540465683,-71.2338865639107 46.8860658883983,-71.2333639718559 46.8854858369979,-71.2333506878837 46.885471033236,-71.2332877320298 46.8854008516228,-71.2332847685282 46.8854019591576,-71.2319718086048 46.8857933432176,-71.2301754006944 46.8862477751586,-71.2284060108658 46.8867112371257,-71.2272661605396 46.8869768668264,-71.2258047173956 46.8873368175377,-71.2245977069832 46.8876120856017,-71.2232167009846 46.8879530246481,-71.2217818545767 46.8882943044775,-71.2206961183411 46.8885872179853,-71.2195566831449 46.8888896889087,-71.2187131748177 46.8891902999096,-71.2180442933285 46.889471340086,-71.2168271873317 46.8900049806153,-71.2151146674969 46.8907170415399,-71.2130942768128 46.8915509693281,-71.211970396765 46.8920193749058,-71.2108605569926 46.8925338241232,-71.2102343802786 46.8929991298762,-71.2096772843122 46.893602420637,-71.2093620714185 46.8941857586601,-71.2090599507427 46.8947413241259,-71.2086128759145 46.8955284955352,-71.2081507576407 46.8961957928496,-71.2076598908487 46.89672482231,-71.2069932705163 46.8971903689364,-71.2061367153534 46.8975371001247,-71.2054802684786 46.8977533964325,-71.2046070868213 46.8978602880898,-71.2036920977759 46.8978566770094,-71.2022376265405 46.89775486432,-71.201442647035 46.8976674544632,-71.2009984384495 46.8976517150757,-71.2004736146808 46.8976457064359,-71.1994522034667 46.897735005325,-71.1988745185592 46.8978031357016,-71.1980145476238 46.8978914360643,-71.1969665696068 46.8980085562657,-71.1961477964215 46.8981611939667,-71.195450455437 46.8983407696842,-71.1951154073369 46.8984443184867,-71.1948344298374 46.8985659894752,-71.1943124562497 46.8987814053786,-71.1937629795619 46.8989508527158,-71.1932132613591 46.8991018295362,-71.1927565287877 46.8991599663533,-71.1923264616009 46.8991994797489,-71.190833692119 46.8992592457419,-71.188519564054 46.8992731872766,-71.1878994856196 46.8991846313225,-71.1868993881233 46.8988399531254,-71.185683564167 46.898459655827,-71.1825762485534 46.8974631136904,-71.1816305037757 46.8971549859946,-71.1806578537621 46.8968470104521,-71.1794155971883 46.8964481723994,-71.1782010221629 46.8969307731546,-71.1764611540998 46.8976562616643,-71.1757938387991 46.8980847007508,-71.1754357004697 46.8984928608017,-71.1751856620661 46.898937293855,-71.1748953527468 46.899391184915,-71.1745641533722 46.8998806084894,-71.1742501316899 46.9002781230372,-71.1737005900316 46.9006718141213,-71.1727094081558 46.9012132352547,-71.1714537015486 46.9017599959838,-71.1700247425252 46.9023114274852,-71.1701230447394 46.9024328863405,-71.1701865802797 46.9025861794886,-71.1702107557169 46.9027281878254,-71.1703091844265 46.9029850124557,-71.1703157465461 46.9030618200608,-71.1703154872998 46.9030620824702,-71.1702714517511 46.9031043438287,-71.1701235164181 46.9033702935888,-71.1700463870111 46.9034744718887,-71.1699585400857 46.9036171178739,-71.1698433192528 46.9038098891664,-71.1697743159103 46.9041176409739,-71.1697653773866 46.9041935496938,-71.1697605386136 46.904255058411,-71.1697608721214 46.90425548828,-71.1697911961075 46.904294687475,-71.1697953051132 46.9042999982134,-71.1698403178999 46.9043582105027,-71.1699159356724 46.9043822738242,-71.1702847239448 46.9044176835062,-71.1705735111207 46.9044164600846,-71.1707108095673 46.904419497168,-71.1712041243853 46.9044473460907,-71.171855918141 46.9046048795462,-71.1722503538451 46.9047470618584,-71.17225474459 46.9047486374083,-71.1723173634719 46.9047712101267,-71.1724112677662 46.9048897420287,-71.1724114361754 46.9048937623652,-71.1724397204886 46.9053774327677,-71.1723517756577 46.9057828346892,-71.1723517209314 46.9057868563357,-71.1723361473836 46.906320776435,-71.1721403862428 46.9067983134806,-71.1720113290784 46.9072293618219,-71.1718807203673 46.9075374583425,-71.1717060660165 46.9079073115022,-71.1714608895691 46.9082182387634,-71.1712621698327 46.9084915046805,-71.1709525248152 46.9093624294007,-71.1709527650439 46.9093659005442,-71.1709661318024 46.9095544375216,-71.170965927055 46.9095548615452,-71.1708951143168 46.9097008268301,-71.1708818968349 46.9097230710398,-71.1708237073498 46.9098013015302,-71.1708178371226 46.9098074353829,-71.1708055928302 46.9098245640128,-71.1707932092716 46.9098357919196,-71.1707599975221 46.9098642707152,-71.1707331714253 46.9098942594428,-71.1707069343144 46.9099251623303,-71.1706849528685 46.9099520459467,-71.1706742419321 46.9099595036104,-71.1706522366671 46.9099844801557,-71.1706249157772 46.9100053315695,-71.1706005793168 46.9100265433372,-71.1705553283423 46.9100580973404,-71.1705291613955 46.910087272496,-71.1705138875053 46.9101014860621,-71.1705069287097 46.9101087598012,-71.1705066428409 46.9101089953779,-71.1704552952602 46.9101432839219,-71.1704079982096 46.9101928963183,-71.1704050912662 46.9101966467835,-71.170396777152 46.9102015624399,-71.170352518478 46.9102358634022,-71.1703372183619 46.9102490335333,-71.1702840336638 46.9102918252126,-71.1702516644932 46.9103215943843,-71.1701971782393 46.9103768804317,-71.1701851130004 46.9103968147738,-71.1701705740266 46.9104110239909,-71.1701325043056 46.9104489770973,-71.1701007803665 46.9104978774624,-71.1700850969966 46.9105213864885,-71.1700838005726 46.9105237510931,-71.170058747796 46.9105401899298,-71.1700234472267 46.9105633459599,-71.1699955246152 46.9106223358265,-71.1699738550166 46.9106469054426,-71.169949382242 46.9106898797838,-71.1699336507272 46.9107137489199,-71.1699288460103 46.9107221795294,-71.169923155745 46.9107301295234,-71.1699072743952 46.9107567253947,-71.1698733717747 46.9107993770564,-71.1698679813214 46.9108219082063,-71.1698547029076 46.9108519613897,-71.1698407290058 46.9108715020306,-71.169827986128 46.9108886964433,-71.1698244825584 46.91089303514,-71.1697967699246 46.91091938535,-71.1697811857997 46.9109361285759,-71.1697583582846 46.9109573403286,-71.1697172455683 46.9110124219526,-71.1697000967974 46.9110384584447,-71.1696732361871 46.911083686757,-71.1696625530844 46.911116594537,-71.169660778665 46.9111195826734,-71.1696356703661 46.9111579455879,-71.1696154464355 46.9112048083671,-71.1696092931048 46.9112156398515,-71.1695833570022 46.9112571112999,-71.1695821706892 46.9112609416423,-71.1695719560896 46.9112713920471,-71.1695557414228 46.9112849542586,-71.169527194714 46.911318146425,-71.169521646522 46.9113238105213,-71.169510615921 46.9113330422036,-71.1694602588036 46.9113784888391,-71.1694286420788 46.9114171146718,-71.1694147799927 46.9114351162469,-71.1694124739747 46.9114375857056,-71.1693908246607 46.9114564514702,-71.1693876800614 46.9114601043396,-71.1693673646181 46.911474338231,-71.1693071908147 46.9115464081027,-71.1693002098478 46.9115561468668,-71.1692909522873 46.9115665016884,-71.169284058101 46.9115737209959,-71.1692457030095 46.9116004661474,-71.1692086356283 46.9116610566231,-71.1692068238263 46.9116631543425,-71.1691603647344 46.9117138408594,-71.1691583379164 46.9117176491212,-71.1691482021612 46.9117270644584,-71.1691473118482 46.9117283111439,-71.1691345210173 46.9117395772325,-71.1691304189799 46.9117443602211,-71.1691052534443 46.9117665750924,-71.1690987259527 46.911774781832,-71.1690774136403 46.9117859357858,-71.1690424027258 46.9118103133038,-71.1690391716246 46.9118122933677,-71.1689531229002 46.9118422589059,-71.1688165173357 46.9120093436098,-71.1688056120481 46.9120212823599,-71.1688004648622 46.9120254237127,-71.1687873906874 46.9120371412292,-71.1687394383178 46.9120775985707,-71.1686814325186 46.9121478292034,-71.1686507509603 46.9121994489237,-71.1686447910606 46.9122110798901,-71.1686461356983 46.9122125834053,-71.1711809136912 46.9150436754305,-71.1729282463448 46.916995065481,-71.175177298067 46.9195063467382,-71.175338936003 46.9196868023696,-71.175867792831 46.9202775046735,-71.1759438726638 46.9203603156206,-71.1766306722906 46.9211292776008,-71.1771507388727 46.9217099410303,-71.1776742261182 46.9222944051959,-71.1789710405518 46.9237422031425,-71.1791481543644 46.9239399332103,-71.1801522321827 46.9250608305544,-71.1808399645179 46.9258285557079,-71.1815016753081 46.926567184827,-71.182697231698 46.9279016861983,-71.1830517816481 46.9282984278121,-71.1838602539016 46.9291289093351,-71.1843313642719 46.9296128346559,-71.1847455705315 46.9300382990885,-71.1853143297505 46.9306225017954,-71.1861607452676 46.9314918911833,-71.1868170066147 46.9321659108131,-71.1871671482058 46.9325255295095,-71.1880297001089 46.9334113969986,-71.1884127033502 46.933804739042,-71.1890671716213 46.934476858126,-71.1898526988243 46.9352835317474,-71.1901875756157 46.9356274446729,-71.1910344816351 46.9364971003046,-71.1918386230682 46.9373228456119,-71.192510081973 46.9380123126259,-71.1932226880642 46.9383735068827,-71.1940227313771 46.9392747395888,-71.1946188754297 46.9399510303156,-71.1950156989765 46.9404153270437,-71.1953970075968 46.9408535466516,-71.1963986964706 46.9420047473603,-71.1990036065962 46.944893430444,-71.2039023644186 46.9500526726309))</Geometrie>
</Quartier>

我试图在XSLT文件中计算多边形对象中有多少个坐标。我在网上看了我怎么能这样做,但是徒劳无功。有谁知道我怎么能这样做?只需一个有用的链接即可。

谢谢你。

2 个答案:

答案 0 :(得分:1)

如果我理解正确,多边形中顶点的数量等于<Geometrie>文本值+ 1内的逗号数,请尝试:

<xsl:variable name="string" select="/Quartier/Geometrie" />
<xsl:value-of select="string-length(translate($string, translate($string, ',', ''), '')) + 1"/>

在您的示例中返回510。

严格来说,坐标的数量是其两倍 - 但我怀疑你的意思是严格的。

答案 1 :(得分:1)

我用过

count(tokenize(/Quartier/Geometrie, ','))

所以例如这里 - http://xslttest.appspot.com/我把

<table xsl:version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><tr><td><xsl:value-of select="count(tokenize(/Quartier/Geometrie, ','))"/></td></tr></table>

作为XSLT和您的XML作为输入。