Skip to content

Instantly share code, notes, and snippets.

@rveciana
Last active March 6, 2017 13:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rveciana/edb1dd43f3edc5d16ecaf4839c032dec to your computer and use it in GitHub Desktop.
Save rveciana/edb1dd43f3edc5d16ecaf4839c032dec to your computer and use it in GitHub Desktop.
Drawing streamlines from a GeoTIFF file
license: mit

This example shows how to draw streamlines for a vectorial field using d3js and Canvas.

To calculate the streamlines, the raster-streamlines library is used. To calculate the position of the small arrows at the middle of each line, the svg-path-properties library is used too.

The data is the wind from a sample WRF model, reprojected from Lambert Conformal to latlon so it can be drawn.

The wind speed is plotted under the barbs, using the d3-marching-squares library.

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.rastertools=e.rastertools||{})}(this,function(e){"use strict";function t(e,t,o){return(e-t)/(o-t)}function o(e){for(var t=[],o=e.rows,r=e.cols,l=[],h=0;h<o;h++)for(var a=0;a<r;a++)if("undefined"!=typeof e.cells[h][a]&&e.cells[h][a].edges.length>0){var n=e.cells[h][a],f=(n.cval,p(n)),i=null,c=a,b=h;null!==f&&l.push([f.p[0]+c,f.p[1]+b]);do{if(i=u(e.cells[b][c],f.x,f.y,f.o),null===i)break;if(l.push([i.p[0]+c,i.p[1]+b]),c+=i.x,b+=i.y,f=i,b<0||b>=o||c<0||c>=r||"undefined"==typeof e.cells[b][c]){c-=i.x,b-=i.y;var g=s(e,c,b,i.x,i.y,i.o);if(null===g)break;g.path.forEach(function(e){l.push(e)}),c=g.i,b=g.j,f=g}}while("undefined"!=typeof e.cells[b][c]&&e.cells[b][c].edges.length>0);t.push(l),l=[],e.cells[h][a].edges.length>0&&a--}return t}function s(e,t,o,s,r,p){for(var u=e.cells[o][t],l=u.cval_real,h=t+s,a=o+r,n=[],f=(e.rows,e.cols,!1);!f;){if("undefined"==typeof e.cells[a]||"undefined"==typeof e.cells[a][h])if(a-=r,h-=s,u=e.cells[a][h],l=u.cval_real,r===-1)if(0===p)if(l&w)n.push([h,a]),s=-1,r=0,p=0;else{if(!(l&x)){n.push([h+u.bottomright,a]),s=0,r=1,p=1,f=!0;break}n.push([h+1,a]),s=1,r=0,p=0}else{if(!(l&w)){if(l&x){n.push([h+u.bottomright,a]),s=0,r=1,p=1,f=!0;break}n.push([h+u.bottomleft,a]),s=0,r=1,p=0,f=!0;break}n.push([h,a]),s=-1,r=0,p=0}else if(1===r)if(0===p){if(!(l&k)){if(l&v){n.push([h+u.topleft,a+1]),s=0,r=-1,p=0,f=!0;break}n.push([h+u.topright,a+1]),s=0,r=-1,p=1,f=!0;break}n.push([h+1,a+1]),s=1,r=0,p=1}else l&k?(n.push([h+1,a+1]),s=1,r=0,p=1):(n.push([h+1,a+1]),s=1,r=0,p=1);else if(s===-1)if(0===p){if(!(l&v)){if(l&w){n.push([h,a+u.leftbottom]),s=1,r=0,p=0,f=!0;break}n.push([h,a+u.lefttop]),s=1,r=0,p=1,f=!0;break}n.push([h,a+1]),s=0,r=1,p=0}else{if(!(l&v)){console.log("wtf");break}n.push([h,a+1]),s=0,r=1,p=0}else{if(1!==s){console.log("we came from nowhere!");break}if(0===p){if(!(l&x)){n.push([h+1,a+u.rightbottom]),s=-1,r=0,p=0,f=!0;break}n.push([h+1,a]),s=0,r=-1,p=1}else{if(!(l&x)){if(l&k){n.push([h+1,a+u.righttop]),s=-1,r=0,p=1;break}n.push([h+1,a+u.rightbottom]),s=-1,r=0,p=0,f=!0;break}n.push([h+1,a]),s=0,r=-1,p=1}}else if(u=e.cells[a][h],l=u.cval_real,s===-1)if(0===p)if("undefined"!=typeof e.cells[a-1]&&"undefined"!=typeof e.cells[a-1][h])s=0,r=-1,p=1;else{if(!(l&w)){n.push([h+u.bottomright,a]),s=0,r=1,p=1,f=!0;break}n.push([h,a])}else{if(!(l&v)){console.log("found entry from top at "+h+","+a);break}console.log("proceeding in x-direction!")}else if(1===s){if(0===p){console.log("wtf");break}if("undefined"!=typeof e.cells[a+1]&&"undefined"!=typeof e.cells[a+1][h])s=0,r=1,p=0;else{if(!(l&k)){n.push([h+u.topleft,a+1]),s=0,r=-1,p=0,f=!0;break}n.push([h+1,a+1]),s=1,r=0,p=1}}else if(r===-1){if(1!==p){console.log("wtf");break}if("undefined"!=typeof e.cells[a][h+1])s=1,r=0,p=1;else{if(!(l&x)){n.push([h+1,a+u.righttop]),s=-1,r=0,p=1,f=!0;break}n.push([h+1,a]),s=0,r=-1,p=1}}else{if(1!==r){console.log("where did we came from???");break}if(0!==p){console.log("wtf");break}if("undefined"!=typeof e.cells[a][h-1])s=-1,r=0,p=0;else{if(!(l&v)){n.push([h,a+u.leftbottom]),s=1,r=0,p=0,f=!0;break}n.push([h,a+1]),s=0,r=1,p=0}}if(h+=s,a+=r,h===t&&a===o)break}return{path:n,i:h,j:a,x:s,y:r,o:p}}function r(e,t){delete e.edges[t];for(var o=t+1;o<e.edges.length;o++)e.edges[o-1]=e.edges[o];e.edges.pop()}function p(e){if(e.edges.length>0){var t=e.edges[e.edges.length-1],o=e.cval_real;switch(t){case 0:return o&k?{p:[1,e.righttop],x:-1,y:0,o:1}:{p:[e.topleft,1],x:0,y:-1,o:0};case 1:return o&x?{p:[e.topleft,1],x:0,y:-1,o:0}:{p:[1,e.rightbottom],x:-1,y:0,o:0};case 2:return o&x?{p:[e.bottomright,0],x:0,y:1,o:1}:{p:[e.topleft,1],x:0,y:-1,o:0};case 3:return o&w?{p:[e.topleft,1],x:0,y:-1,o:0}:{p:[e.bottomleft,0],x:0,y:1,o:0};case 4:return o&k?{p:[1,e.righttop],x:-1,y:0,o:1}:{p:[e.topright,1],x:0,y:-1,o:1};case 5:return o&x?{p:[e.topright,1],x:0,y:-1,o:1}:{p:[1,e.rightbottom],x:-1,y:0,o:0};case 6:return o&x?{p:[e.bottomright,0],x:0,y:1,o:1}:{p:[e.topright,1],x:0,y:-1,o:1};case 7:return o&w?{p:[e.topright,1],x:0,y:-1,o:1}:{p:[e.bottomleft,0],x:0,y:1,o:0};case 8:return o&x?{p:[e.bottomright],x:0,y:1,o:1}:{p:[1,e.righttop],x:-1,y:0,o:1};case 9:return o&w?{p:[1,e.righttop],x:-1,y:0,o:1}:{p:[e.bottomleft,0],x:0,y:1,o:0};case 10:return o&w?{p:[0,e.leftbottom],x:1,y:0,o:0}:{p:[1,e.righttop],x:-1,y:0,o:1};case 11:return o&v?{p:[1,e.righttop],x:-1,y:0,o:1}:{p:[0,e.lefttop],x:1,y:0,o:1};case 12:return o&x?{p:[e.bottomright,0],x:0,y:1,o:1}:{p:[1,e.rightbottom],x:-1,y:0,o:0};case 13:return o&w?{p:[1,e.rightbottom],x:-1,y:0,o:0}:{p:[e.bottomleft,0],x:0,y:1,o:0};case 14:return o&w?{p:[0,e.leftbottom],x:1,y:0,o:0}:{p:[1,e.rightbottom],x:-1,y:0,o:0};case 15:return o&v?{p:[1,e.rightbottom],x:-1,y:0,o:0}:{p:[0,e.lefttop],x:1,y:0,o:1};case 16:return o&x?{p:[e.bottomright,0],x:0,y:1,o:1}:{p:[0,e.leftbottom],x:1,y:0,o:0};case 17:return o&v?{p:[e.bottomright,0],x:0,y:1,o:1}:{p:[0,e.lefttop],x:1,y:0,o:1};case 18:return o&w?{p:[0,e.leftbottom],x:1,y:0,o:0}:{p:[e.bottomleft,0],x:0,y:1,o:0};case 19:return o&v?{p:[e.bottomleft,0],x:0,y:1,o:0}:{p:[0,e.lefttop],x:1,y:0,o:1};case 20:return o&v?{p:[e.topleft,1],x:0,y:-1,o:0}:{p:[0,e.leftbottom],x:1,y:0,o:0};case 21:return o&k?{p:[0,e.leftbottom],x:1,y:0,o:0}:{p:[e.topright,1],x:0,y:-1,o:1};case 22:return o&v?{p:[e.topleft,1],x:0,y:-1,o:0}:{p:[0,e.lefttop],x:1,y:0,o:1};case 23:return o&k?{p:[0,e.lefttop],x:1,y:0,o:1}:{p:[e.topright,1],x:0,y:-1,o:1};default:console.log("edge index out of range!"),console.log(e)}}return null}function u(e,t,o,s){var p,u,t,o,l,h,a,n=e.cval;switch(t){case-1:switch(s){case 0:p=U[n],l=A[n],h=G[n],a=P[n];break;default:p=R[n],l=F[n],h=O[n],a=I[n]}break;case 1:switch(s){case 0:p=Y[n],l=J[n],h=K[n],a=Q[n];break;default:p=Z[n],l=B[n],h=D[n],a=H[n]}break;default:switch(o){case-1:switch(s){case 0:p=$[n],l=N[n],h=C[n],a=j[n];break;default:p=ee[n],l=_[n],h=E[n],a=M[n]}break;case 1:switch(s){case 0:p=X[n],l=T[n],h=V[n],a=L[n];break;default:p=W[n],l=S[n],h=q[n],a=z[n]}}}if(u=e.edges.indexOf(p),"undefined"==typeof e.edges[u])return null;switch(r(e,u),n=e.cval_real,p){case 0:n&k?(t=e.topleft,o=1):(t=1,o=e.righttop);break;case 1:n&x?(t=1,o=e.rightbottom):(t=e.topleft,o=1);break;case 2:n&x?(t=e.topleft,o=1):(t=e.bottomright,o=0);break;case 3:n&w?(t=e.bottomleft,o=0):(t=e.topleft,o=1);break;case 4:n&k?(t=e.topright,o=1):(t=1,o=e.righttop);break;case 5:n&x?(t=1,o=e.rightbottom):(t=e.topright,o=1);break;case 6:n&x?(t=e.topright,o=1):(t=e.bottomright,o=0);break;case 7:n&w?(t=e.bottomleft,o=0):(t=e.topright,o=1);break;case 8:n&x?(t=1,o=e.righttop):(t=e.bottomright,o=0);break;case 9:n&w?(t=e.bottomleft,o=0):(t=1,o=e.righttop);break;case 10:n&w?(t=1,o=e.righttop):(t=0,o=e.leftbottom);break;case 11:n&v?(t=0,o=e.lefttop):(t=1,o=e.righttop);break;case 12:n&x?(t=1,o=e.rightbottom):(t=e.bottomright,o=0);break;case 13:n&w?(t=e.bottomleft,o=0):(t=1,o=e.rightbottom);break;case 14:n&w?(t=1,o=e.rightbottom):(t=0,o=e.leftbottom);break;case 15:n&v?(t=0,o=e.lefttop):(t=1,o=e.rightbottom);break;case 16:n&x?(t=0,o=e.leftbottom):(t=e.bottomright,o=0);break;case 17:n&v?(t=0,o=e.lefttop):(t=e.bottomright,o=0);break;case 18:n&w?(t=e.bottomleft,o=0):(t=0,o=e.leftbottom);break;case 19:n&v?(t=0,o=e.lefttop):(t=e.bottomleft,o=0);break;case 20:n&v?(t=0,o=e.leftbottom):(t=e.topleft,o=1);break;case 21:n&k?(t=e.topright,o=1):(t=0,o=e.leftbottom);break;case 22:n&v?(t=0,o=e.lefttop):(t=e.topleft,o=1);break;case 23:n&k?(t=e.topright,o=1):(t=0,o=e.lefttop);break;default:return console.log("edge index out of range!"),console.log(e),null}return"undefined"!=typeof t&&"undefined"!=typeof o&&"undefined"!=typeof l&&"undefined"!=typeof h&&"undefined"!=typeof a||(console.log("undefined value!"),console.log(e),console.log(t+" "+o+" "+l+" "+h+" "+a)),{p:[t,o],x:l,y:h,o:a}}function l(e,t,o){return(e-t)/(o-t)}function h(e,t){for(var o=e.length-1,s=e[0].length-1,r={rows:o,cols:s,cells:[]},p=0;p<o;++p){r.cells[p]=[];for(var u=0;u<s;++u){var h=0,a=e[p+1][u],n=e[p+1][u+1],f=e[p][u+1],i=e[p][u];if(!(isNaN(a)||isNaN(n)||isNaN(f)||isNaN(i))){h|=a>=t?8:0,h|=n>=t?4:0,h|=f>=t?2:0,h|=i>=t?1:0;var c=!1;if(5==h||10==h){var b=(a+n+f+i)/4;5==h&&b<t?(h=10,c=!0):10==h&&b<t&&(h=5,c=!0)}if(0!=h&&15!=h){var g,d,y,m;g=d=y=m=.5,1==h?(y=1-l(t,a,i),d=1-l(t,f,i)):2==h?(d=l(t,i,f),m=1-l(t,n,f)):3==h?(y=1-l(t,a,i),m=1-l(t,n,f)):4==h?(g=l(t,a,n),m=l(t,f,n)):5==h?(g=l(t,a,n),m=l(t,f,n),d=1-l(t,f,i),y=1-l(t,a,i)):6==h?(d=l(t,i,f),g=l(t,a,n)):7==h?(y=1-l(t,a,i),g=l(t,a,n)):8==h?(y=l(t,i,a),g=1-l(t,n,a)):9==h?(d=1-l(t,f,i),g=1-l(t,n,a)):10==h?(g=1-l(t,n,a),m=1-l(t,n,f),d=l(t,i,f),y=l(t,i,a)):11==h?(g=1-l(t,n,a),m=1-l(t,n,f)):12==h?(y=l(t,i,a),m=l(t,f,n)):13==h?(d=1-l(t,f,i),m=l(t,f,n)):14==h?(y=l(t,i,a),d=l(t,i,f)):console.log("Illegal cval detected: "+h),r.cells[p][u]={cval:h,flipped:c,top:g,right:m,bottom:d,left:y}}}}}return r}function a(e){return 5==e.cval||10==e.cval}function n(e){return 0==e.cval||15==e.cval}function f(e){n(e)||5==e.cval||10==e.cval||(e.cval=15)}function i(e,t){return"top"===t?[e.top,1]:"bottom"===t?[e.bottom,0]:"right"===t?[1,e.right]:"left"===t?[0,e.left]:void 0}function c(e){var t=[],o=0,s=(e.rows,e.cols,1e-7);return e.cells.forEach(function(r,p){r.forEach(function(r,u){if("undefined"!=typeof r&&!a(r)&&!n(r)){var l=b(e.cells,p,u),h=!1;if("mergeable"==l.info)for(var f=l.path[l.path.length-1][0],i=l.path[l.path.length-1][1],c=o-1;c>=0;c--)if(Math.abs(t[c][0][0]-f)<=s&&Math.abs(t[c][0][1]-i)<=s){for(var g=l.path.length-2;g>=0;--g)t[c].unshift(l.path[g]);h=!0;break}h||(t[o++]=l.path)}})}),t}function b(e,t,o){var s,r,p,u=e.length,l=[],h=[0,0,1,1,0,0,0,0,-1,0,1,1,-1,0,-1,0],a=[0,-1,0,0,1,1,1,1,0,-1,0,0,0,-1,0,0],n=["none","left","bottom","left","right","none","bottom","left","top","top","none","top","right","right","bottom","none"],c=["none","bottom","right","right","top","top","top","top","left","bottom","right","right","left","bottom","left","none"],b=(e[t][o],e[t][o]),g=b.cval,p=n[g],d=i(b,p);l.push([o+d[0],t+d[1]]),p=c[g],d=i(b,p),l.push([o+d[0],t+d[1]]),f(b);for(var y=o+h[g],m=t+a[g],v=g;y>=0&&m>=0&&m<u&&(y!=o||m!=t)&&(b=e[m][y],"undefined"!=typeof b);){if(g=b.cval,0==g||15==g)return{path:l,info:"mergeable"};p=c[g],s=h[g],r=a[g],5!=g&&10!=g||(5==g?b.flipped?a[v]==-1?(p="left",s=-1,r=0):(p="right",s=1,r=0):h[v]==-1&&(p="bottom",s=0,r=-1):10==g&&(b.flipped?h[v]==-1?(p="top",s=0,r=1):(p="bottom",s=0,r=-1):1==a[v]&&(p="left",s=-1,r=0))),d=i(b,p),l.push([y+d[0],m+d[1]]),f(b),y+=s,m+=r,v=g}return{path:l,info:"closed"}}var g=function(e,t,o){for(var s={type:"FeatureCollection",features:[]},r=1;r<o.length;r++){for(var p=o[r-1],u=o[r],l=d(e,t,p,u-p),h=0;h<l.length;h++)l[h].reverse();s.features.push({type:"Feature",geometry:{type:"Polygon",coordinates:l},properties:[{lowerValue:p,upperValue:u}]})}return s},d=function(e,t,o,s){if(typeof t!=typeof new Array||6!=t.length)throw new Error("GeoTransform must be a 6 elements array");for(var r=m(e,o,s),p=0;p<r.length;p++)for(var u=0;u<r[p].length;u++){var l=y(r[p][u][0],r[p][u][1],t);r[p][u][0]=l[0],r[p][u][1]=l[1]}return r},y=function(e,t,o){var s=o[0]+e*o[1]+t*o[2],r=o[3]+e*o[4]+t*o[5];return[s,r]},m=function(e,t,s,r){var p={},u={successCallback:null,progressCallback:null,verbose:!1};r=r?r:{};for(var l=Object.keys(u),h=0;h<l.length;h++){var a=l[h],n=r[a];n="undefined"!=typeof n&&null!==n?n:u[a],p[a]=n}p.verbose&&console.log("computing isobands for ["+t+":"+(t+s)+"]");var f=te(e,t,s);p.verbose&&(p.polygons?console.log("returning single polygons for each grid cell"):console.log("returning polygon paths for entire data grid"));var i=o(f);return"function"==typeof p.successCallback&&p.successCallback(i),i},v=64,k=16,x=4,w=1,N=[],C=[],j=[],_=[],E=[],M=[],F=[],O=[],I=[],A=[],G=[],P=[],T=[],V=[],L=[],S=[],q=[],z=[],B=[],D=[],H=[],J=[],K=[],Q=[];F[85]=A[85]=-1,O[85]=G[85]=0,I[85]=P[85]=1,B[85]=J[85]=1,D[85]=K[85]=0,H[85]=Q[85]=1,N[85]=_[85]=0,C[85]=E[85]=-1,j[85]=L[85]=0,S[85]=T[85]=0,q[85]=V[85]=1,M[85]=z[85]=1,J[1]=J[169]=0,K[1]=K[169]=-1,Q[1]=Q[169]=0,T[1]=T[169]=-1,V[1]=V[169]=0,L[1]=L[169]=0,A[4]=A[166]=0,G[4]=G[166]=-1,P[4]=P[166]=1,S[4]=S[166]=1,q[4]=q[166]=0,z[4]=z[166]=0,F[16]=F[154]=0,O[16]=O[154]=1,I[16]=I[154]=1,_[16]=_[154]=1,E[16]=E[154]=0,M[16]=M[154]=1,B[64]=B[106]=0,D[64]=D[106]=1,H[64]=H[106]=0,N[64]=N[106]=-1,C[64]=C[106]=0,j[64]=j[106]=1,B[2]=B[168]=0,D[2]=D[168]=-1,H[2]=H[168]=1,J[2]=J[168]=0,K[2]=K[168]=-1,Q[2]=Q[168]=0,T[2]=T[168]=-1,V[2]=V[168]=0,L[2]=L[168]=0,S[2]=S[168]=-1,q[2]=q[168]=0,z[2]=z[168]=1,F[8]=F[162]=0,O[8]=O[162]=-1,I[8]=I[162]=0,A[8]=A[162]=0,G[8]=G[162]=-1,P[8]=P[162]=1,T[8]=T[162]=1,V[8]=V[162]=0,L[8]=L[162]=1,S[8]=S[162]=1,q[8]=q[162]=0,z[8]=z[162]=0,F[32]=F[138]=0,O[32]=O[138]=1,I[32]=I[138]=1,A[32]=A[138]=0,G[32]=G[138]=1,P[32]=P[138]=0,N[32]=N[138]=1,C[32]=C[138]=0,j[32]=j[138]=0,_[32]=_[138]=1,E[32]=E[138]=0,M[32]=M[138]=1,J[128]=J[42]=0,K[128]=K[42]=1,Q[128]=Q[42]=1,B[128]=B[42]=0,D[128]=D[42]=1,H[128]=H[42]=0,N[128]=N[42]=-1,C[128]=C[42]=0,j[128]=j[42]=1,_[128]=_[42]=-1,E[128]=E[42]=0,M[128]=M[42]=0,A[5]=A[165]=-1,G[5]=G[165]=0,P[5]=P[165]=0,J[5]=J[165]=1,K[5]=K[165]=0,Q[5]=Q[165]=0,S[20]=S[150]=0,q[20]=q[150]=1,z[20]=z[150]=1,_[20]=_[150]=0,E[20]=E[150]=-1,M[20]=M[150]=1,F[80]=F[90]=-1,O[80]=O[90]=0,I[80]=I[90]=1,B[80]=B[90]=1,D[80]=D[90]=0,H[80]=H[90]=1,T[65]=T[105]=0,V[65]=V[105]=1,L[65]=L[105]=0,N[65]=N[105]=0,C[65]=C[105]=-1,j[65]=j[105]=0,F[160]=F[10]=-1,O[160]=O[10]=0,I[160]=I[10]=1,A[160]=A[10]=-1,G[160]=G[10]=0,P[160]=P[10]=0,J[160]=J[10]=1,K[160]=K[10]=0,Q[160]=Q[10]=0,B[160]=B[10]=1,D[160]=D[10]=0,H[160]=H[10]=1,S[130]=S[40]=0,q[130]=q[40]=1,z[130]=z[40]=1,T[130]=T[40]=0,V[130]=V[40]=1,L[130]=L[40]=0,N[130]=N[40]=0,C[130]=C[40]=-1,j[130]=j[40]=0,_[130]=_[40]=0,E[130]=E[40]=-1,M[130]=M[40]=1,A[37]=A[133]=0,G[37]=G[133]=1,P[37]=P[133]=1,J[37]=J[133]=0,K[37]=K[133]=1,Q[37]=Q[133]=0,N[37]=N[133]=-1,C[37]=C[133]=0,j[37]=j[133]=0,_[37]=_[133]=1,E[37]=E[133]=0,M[37]=M[133]=0,S[148]=S[22]=-1,q[148]=q[22]=0,z[148]=z[22]=0,J[148]=J[22]=0,K[148]=K[22]=-1,Q[148]=Q[22]=1,B[148]=B[22]=0,D[148]=D[22]=1,H[148]=H[22]=1,_[148]=_[22]=-1,E[148]=E[22]=0,M[148]=M[22]=1,F[82]=F[88]=0,O[82]=O[88]=-1,I[82]=I[88]=1,S[82]=S[88]=1,q[82]=q[88]=0,z[82]=z[88]=1,T[82]=T[88]=-1,V[82]=V[88]=0,L[82]=L[88]=1,B[82]=B[88]=0,D[82]=D[88]=-1,H[82]=H[88]=0,F[73]=F[97]=0,O[73]=O[97]=1,I[73]=I[97]=0,A[73]=A[97]=0,G[73]=G[97]=-1,P[73]=P[97]=0,T[73]=T[97]=1,V[73]=V[97]=0,L[73]=L[97]=0,N[73]=N[97]=1,C[73]=C[97]=0,j[73]=j[97]=1,F[145]=F[25]=0,O[145]=O[25]=-1,I[145]=I[25]=0,T[145]=T[25]=1,V[145]=V[25]=0,L[145]=L[25]=1,J[145]=J[25]=0,K[145]=K[25]=1,Q[145]=Q[25]=1,_[145]=_[25]=-1,E[145]=E[25]=0,M[145]=M[25]=0,A[70]=A[100]=0,G[70]=G[100]=1,P[70]=P[100]=0,S[70]=S[100]=-1,q[70]=q[100]=0,z[70]=z[100]=1,B[70]=B[100]=0,D[70]=D[100]=-1;H[70]=H[100]=1;N[70]=N[100]=1,C[70]=C[100]=0,j[70]=j[100]=0,A[101]=A[69]=0,G[101]=G[69]=1,P[101]=P[69]=0,N[101]=N[69]=1,C[101]=C[69]=0,j[101]=j[69]=0,J[149]=J[21]=0,K[149]=K[21]=1,Q[149]=Q[21]=1,_[149]=_[21]=-1,E[149]=E[21]=0,M[149]=M[21]=0,S[86]=S[84]=-1,q[86]=q[84]=0,z[86]=z[84]=1,B[86]=B[84]=0,D[86]=D[84]=-1,H[86]=H[84]=1,F[89]=F[81]=0,O[89]=O[81]=-1,I[89]=I[81]=0,T[89]=T[81]=1,V[89]=V[81]=0,L[89]=L[81]=1,F[96]=F[74]=0,O[96]=O[74]=1,I[96]=I[74]=0,A[96]=A[74]=-1,G[96]=G[74]=0,P[96]=P[74]=1,B[96]=B[74]=1,D[96]=D[74]=0,H[96]=H[74]=0,N[96]=N[74]=1,C[96]=C[74]=0,j[96]=j[74]=1,F[24]=F[146]=0,O[24]=O[146]=-1,I[24]=I[146]=1,S[24]=S[146]=1,q[24]=q[146]=0,z[24]=z[146]=1,T[24]=T[146]=0,V[24]=V[146]=1,L[24]=L[146]=1,_[24]=_[146]=0,E[24]=E[146]=-1,M[24]=M[146]=0,A[6]=A[164]=-1,G[6]=G[164]=0,P[6]=P[164]=1,S[6]=S[164]=-1,q[6]=q[164]=0,z[6]=z[164]=0,J[6]=J[164]=0,K[6]=K[164]=-1,Q[6]=Q[164]=1,B[6]=B[164]=1,D[6]=D[164]=0,H[6]=H[164]=0,T[129]=T[41]=0,V[129]=V[41]=1,L[129]=L[41]=1,J[129]=J[41]=0,K[129]=K[41]=1,Q[129]=Q[41]=0,N[129]=N[41]=-1,C[129]=C[41]=0,j[129]=j[41]=0,_[129]=_[41]=0,E[129]=E[41]=-1,M[129]=M[41]=0,S[66]=S[104]=0,q[66]=q[104]=1,z[66]=z[104]=0,T[66]=T[104]=-1,V[66]=V[104]=0,L[66]=L[104]=1,B[66]=B[104]=0,D[66]=D[104]=-1,H[66]=H[104]=0,N[66]=N[104]=0,C[66]=C[104]=-1,j[66]=j[104]=1,F[144]=F[26]=-1,O[144]=O[26]=0,I[144]=I[26]=0,J[144]=J[26]=1,K[144]=K[26]=0,Q[144]=Q[26]=1,B[144]=B[26]=0,D[144]=D[26]=1,H[144]=H[26]=1,_[144]=_[26]=-1,E[144]=E[26]=0,M[144]=M[26]=1,A[36]=A[134]=0,G[36]=G[134]=1,P[36]=P[134]=1,S[36]=S[134]=0,q[36]=q[134]=1,z[36]=z[134]=0,N[36]=N[134]=0,C[36]=C[134]=-1,j[36]=j[134]=1,_[36]=_[134]=1,E[36]=E[134]=0,M[36]=M[134]=0,F[9]=F[161]=-1,O[9]=O[161]=0,I[9]=I[161]=0,A[9]=A[161]=0,G[9]=G[161]=-1,P[9]=P[161]=0,T[9]=T[161]=1,V[9]=V[161]=0,L[9]=L[161]=0,J[9]=J[161]=1,K[9]=K[161]=0,Q[9]=Q[161]=1,F[136]=0,O[136]=1,I[136]=1,A[136]=0,G[136]=1,P[136]=0,S[136]=-1,q[136]=0,z[136]=1,T[136]=-1,V[136]=0,L[136]=0,J[136]=0,K[136]=-1,Q[136]=0,B[136]=0,D[136]=-1,H[136]=1,N[136]=1,C[136]=0,j[136]=0,_[136]=1,E[136]=0,M[136]=1,F[34]=0,O[34]=-1,I[34]=0,A[34]=0,G[34]=-1,P[34]=1,S[34]=1,q[34]=0,z[34]=0,T[34]=1,V[34]=0,L[34]=1,J[34]=0,K[34]=1,Q[34]=1,B[34]=0,D[34]=1,H[34]=0,N[34]=-1,C[34]=0,j[34]=1,_[34]=-1,E[34]=0,M[34]=0,F[35]=0,O[35]=1,I[35]=1,A[35]=0,G[35]=-1,P[35]=1,S[35]=1,q[35]=0,z[35]=0,T[35]=-1,V[35]=0,L[35]=0,J[35]=0,K[35]=-1,Q[35]=0,B[35]=0,D[35]=1,H[35]=0,N[35]=-1,C[35]=0,j[35]=1,_[35]=1,E[35]=0,M[35]=1,F[153]=0,O[153]=1,I[153]=1,T[153]=-1,V[153]=0;L[153]=0;J[153]=0,K[153]=-1,Q[153]=0,_[153]=1,E[153]=0,M[153]=1,A[102]=0,G[102]=-1,P[102]=1,S[102]=1,q[102]=0,z[102]=0,B[102]=0,D[102]=1,H[102]=0,N[102]=-1,C[102]=0,j[102]=1,F[155]=0,O[155]=-1,I[155]=0,T[155]=1,V[155]=0,L[155]=1,J[155]=0,K[155]=1,Q[155]=1,_[155]=-1,E[155]=0,M[155]=0,A[103]=0,G[103]=1,P[103]=0,S[103]=-1,q[103]=0,z[103]=1,B[103]=0,D[103]=-1,H[103]=1,N[103]=1,C[103]=0,j[103]=0,F[152]=0,O[152]=1,I[152]=1,S[152]=-1,q[152]=0,z[152]=1,T[152]=-1,V[152]=0,L[152]=0,J[152]=0,K[152]=-1,Q[152]=0,B[152]=0,D[152]=-1,H[152]=1,_[152]=1,E[152]=0,M[152]=1,F[156]=0,O[156]=-1,I[156]=1,S[156]=1,q[156]=0,z[156]=1,T[156]=-1,V[156]=0,L[156]=0,J[156]=0,K[156]=-1,Q[156]=0,B[156]=0,D[156]=1,H[156]=1,_[156]=-1,E[156]=0,M[156]=1,F[137]=0,O[137]=1,I[137]=1,A[137]=0,G[137]=1,P[137]=0,T[137]=-1,V[137]=0,L[137]=0,J[137]=0,K[137]=-1,Q[137]=0,N[137]=1,C[137]=0,j[137]=0,_[137]=1,E[137]=0,M[137]=1,F[139]=0,O[139]=1,I[139]=1,A[139]=0,G[139]=-1,P[139]=0,T[139]=1,V[139]=0,L[139]=0,J[139]=0,K[139]=1,Q[139]=0,N[139]=-1,C[139]=0,j[139]=0,_[139]=1,E[139]=0,M[139]=1,F[98]=0,O[98]=-1,I[98]=0,A[98]=0,G[98]=-1,P[98]=1,S[98]=1,q[98]=0,z[98]=0,T[98]=1,V[98]=0,L[98]=1,B[98]=0,D[98]=1,H[98]=0,N[98]=-1,C[98]=0,j[98]=1,F[99]=0,O[99]=1,I[99]=0,A[99]=0,G[99]=-1,P[99]=1,S[99]=1,q[99]=0,z[99]=0,T[99]=-1,V[99]=0,L[99]=1,B[99]=0,D[99]=-1,H[99]=0,N[99]=1,C[99]=0,j[99]=1,A[38]=0,G[38]=-1,P[38]=1,S[38]=1,q[38]=0,z[38]=0,J[38]=0,K[38]=1,Q[38]=1,B[38]=0,D[38]=1,H[38]=0,N[38]=-1,C[38]=0,j[38]=1,_[38]=-1,E[38]=0,M[38]=0,A[39]=0,G[39]=1,P[39]=1,S[39]=-1,q[39]=0,z[39]=0,J[39]=0,K[39]=-1,Q[39]=1,B[39]=0,D[39]=1,H[39]=0,N[39]=-1,C[39]=0,j[39]=1,_[39]=1,E[39]=0,M[39]=0;var R=[],U=[],W=[],X=[],Y=[],Z=[],$=[],ee=[];X[1]=Y[1]=18,X[169]=Y[169]=18,W[4]=U[4]=12,W[166]=U[166]=12,R[16]=ee[16]=4,R[154]=ee[154]=4,Z[64]=$[64]=22,Z[106]=$[106]=22,W[2]=Z[2]=17,X[2]=Y[2]=18,W[168]=Z[168]=17,X[168]=Y[168]=18,R[8]=X[8]=9,U[8]=W[8]=12,R[162]=X[162]=9,U[162]=W[162]=12,R[32]=ee[32]=4,U[32]=$[32]=1,R[138]=ee[138]=4,U[138]=$[138]=1,Y[128]=ee[128]=21,Z[128]=$[128]=22,Y[42]=ee[42]=21,Z[42]=$[42]=22,U[5]=Y[5]=14,U[165]=Y[165]=14,W[20]=ee[20]=6,W[150]=ee[150]=6,R[80]=Z[80]=11,R[90]=Z[90]=11,X[65]=$[65]=3,X[105]=$[105]=3,R[160]=Z[160]=11,U[160]=Y[160]=14,R[10]=Z[10]=11,U[10]=Y[10]=14,W[130]=ee[130]=6,X[130]=$[130]=3,W[40]=ee[40]=6,X[40]=$[40]=3,U[101]=$[101]=1,U[69]=$[69]=1,Y[149]=ee[149]=21,Y[21]=ee[21]=21,W[86]=Z[86]=17,W[84]=Z[84]=17,R[89]=X[89]=9,R[81]=X[81]=9,R[96]=$[96]=0,U[96]=Z[96]=15,R[74]=$[74]=0,U[74]=Z[74]=15,R[24]=W[24]=8,X[24]=ee[24]=7,R[146]=W[146]=8,X[146]=ee[146]=7,U[6]=Z[6]=15,W[6]=Y[6]=16,U[164]=Z[164]=15,W[164]=Y[164]=16,X[129]=ee[129]=7,Y[129]=$[129]=20,X[41]=ee[41]=7,Y[41]=$[41]=20,W[66]=$[66]=2,X[66]=Z[66]=19,W[104]=$[104]=2,X[104]=Z[104]=19,R[144]=Y[144]=10,Z[144]=ee[144]=23,R[26]=Y[26]=10,Z[26]=ee[26]=23,U[36]=ee[36]=5,W[36]=$[36]=2,U[134]=ee[134]=5,W[134]=$[134]=2,R[9]=Y[9]=10,U[9]=X[9]=13,R[161]=Y[161]=10,U[161]=X[161]=13,U[37]=ee[37]=5,Y[37]=$[37]=20,U[133]=ee[133]=5,Y[133]=$[133]=20,W[148]=Y[148]=16,Z[148]=ee[148]=23,W[22]=Y[22]=16,Z[22]=ee[22]=23,R[82]=W[82]=8,X[82]=Z[82]=19,R[88]=W[88]=8,X[88]=Z[88]=19,R[73]=$[73]=0,U[73]=X[73]=13,R[97]=$[97]=0,U[97]=X[97]=13,R[145]=X[145]=9,Y[145]=ee[145]=21,R[25]=X[25]=9,Y[25]=ee[25]=21,U[70]=$[70]=1,W[70]=Z[70]=17,U[100]=$[100]=1,W[100]=Z[100]=17,R[34]=X[34]=9,U[34]=W[34]=12,Y[34]=ee[34]=21,Z[34]=$[34]=22,R[136]=ee[136]=4,U[136]=$[136]=1,W[136]=Z[136]=17,X[136]=Y[136]=18,R[35]=ee[35]=4,U[35]=W[35]=12,X[35]=Y[35]=18,Z[35]=$[35]=22,R[153]=ee[153]=4,X[153]=Y[153]=18,U[102]=W[102]=12,Z[102]=$[102]=22,R[155]=X[155]=9,Y[155]=ee[155]=23,U[103]=$[103]=1,W[103]=Z[103]=17,R[152]=ee[152]=4,W[152]=Z[152]=17,X[152]=Y[152]=18,R[156]=W[156]=8,X[156]=Y[156]=18,Z[156]=ee[156]=23,R[137]=ee[137]=4,U[137]=$[137]=1,X[137]=Y[137]=18,R[139]=ee[139]=4,U[139]=X[139]=13,Y[139]=$[139]=20,R[98]=X[98]=9,U[98]=W[98]=12,Z[98]=$[98]=22,R[99]=$[99]=0,U[99]=W[99]=12,X[99]=Z[99]=19,U[38]=W[38]=12,Y[38]=ee[38]=21,Z[38]=$[38]=22,U[39]=ee[39]=5,W[39]=Y[39]=16,Z[39]=$[39]=22;var te=function(e,o,s){for(var r=e.length-1,p=e[0].length-1,u={rows:r,cols:p,cells:[]},l=o+Math.abs(s),h=0;h<r;++h){u.cells[h]=[];for(var a=0;a<p;++a){var n=0,f=e[h+1][a],i=e[h+1][a+1],c=e[h][a+1],b=e[h][a];if(!(isNaN(f)||isNaN(i)||isNaN(c)||isNaN(b))){n|=f<o?0:f>l?128:64,n|=i<o?0:i>l?32:16,n|=c<o?0:c>l?8:4,n|=b<o?0:b>l?2:1;var g=+n,d=0;if(17==n||18==n||33==n||34==n||38==n||68==n||72==n||98==n||102==n||132==n||136==n||137==n||152==n||153==n){var y=(f+i+c+b)/4;d=y>l?2:y<o?0:1,34===n?1===d?n=35:0===d&&(n=136):136===n?1===d?(n=35,d=4):0===d&&(n=34):17===n?1===d?(n=155,d=4):0===d&&(n=153):68===n?1===d?(n=103,d=4):0===d&&(n=102):153===n?1===d&&(n=155):102===n?1===d&&(n=103):152===n?d<2&&(n=156,d=1):137===n?d<2&&(n=139,d=1):98===n?d<2&&(n=99,d=1):38===n?d<2&&(n=39,d=1):18===n?d>0?(n=156,d=4):n=152:33===n?d>0?(n=139,d=4):n=137:72===n?d>0?(n=99,d=4):n=98:132===n&&(d>0?(n=39,d=4):n=38)}if(0!=n&&170!=n){var m,v,k,x,w,N,C,j;m=v=k=x=w=N=C=j=.5;var _=[];1===n?(k=1-t(o,c,b),j=1-t(o,f,b),_.push(X[n])):169===n?(k=t(l,b,c),j=t(l,b,f),_.push(X[n])):4===n?(N=1-t(o,i,c),x=t(o,b,c),_.push(U[n])):166===n?(N=t(l,c,i),x=1-t(l,c,b),_.push(U[n])):16===n?(w=t(o,c,i),v=t(o,f,i),_.push(R[n])):154===n?(w=1-t(l,i,c),v=1-t(l,i,f),_.push(R[n])):64===n?(C=t(o,b,f),m=1-t(o,i,f),_.push(Z[n])):106===n?(C=1-t(l,f,b),m=t(l,f,i),_.push(Z[n])):168===n?(x=t(l,b,c),k=t(o,b,c),j=t(o,b,f),C=t(l,b,f),_.push(W[n]),_.push(X[n])):2===n?(x=1-t(o,c,b),k=1-t(l,c,b),j=1-t(l,f,b),C=1-t(o,f,b),_.push(W[n]),_.push(X[n])):162===n?(w=t(l,c,i),N=t(o,c,i),x=1-t(o,c,b),k=1-t(l,c,b),_.push(W[n]),_.push(X[n])):8===n?(w=1-t(o,i,c),N=1-t(l,i,c),x=t(l,b,c),k=t(o,b,c),_.push(R[n]),_.push(U[n])):138===n?(w=1-t(o,i,c),N=1-t(l,i,c),m=1-t(l,i,f),v=1-t(o,i,f),_.push(R[n]),_.push(U[n])):32===n?(w=t(l,c,i),N=t(o,c,i),m=t(o,f,i),v=t(l,f,i),_.push(R[n]),_.push(U[n])):42===n?(j=1-t(l,f,b),C=1-t(o,f,b),m=t(o,f,i),v=t(l,f,i),_.push(Y[n]),_.push(Z[n])):128===n&&(j=t(o,b,f),C=t(l,b,f),m=1-t(l,i,f),v=1-t(o,i,f),_.push(Y[n]),_.push(Z[n])),5===n?(N=1-t(o,i,c),j=1-t(o,f,b),_.push(U[n])):165===n?(N=t(l,c,i),j=t(l,b,f),_.push(U[n])):20===n?(x=t(o,b,c),v=t(o,f,i),_.push(W[n])):150===n?(x=1-t(l,c,b),v=1-t(l,i,f),_.push(W[n])):80===n?(w=t(o,c,i),C=t(o,b,f),_.push(R[n])):90===n?(w=1-t(l,i,c),C=1-t(l,f,b),_.push(R[n])):65===n?(k=1-t(o,c,b),m=1-t(o,i,f),_.push(X[n])):105===n?(k=t(l,b,c),m=t(l,f,i),_.push(X[n])):160===n?(w=t(l,c,i),N=t(o,c,i),j=t(o,b,f),C=t(l,b,f),_.push(R[n]),_.push(U[n])):10===n?(w=1-t(o,i,c),N=1-t(l,i,c),j=1-t(l,f,b),C=1-t(o,f,b),_.push(R[n]),_.push(U[n])):130===n?(x=1-t(o,c,b),k=1-t(l,c,b),m=1-t(l,i,f),v=1-t(o,i,f),_.push(W[n]),_.push(X[n])):40===n?(x=t(l,b,c),k=t(o,b,c),m=t(o,f,i),v=t(l,f,i),_.push(W[n]),_.push(X[n])):101===n?(N=t(l,c,i),m=t(l,f,i),_.push(U[n])):69===n?(N=1-t(o,i,c),m=1-t(o,i,f),_.push(U[n])):149===n?(j=t(l,b,f),v=1-t(l,i,f),_.push(Y[n])):21===n?(j=1-t(o,f,b),v=t(o,f,i),_.push(Y[n])):86===n?(x=1-t(l,c,b),C=1-t(l,f,b),_.push(W[n])):84===n?(x=t(o,b,c),C=t(o,b,f),_.push(W[n])):89===n?(w=1-t(l,i,c),k=t(l,b,c),_.push(X[n])):81===n?(w=t(o,c,i),k=1-t(o,c,b),_.push(X[n])):96===n?(w=t(l,c,i),N=t(o,c,i),C=t(o,b,f),m=t(l,f,i),_.push(R[n]),_.push(U[n])):74===n?(w=1-t(o,i,c),N=1-t(l,i,c),C=1-t(l,f,b),m=1-t(o,i,f),_.push(R[n]),_.push(U[n])):24===n?(w=1-t(l,i,c),x=t(l,b,c),k=t(o,b,c),v=t(o,f,i),_.push(R[n]),_.push(X[n])):146===n?(w=t(o,c,i),x=1-t(o,c,b),k=1-t(l,c,b),v=1-t(l,i,f),_.push(R[n]),_.push(X[n])):6===n?(N=1-t(o,i,c),x=1-t(l,c,b),j=1-t(l,f,b),C=1-t(o,f,b),_.push(U[n]),_.push(W[n])):164===n?(N=t(l,c,i),x=t(o,b,c),j=t(o,b,f),C=t(l,b,f),_.push(U[n]),_.push(W[n])):129===n?(k=1-t(o,c,b),j=t(l,b,f),m=1-t(l,i,f),v=1-t(o,i,f),_.push(X[n]),_.push(Y[n])):41===n?(k=t(l,b,c),j=1-t(o,f,b),m=t(o,f,i),v=t(l,f,i),_.push(X[n]),_.push(Y[n])):66===n?(x=1-t(o,c,b),k=1-t(l,c,b),C=1-t(l,f,b),m=1-t(o,i,f),_.push(W[n]),_.push(X[n])):104===n?(x=t(l,b,c),k=t(o,b,c),C=t(o,b,f),m=t(l,f,i),_.push(X[n]),_.push($[n])):144===n?(w=t(o,c,i),j=t(o,b,f),C=t(l,b,f),v=1-t(l,i,f),_.push(R[n]),_.push(Z[n])):26===n?(w=1-t(l,i,c),j=1-t(l,f,b),C=1-t(o,f,b),v=t(o,f,i),_.push(R[n]),_.push(Z[n])):36===n?(N=t(l,c,i),x=t(o,b,c),m=t(o,f,i),v=t(l,f,i),_.push(U[n]),_.push(W[n])):134===n?(N=1-t(o,i,c),x=1-t(l,c,b),m=1-t(l,i,f),v=1-t(o,i,f),_.push(U[n]),_.push(W[n])):9===n?(w=1-t(o,i,c),N=1-t(l,i,c),k=t(l,b,c),j=1-t(o,f,b),_.push(R[n]),_.push(U[n])):161===n?(w=t(l,c,i),N=t(o,c,i),k=1-t(o,c,b),j=t(l,b,f),_.push(R[n]),_.push(U[n])):37===n?(N=t(l,c,i),j=1-t(o,f,b),m=t(o,f,i),v=t(l,f,i),_.push(U[n]),_.push(Y[n])):133===n?(N=1-t(o,i,c),j=t(l,b,f),m=1-t(l,i,f),v=1-t(o,i,f),_.push(U[n]),_.push(Y[n])):148===n?(x=t(o,b,c),j=t(o,b,f),C=t(l,b,f),v=1-t(l,i,f),_.push(W[n]),_.push(Z[n])):22===n?(x=1-t(l,c,b),j=1-t(l,f,b),C=1-t(o,f,b),v=t(o,f,i),_.push(W[n]),_.push(Z[n])):82===n?(w=t(o,c,i),x=1-t(o,c,b),k=1-t(l,c,b),C=1-t(l,f,b),_.push(R[n]),_.push(X[n])):88===n?(w=1-t(l,i,c),x=t(l,b,c),k=t(o,b,c),C=t(o,b,f),_.push(R[n]),_.push(X[n])):73===n?(w=1-t(o,i,c),N=1-t(l,i,c),k=t(l,b,c),m=1-t(o,i,f),_.push(R[n]),_.push(U[n])):97===n?(w=t(l,c,i),N=t(o,c,i),k=1-t(o,c,b),m=t(l,f,i),_.push(R[n]),_.push(U[n])):145===n?(w=t(o,c,i),k=1-t(o,c,b),j=t(l,b,f),v=1-t(l,i,f),_.push(R[n]),_.push(Y[n])):25===n?(w=1-t(l,i,c),k=t(l,b,c),j=1-t(o,f,b),v=t(o,f,i),_.push(R[n]),_.push(Y[n])):70===n?(N=1-t(o,i,c),x=1-t(l,c,b),C=1-t(l,f,b),m=1-t(o,i,f),_.push(U[n]),_.push(W[n])):100===n?(N=t(l,c,i),x=t(o,b,c),C=t(o,b,f),m=t(l,f,i),_.push(U[n]),_.push(W[n])):34===n?(0===d?(w=1-t(o,i,c),N=1-t(l,i,c),x=t(l,b,c),k=t(o,b,c),j=t(o,b,f),C=t(l,b,f),m=1-t(l,i,f),v=1-t(o,i,f)):(w=t(l,c,i),N=t(o,c,i),x=1-t(o,c,b),k=1-t(l,c,b),j=1-t(l,f,b),C=1-t(o,f,b),m=t(o,f,i),v=t(l,f,i)),_.push(R[n]),_.push(U[n]),_.push(Y[n]),_.push(Z[n])):35===n?(4===d?(w=1-t(o,i,c),N=1-t(l,i,c),x=t(l,b,c),k=t(o,b,c),j=t(o,b,f),C=t(l,b,f),m=1-t(l,i,f),v=1-t(o,i,f)):(w=t(l,c,i),N=t(o,c,i),x=1-t(o,c,b),k=1-t(l,c,b),j=1-t(l,f,b),C=1-t(o,f,b),m=t(o,f,i),v=t(l,f,i)),_.push(R[n]),_.push(U[n]),_.push(X[n]),_.push(Z[n])):136===n?(0===d?(w=t(l,c,i),N=t(o,c,i),x=1-t(o,c,b),k=1-t(l,c,b),j=1-t(l,f,b),C=1-t(o,f,b),m=t(o,f,i),v=t(l,f,i)):(w=1-t(o,i,c),N=1-t(l,i,c),x=t(l,b,c),k=t(o,b,c),j=t(o,b,f),C=t(l,b,f),m=1-t(l,i,f),v=1-t(o,i,f)),_.push(R[n]),_.push(U[n]),_.push(Y[n]),_.push(Z[n])):153===n?(0===d?(w=t(o,c,i),k=1-t(o,c,b),j=1-t(o,f,b),v=t(o,f,i)):(w=1-t(l,i,c),k=t(l,b,c),j=t(l,b,f),v=1-t(l,i,f)),_.push(R[n]),_.push(X[n])):102===n?(0===d?(N=1-t(o,i,c),x=t(o,b,c),C=t(o,b,f),m=1-t(o,i,f)):(N=t(l,c,i),x=1-t(l,c,b),C=1-t(l,f,b),m=t(l,f,i)),_.push(U[n]),_.push(Z[n])):155===n?(4===d?(w=t(o,c,i),k=1-t(o,c,b),j=1-t(o,f,b),v=t(o,f,i)):(w=1-t(l,i,c),k=t(l,b,c),j=t(l,b,f),v=1-t(l,i,f)),_.push(R[n]),_.push(Y[n])):103===n?(4===d?(N=1-t(o,i,c),x=t(o,b,c),C=t(o,b,f),m=1-t(o,i,f)):(N=t(l,c,i),x=1-t(l,c,b),C=1-t(l,f,b),m=t(l,f,i)),_.push(U[n]),_.push(W[n])):152===n?(0===d?(w=t(o,c,i),x=1-t(o,c,b),k=1-t(l,c,b),j=1-t(l,f,b),C=1-t(o,f,b),v=t(o,f,i)):(w=1-t(l,i,c),x=t(l,b,c),k=t(o,b,c),j=t(o,b,f),C=t(l,b,f),v=1-t(l,i,f)),_.push(R[n]),_.push(W[n]),_.push(X[n])):156===n?(4===d?(w=t(o,c,i),x=1-t(o,c,b),k=1-t(l,c,b),j=1-t(l,f,b),C=1-t(o,f,b),v=t(o,f,i)):(w=1-t(l,i,c),x=t(l,b,c),k=t(o,b,c),j=t(o,b,f),C=t(l,b,f),v=1-t(l,i,f)),_.push(R[n]),_.push(X[n]),_.push(Z[n])):137===n?(0===d?(w=t(l,c,i),N=t(o,c,i),k=1-t(o,c,b),j=1-t(o,f,b),m=t(o,f,i),v=t(l,f,i)):(w=1-t(o,i,c),N=1-t(l,i,c),k=t(l,b,c),j=t(l,b,f),m=1-t(l,i,f),v=1-t(o,i,f)),_.push(R[n]),_.push(U[n]),_.push(X[n])):139===n?(4===d?(w=t(l,c,i),N=t(o,c,i),k=1-t(o,c,b),j=1-t(o,f,b),m=t(o,f,i),v=t(l,f,i)):(w=1-t(o,i,c),N=1-t(l,i,c),k=t(l,b,c),j=t(l,b,f),m=1-t(l,i,f),v=1-t(o,i,f)),_.push(R[n]),_.push(U[n]),_.push(Y[n])):98===n?(0===d?(w=1-t(o,i,c),N=1-t(l,i,c),x=t(l,b,c),k=t(o,b,c),C=t(o,b,f),m=1-t(o,i,f)):(w=t(l,c,i),N=t(o,c,i),x=1-t(o,c,b),k=1-t(l,c,b),C=1-t(l,f,b),m=t(l,f,i)),_.push(R[n]),_.push(U[n]),_.push(Z[n])):99===n?(4===d?(w=1-t(o,i,c),N=1-t(l,i,c),x=t(l,b,c),k=t(o,b,c),C=t(o,b,f),m=1-t(o,i,f)):(w=t(l,c,i),N=t(o,c,i),x=1-t(o,c,b),k=1-t(l,c,b),C=1-t(l,f,b),m=t(l,f,i)),_.push(R[n]),_.push(U[n]),_.push(X[n])):38===n?(0===d?(N=1-t(o,i,c),x=t(o,b,c),j=t(o,b,f),C=t(l,b,f),m=1-t(l,i,f),v=1-t(o,i,f)):(N=t(l,c,i),x=1-t(l,c,b),j=1-t(l,f,b),C=1-t(o,f,b),m=t(o,f,i),v=t(l,f,i)),_.push(U[n]),_.push(Y[n]),_.push(Z[n])):39===n?(4===d?(N=1-t(o,i,c),x=t(o,b,c),j=t(o,b,f),C=t(l,b,f),m=1-t(l,i,f),v=1-t(o,i,f)):(N=t(l,c,i),x=1-t(l,c,b),j=1-t(l,f,b),C=1-t(o,f,b),m=t(o,f,i),v=t(l,f,i)),_.push(U[n]),_.push(W[n]),_.push(Z[n])):85===n&&(w=1,N=0,x=1,k=0,j=0,C=1,m=0,v=1),(m<0||m>1||v<0||v>1||w<0||w>1||x<0||x>1||j<0||j>1||C<0||C>1)&&console.log(n+" "+g+" "+f+","+i+","+c+","+b+" "+d+" "+m+" "+v+" "+w+" "+N+" "+x+" "+k+" "+j+" "+C),u.cells[h][a]={cval:n,cval_real:g,flipped:d,topleft:m,topright:v,righttop:w,rightbottom:N,bottomright:x,bottomleft:k,leftbottom:j,lefttop:C,edges:_}}}}}return u},oe=function(e,t,o){for(var s={type:"FeatureCollection",features:[]},r=0;r<o.length;r++){var p=o[r],u=se(e,t,p);s.features.push({type:"Feature",geometry:{type:"MultiLineString",coordinates:u},properties:[{value:p}]})}return s},se=function(e,t,o){if(typeof t!=typeof new Array||6!=t.length)throw new Error("GeoTransform must be a 6 elements array");for(var s=pe(e,o),r=0;r<s.length;r++)for(var p=0;p<s[r].length;p++){var u=re(s[r][p][0],s[r][p][1],t);s[r][p][0]=u[0],s[r][p][1]=u[1]}return s},re=function(e,t,o){var s=o[0]+e*o[1]+t*o[2],r=o[3]+e*o[4]+t*o[5];return[s,r]},pe=function(e,t,o){var s={successCallback:null,progressCallback:null,verbose:!1},r={};o=o?o:{};for(var p=Object.keys(s),u=0;u<p.length;u++){var l=p[u],a=o[l];a="undefined"!=typeof a&&null!==a?a:s[l],r[l]=a}r.verbose&&console.log("computing isocontour for "+t);var n=c(h(e,t));return"function"==typeof r.successCallback&&r.successCallback(n),n};e.isoband=m,e.projectedIsoband=d,e.isobands=g,e.isoline=pe,e.projectedIsoline=se,e.isolines=oe,Object.defineProperty(e,"__esModule",{value:!0})});
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){"use strict";function d(){}d.prototype={isAsync:function(){return"undefined"==typeof this.decodeBlock}},b.exports=d},{}],2:[function(a,b,c){"use strict";function d(){}var e=a("../abstractdecoder.js");d.prototype=Object.create(e.prototype),d.prototype.constructor=d,d.prototype.decodeBlockAsync=function(a,b){throw new Error("DeflateDecoder is not yet implemented.")},b.exports=d},{"../abstractdecoder.js":1}],3:[function(a,b,c){"use strict";function d(){}var e=a("../abstractdecoder.js");d.prototype=Object.create(e.prototype),d.prototype.constructor=d,d.prototype.decodeBlock=function(a){throw new Error("LZWDecoder is not yet implemented")},b.exports=d},{"../abstractdecoder.js":1}],4:[function(a,b,c){"use strict";function d(){}var e=a("../abstractdecoder.js");d.prototype=Object.create(e.prototype),d.prototype.constructor=d,d.prototype.decodeBlock=function(a){var b,c,d=new DataView(a),e=[];for(b=0;b<a.byteLength;++b){var f=d.getInt8(b);if(0>f){var g=d.getUint8(b+1);for(f=-f,c=0;f>=c;++c)e.push(g);b+=1}else{for(c=0;f>=c;++c)e.push(d.getUint8(b+c+1));b+=f+1}}return new Uint8Array(e).buffer},b.exports=d},{"../abstractdecoder.js":1}],5:[function(a,b,c){"use strict";function d(){}var e=a("../abstractdecoder.js");d.prototype=Object.create(e.prototype),d.prototype.constructor=d,d.prototype.decodeBlock=function(a){return a},b.exports=d},{"../abstractdecoder.js":1}],6:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),f=function(){function a(b){d(this,a),this._dataView=new DataView(b)}return e(a,[{key:"getUint64",value:function(a,b){var c=this.getUint32(a,b),d=this.getUint32(a+4,b);return b?c<<32|d:d<<32|c}},{key:"getInt64",value:function(a,b){var c,d;return b?(c=this.getInt32(a,b),d=this.getUint32(a+4,b),c<<32|d):(c=this.getUint32(a,b),d=this.getInt32(a+4,b),d<<32|c)}},{key:"getUint8",value:function(a,b){return this._dataView.getUint8(a,b)}},{key:"getInt8",value:function(a,b){return this._dataView.getInt8(a,b)}},{key:"getUint16",value:function(a,b){return this._dataView.getUint16(a,b)}},{key:"getInt16",value:function(a,b){return this._dataView.getInt16(a,b)}},{key:"getUint32",value:function(a,b){return this._dataView.getUint32(a,b)}},{key:"getInt32",value:function(a,b){return this._dataView.getInt32(a,b)}},{key:"getFloat32",value:function(a,b){return this._dataView.getFloat32(a,b)}},{key:"getFloat64",value:function(a,b){return this._dataView.getFloat64(a,b)}},{key:"buffer",get:function(){return this._dataView.buffer}}]),a}();b.exports=f},{}],7:[function(a,b,c){"use strict";function d(a,b){this.dataView=new g(a),b=b||{},this.cache=b.cache||!1;var c=this.dataView.getUint16(0,0);if(18761===c)this.littleEndian=!0;else{if(19789!==c)throw new TypeError("Invalid byte order value.");this.littleEndian=!1}var d=this.dataView.getUint16(2,this.littleEndian);if(42===this.dataView.getUint16(2,this.littleEndian))this.bigTiff=!1;else{if(43!==d)throw new TypeError("Invalid magic number.");this.bigTiff=!0;var e=this.dataView.getUint16(4,this.littleEndian);if(8!==e)throw new Error("Unsupported offset byte-size.")}this.fileDirectories=this.parseFileDirectories(this.getOffset(this.bigTiff?8:4))}var e=a("./globals.js"),f=a("./geotiffimage.js"),g=a("./dataview64.js"),h=e.fieldTypes,i=e.fieldTagNames,j=e.arrayFields,k=e.geoKeyNames;d.prototype={getOffset:function(a){return this.bigTiff?this.dataView.getUint64(a,this.littleEndian):this.dataView.getUint32(a,this.littleEndian)},getFieldTypeLength:function(a){switch(a){case h.BYTE:case h.ASCII:case h.SBYTE:case h.UNDEFINED:return 1;case h.SHORT:case h.SSHORT:return 2;case h.LONG:case h.SLONG:case h.FLOAT:return 4;case h.RATIONAL:case h.SRATIONAL:case h.DOUBLE:case h.LONG8:case h.SLONG8:case h.IFD8:return 8;default:throw new RangeError("Invalid field type: "+a)}},getValues:function(a,b,c){var d,e=null,f=null,g=this.getFieldTypeLength(a);switch(a){case h.BYTE:case h.ASCII:case h.UNDEFINED:e=new Uint8Array(b),f=this.dataView.getUint8;break;case h.SBYTE:e=new Int8Array(b),f=this.dataView.getInt8;break;case h.SHORT:e=new Uint16Array(b),f=this.dataView.getUint16;break;case h.SSHORT:e=new Int16Array(b),f=this.dataView.getInt16;break;case h.LONG:e=new Uint32Array(b),f=this.dataView.getUint32;break;case h.SLONG:e=new Int32Array(b),f=this.dataView.getInt32;break;case h.LONG8:case h.IFD8:e=new Array(b),f=this.dataView.getUint64;break;case h.SLONG8:e=new Array(b),f=this.dataView.getInt64;break;case h.RATIONAL:e=new Uint32Array(2*b),f=this.dataView.getUint32;break;case h.SRATIONAL:e=new Int32Array(2*b),f=this.dataView.getInt32;break;case h.FLOAT:e=new Float32Array(b),f=this.dataView.getFloat32;break;case h.DOUBLE:e=new Float64Array(b),f=this.dataView.getFloat64;break;default:throw new RangeError("Invalid field type: "+a)}if(a!==h.RATIONAL&&a!==h.SRATIONAL)for(d=0;b>d;++d)e[d]=f.call(this.dataView,c+d*g,this.littleEndian);else for(d=0;2*b>d;d+=2)e[d]=f.call(this.dataView,c+d*g,this.littleEndian),e[d+1]=f.call(this.dataView,c+(d+1)*g,this.littleEndian);return a===h.ASCII?String.fromCharCode.apply(null,e):e},getFieldValues:function(a,b,c,d){var e,f=this.getFieldTypeLength(b);if(f*c<=(this.bigTiff?8:4))e=this.getValues(b,c,d);else{var g=this.getOffset(d);e=this.getValues(b,c,g)}return 1===c&&-1===j.indexOf(a)&&b!==h.RATIONAL&&b!==h.SRATIONAL?e[0]:e},parseGeoKeyDirectory:function(a){var b=a.GeoKeyDirectory;if(!b)return null;for(var c={},d=4;d<4*b[3];d+=4){var e=k[b[d]],f=b[d+1]?i[b[d+1]]:null,g=b[d+2],h=b[d+3],j=null;if(f){if(j=a[f],"undefined"==typeof j||null===j)throw new Error("Could not get value of geoKey '"+e+"'.");"string"==typeof j?j=j.substring(h,h+g-1):j.subarray&&(j=j.subarray(h,h+g-1))}else j=h;c[e]=j}return c},parseFileDirectories:function(a){for(var b=a,c=[];0!==b;){for(var d=this.bigTiff?this.dataView.getUint64(b,this.littleEndian):this.dataView.getUint16(b,this.littleEndian),e={},f=a+(this.bigTiff?8:2),g=0;d>g;f+=this.bigTiff?20:12,++g){var h=this.dataView.getUint16(f,this.littleEndian),j=this.dataView.getUint16(f+2,this.littleEndian),k=this.bigTiff?this.dataView.getUint64(f+4,this.littleEndian):this.dataView.getUint32(f+4,this.littleEndian);e[i[h]]=this.getFieldValues(h,j,k,f+(this.bigTiff?12:8))}c.push([e,this.parseGeoKeyDirectory(e)]),b=this.getOffset(f)}return c},getImage:function(a){a=a||0;var b=this.fileDirectories[a];if(!b)throw new RangeError("Invalid image index");return new f(b[0],b[1],this.dataView,this.littleEndian,this.cache)},getImageCount:function(){return this.fileDirectories.length}},b.exports=d},{"./dataview64.js":6,"./geotiffimage.js":8,"./globals.js":9}],8:[function(a,b,c){"use strict";function d(a,b,c,d,e){this.fileDirectory=a,this.geoKeys=b,this.dataView=c,this.littleEndian=d,this.tiles=e?{}:null,this.isTiled=a.StripOffsets?!1:!0;var j=a.PlanarConfiguration;if(this.planarConfiguration="undefined"==typeof j?1:j,1!==this.planarConfiguration&&2!==this.planarConfiguration)throw new Error("Invalid planar configuration.");switch(this.fileDirectory.Compression){case void 0:case 1:this.decoder=new f;break;case 5:this.decoder=new g;break;case 6:throw new Error("JPEG compression not supported.");case 8:this.decoder=new h;break;case 32773:this.decoder=new i;break;default:throw new Error("Unknown compresseion method identifier: "+this.fileDirectory.Compression)}}var e=a("./globals.js"),f=a("./compression/raw.js"),g=a("./compression/lzw.js"),h=a("./compression/deflate.js"),i=a("./compression/packbits.js"),j=function(a,b,c){for(var d=0,e=b;c>e;++e)d+=a[e];return d},k=function(a,b,c){switch(a){case 1:switch(b){case 8:return new Uint8Array(c);case 16:return new Uint16Array(c);case 32:return new Uint32Array(c)}break;case 2:switch(b){case 8:return new Int8Array(c);case 16:return new Int16Array(c);case 32:return new Int32Array(c)}break;case 3:switch(b){case 32:return new Float32Array(c);case 64:return new Float64Array(c)}}throw Error("Unsupported data format/bitsPerSample")};d.prototype={getFileDirectory:function(){return this.fileDirectory},getGeoKeys:function(){return this.geoKeys},getWidth:function(){return this.fileDirectory.ImageWidth},getHeight:function(){return this.fileDirectory.ImageLength},getSamplesPerPixel:function(){return this.fileDirectory.SamplesPerPixel},getTileWidth:function(){return this.isTiled?this.fileDirectory.TileWidth:this.getWidth()},getTileHeight:function(){return this.isTiled?this.fileDirectory.TileLength:this.fileDirectory.RowsPerStrip},getBytesPerPixel:function(){for(var a=0,b=0;b<this.fileDirectory.BitsPerSample.length;++b){var c=this.fileDirectory.BitsPerSample[b];if(c%8!==0)throw new Error("Sample bit-width of "+c+" is not supported.");if(c!==this.fileDirectory.BitsPerSample[0])throw new Error("Differing size of samples in a pixel are not supported.");a+=c}return a/8},getSampleByteSize:function(a){if(a>=this.fileDirectory.BitsPerSample.length)throw new RangeError("Sample index "+a+" is out of range.");var b=this.fileDirectory.BitsPerSample[a];if(b%8!==0)throw new Error("Sample bit-width of "+b+" is not supported.");return b/8},getReaderForSample:function(a){var b=this.fileDirectory.SampleFormat?this.fileDirectory.SampleFormat[a]:1,c=this.fileDirectory.BitsPerSample[a];switch(b){case 1:switch(c){case 8:return DataView.prototype.getUint8;case 16:return DataView.prototype.getUint16;case 32:return DataView.prototype.getUint32}break;case 2:switch(c){case 8:return DataView.prototype.getInt8;case 16:return DataView.prototype.getInt16;case 32:return DataView.prototype.getInt32}break;case 3:switch(c){case 32:return DataView.prototype.getFloat32;case 64:return DataView.prototype.getFloat64}}},getArrayForSample:function(a,b){var c=this.fileDirectory.SampleFormat?this.fileDirectory.SampleFormat[a]:1,d=this.fileDirectory.BitsPerSample[a];return k(c,d,b)},getDecoder:function(){return this.decoder},getTileOrStrip:function(a,b,c,d){var e,f=Math.ceil(this.getWidth()/this.getTileWidth()),g=Math.ceil(this.getHeight()/this.getTileHeight()),h=this.tiles;if(1===this.planarConfiguration?e=b*f+a:2===this.planarConfiguration&&(e=c*f*g+b*f+a),null!==h&&e in h)return d?d(null,{x:a,y:b,sample:c,data:h[e]}):h[e];var i,j;this.isTiled?(i=this.fileDirectory.TileOffsets[e],j=this.fileDirectory.TileByteCounts[e]):(i=this.fileDirectory.StripOffsets[e],j=this.fileDirectory.StripByteCounts[e]);var k=this.dataView.buffer.slice(i,i+j);if(d)return this.getDecoder().decodeBlockAsync(k,function(f,g){f||null===h||(h[e]=g),d(f,{x:a,y:b,sample:c,data:g})});var l=this.getDecoder().decodeBlock(k);return null!==h&&(h[e]=l),l},_readRasterAsync:function(a,b,c,d,e,f){function g(e,f){if(e)x=e;else for(var g=new DataView(f.data),j=f.y*k,l=f.x*i,m=(f.y+1)*k,n=(f.x+1)*i,o=(f.sample,Math.max(0,a[1]-j));o<Math.min(k,k-(m-a[3]));++o)for(var t=Math.max(0,a[0]-l);t<Math.min(i,i-(n-a[2]));++t){var u,y=(o*i+t)*q,z=s[C].call(g,y+r[C],w);d?(u=(o+j-a[1])*p*b.length+(t+l-a[0])*b.length+C,c[u]=z):(u=(o+j-a[1])*p+t+l-a[0],c[C][u]=z)}v-=1,h()}function h(){u&&0===v&&(x?f(x):e(c))}for(var i=this.getTileWidth(),k=this.getTileHeight(),l=Math.floor(a[0]/i),m=Math.ceil(a[2]/i),n=Math.floor(a[1]/k),o=Math.ceil(a[3]/k),p=(Math.ceil(this.getWidth()/i),a[2]-a[0]),q=(a[3]-a[1],this.getBytesPerPixel()),r=(this.getWidth(),[]),s=[],t=0;t<b.length;++t)1===this.planarConfiguration?r.push(j(this.fileDirectory.BitsPerSample,0,b[t])/8):r.push(0),s.push(this.getReaderForSample(b[t]));for(var u=!1,v=0,w=this.littleEndian,x=null,y=n;o>=y;++y)for(var z=l;m>=z;++z)for(var A=0;A<b.length;++A){var B=b[A];2===this.planarConfiguration&&(q=this.getSampleByteSize(B));var C=A;v+=1,this.getTileOrStrip(z,y,B,g)}u=!0,h()},_readRaster:function(a,b,c,d,e,f){try{for(var g=this.getTileWidth(),h=this.getTileHeight(),i=Math.floor(a[0]/g),k=Math.ceil(a[2]/g),l=Math.floor(a[1]/h),m=Math.ceil(a[3]/h),n=(Math.ceil(this.getWidth()/g),a[2]-a[0]),o=(a[3]-a[1],this.getBytesPerPixel()),p=(this.getWidth(),[]),q=[],r=0;r<b.length;++r)1===this.planarConfiguration?p.push(j(this.fileDirectory.BitsPerSample,0,b[r])/8):p.push(0),q.push(this.getReaderForSample(b[r]));for(var s=l;m>s;++s)for(var t=i;k>t;++t)for(var u=s*h,v=t*g,w=(s+1)*h,x=(t+1)*g,y=0;y<b.length;++y){var z=b[y];2===this.planarConfiguration&&(o=this.getSampleByteSize(z));for(var A=new DataView(this.getTileOrStrip(t,s,z)),B=Math.max(0,a[1]-u);B<Math.min(h,h-(w-a[3]));++B)for(var C=Math.max(0,a[0]-v);C<Math.min(g,g-(x-a[2]));++C){var D,E=(B*g+C)*o,F=q[y].call(A,E+p[y],this.littleEndian);d?(D=(B+u-a[1])*n*b.length+(C+v-a[0])*b.length+y,c[D]=F):(D=(B+u-a[1])*n+C+v-a[0],c[y][D]=F)}}return e(c),c}catch(G){return f(G)}},readRasters:function(){var a,b,c;switch(arguments.length){case 0:break;case 1:"function"==typeof arguments[0]?b=arguments[0]:a=arguments[0];break;case 2:"function"==typeof arguments[0]?(b=arguments[0],c=arguments[1]):(a=arguments[0],b=arguments[1]);break;case 3:a=arguments[0],b=arguments[1],c=arguments[2];break;default:throw new Error("Invalid number of arguments passed.")}a=a||{},c=c||function(a){console.error(a)};var d=a.window||[0,0,this.getWidth(),this.getHeight()],e=a.samples,f=a.interleave;if(d[0]<0||d[1]<0||d[2]>this.getWidth()||d[3]>this.getHeight())throw new Error("Select window is out of image bounds.");if(d[0]>d[2]||d[1]>d[3])throw new Error("Invalid subsets");var g,h=d[2]-d[0],i=d[3]-d[1],j=h*i;if(e){for(g=0;g<e.length;++g)if(e[g]>=this.fileDirectory.SamplesPerPixel)throw new RangeError("Invalid sample index '"+e[g]+"'.")}else for(e=[],g=0;g<this.fileDirectory.SamplesPerPixel;++g)e.push(g);var l;if(f){var m=this.fileDirectory.SampleFormat?Math.max.apply(null,this.fileDirectory.SampleFormat):1,n=Math.max.apply(null,this.fileDirectory.BitsPerSample);l=k(m,n,j*e.length)}else for(l=[],g=0;g<e.length;++g)l.push(this.getArrayForSample(e[g],j));var o=this.getDecoder();if(o.isAsync()){if(!b)throw new Error("No callback specified for asynchronous raster reading.");return this._readRasterAsync(d,e,l,f,b,c)}return b=b||function(){},this._readRaster(d,e,l,f,b,c)},getTiePoints:function(){if(!this.fileDirectory.ModelTiepoint)return[];for(var a=[],b=0;b<this.fileDirectory.ModelTiepoint.length;b+=6)a.push({i:this.fileDirectory.ModelTiepoint[b],j:this.fileDirectory.ModelTiepoint[b+1],k:this.fileDirectory.ModelTiepoint[b+2],x:this.fileDirectory.ModelTiepoint[b+3],y:this.fileDirectory.ModelTiepoint[b+4],z:this.fileDirectory.ModelTiepoint[b+5]});return a},getGDALMetadata:function(){var a={};if(!this.fileDirectory.GDAL_METADATA)return null;for(var b=this.fileDirectory.GDAL_METADATA,c=e.parseXml(b.substring(0,b.length-1)),d=c.evaluate("GDALMetadata/Item",c,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null),f=0;f<d.snapshotLength;++f){var g=d.snapshotItem(f);a[g.getAttribute("name")]=g.textContent}return a}},b.exports=d},{"./compression/deflate.js":2,"./compression/lzw.js":3,"./compression/packbits.js":4,"./compression/raw.js":5,"./globals.js":9}],9:[function(a,b,c){"use strict";var d,e={315:"Artist",258:"BitsPerSample",265:"CellLength",264:"CellWidth",320:"ColorMap",259:"Compression",33432:"Copyright",306:"DateTime",338:"ExtraSamples",266:"FillOrder",289:"FreeByteCounts",288:"FreeOffsets",291:"GrayResponseCurve",290:"GrayResponseUnit",316:"HostComputer",270:"ImageDescription",257:"ImageLength",256:"ImageWidth",271:"Make",281:"MaxSampleValue",280:"MinSampleValue",272:"Model",254:"NewSubfileType",274:"Orientation",262:"PhotometricInterpretation",284:"PlanarConfiguration",296:"ResolutionUnit",278:"RowsPerStrip",277:"SamplesPerPixel",305:"Software",279:"StripByteCounts",273:"StripOffsets",255:"SubfileType",263:"Threshholding",282:"XResolution",283:"YResolution",326:"BadFaxLines",327:"CleanFaxData",343:"ClipPath",328:"ConsecutiveBadFaxLines",433:"Decode",434:"DefaultImageColor",269:"DocumentName",336:"DotRange",321:"HalftoneHints",346:"Indexed",347:"JPEGTables",285:"PageName",297:"PageNumber",317:"Predictor",319:"PrimaryChromaticities",532:"ReferenceBlackWhite",339:"SampleFormat",340:"SMinSampleValue",341:"SMaxSampleValue",559:"StripRowCounts",330:"SubIFDs",292:"T4Options",293:"T6Options",325:"TileByteCounts",323:"TileLength",324:"TileOffsets",322:"TileWidth",301:"TransferFunction",318:"WhitePoint",344:"XClipPathUnits",286:"XPosition",529:"YCbCrCoefficients",531:"YCbCrPositioning",530:"YCbCrSubSampling",345:"YClipPathUnits",287:"YPosition",37378:"ApertureValue",40961:"ColorSpace",36868:"DateTimeDigitized",36867:"DateTimeOriginal",34665:"Exif IFD",36864:"ExifVersion",33434:"ExposureTime",41728:"FileSource",37385:"Flash",40960:"FlashpixVersion",33437:"FNumber",42016:"ImageUniqueID",37384:"LightSource",37500:"MakerNote",37377:"ShutterSpeedValue",37510:"UserComment",33723:"IPTC",34675:"ICC Profile",700:"XMP",42112:"GDAL_METADATA",42113:"GDAL_NODATA",34377:"Photoshop",33550:"ModelPixelScale",33922:"ModelTiepoint",34264:"ModelTransformation",34735:"GeoKeyDirectory",34736:"GeoDoubleParams",34737:"GeoAsciiParams"},f={};for(d in e)f[e[d]]=parseInt(d);var g=[f.BitsPerSample,f.ExtraSamples,f.SampleFormat,f.StripByteCounts,f.StripOffsets,f.StripRowCounts,f.TileByteCounts,f.TileOffsets],h={1:"BYTE",2:"ASCII",3:"SHORT",4:"LONG",5:"RATIONAL",6:"SBYTE",7:"UNDEFINED",8:"SSHORT",9:"SLONG",10:"SRATIONAL",11:"FLOAT",12:"DOUBLE",16:"LONG8",17:"SLONG8",18:"IFD8"},i={};for(d in h)i[h[d]]=parseInt(d);var j={1024:"GTModelTypeGeoKey",1025:"GTRasterTypeGeoKey",1026:"GTCitationGeoKey",2048:"GeographicTypeGeoKey",2049:"GeogCitationGeoKey",2050:"GeogGeodeticDatumGeoKey",2051:"GeogPrimeMeridianGeoKey",2052:"GeogLinearUnitsGeoKey",2053:"GeogLinearUnitSizeGeoKey",2054:"GeogAngularUnitsGeoKey",2055:"GeogAngularUnitSizeGeoKey",2056:"GeogEllipsoidGeoKey",2057:"GeogSemiMajorAxisGeoKey",2058:"GeogSemiMinorAxisGeoKey",2059:"GeogInvFlatteningGeoKey",2060:"GeogAzimuthUnitsGeoKey",2061:"GeogPrimeMeridianLongGeoKey",2062:"GeogTOWGS84GeoKey",3072:"ProjectedCSTypeGeoKey",3073:"PCSCitationGeoKey",3074:"ProjectionGeoKey",3075:"ProjCoordTransGeoKey",3076:"ProjLinearUnitsGeoKey",3077:"ProjLinearUnitSizeGeoKey",3078:"ProjStdParallel1GeoKey",3079:"ProjStdParallel2GeoKey",3080:"ProjNatOriginLongGeoKey",3081:"ProjNatOriginLatGeoKey",3082:"ProjFalseEastingGeoKey",3083:"ProjFalseNorthingGeoKey",3084:"ProjFalseOriginLongGeoKey",3085:"ProjFalseOriginLatGeoKey",3086:"ProjFalseOriginEastingGeoKey",3087:"ProjFalseOriginNorthingGeoKey",3088:"ProjCenterLongGeoKey",3089:"ProjCenterLatGeoKey",3090:"ProjCenterEastingGeoKey",3091:"ProjCenterNorthingGeoKey",3092:"ProjScaleAtNatOriginGeoKey",3093:"ProjScaleAtCenterGeoKey",3094:"ProjAzimuthAngleGeoKey",3095:"ProjStraightVertPoleLongGeoKey",3096:"ProjRectifiedGridAngleGeoKey",4096:"VerticalCSTypeGeoKey",4097:"VerticalCitationGeoKey",4098:"VerticalDatumGeoKey",4099:"VerticalUnitsGeoKey"},k={};for(d in j)k[j[d]]=parseInt(d);var l;"undefined"==typeof window?l=function(b){var c=a("xmldom").DOMParser;return(new c).parseFromString(b,"text/xml")}:"undefined"!=typeof window.DOMParser?l=function(a){return(new window.DOMParser).parseFromString(a,"text/xml")}:"undefined"!=typeof window.ActiveXObject&&new window.ActiveXObject("Microsoft.XMLDOM")&&(l=function(a){var b=new window.ActiveXObject("Microsoft.XMLDOM");return b.async="false",b.loadXML(a),b}),b.exports={fieldTags:f,fieldTagNames:e,arrayFields:g,fieldTypes:i,fieldTypeNames:h,geoKeys:k,geoKeyNames:j,parseXml:l}},{xmldom:"xmldom"}],10:[function(a,b,c){"use strict";var d=a("./geotiff.js"),e=function(a,b){var c,e,f,g;if("string"==typeof a||a instanceof String)for(c=new ArrayBuffer(2*a.length),g=new Uint16Array(c),e=0,f=a.length;f>e;++e)g[e]=a.charCodeAt(e);else{if(!(a instanceof ArrayBuffer))throw new Error("Invalid input data given.");c=a}return new d(c,b)};"undefined"!=typeof b&&"undefined"!=typeof b.exports&&(b.exports.parse=e),"undefined"!=typeof window&&(window.GeoTIFF={parse:e})},{"./geotiff.js":7}]},{},[10]);
<!DOCTYPE html>
<meta charset="utf-8">
<style>
#tooltip {
position: absolute;
top: 0;
left: 0;
z-index: 10;
margin: 0;
padding: 10px;
width: 180px;
height: 50px;
color: white;
font-family: sans-serif;
font-size: 0.9em;
font-weight: bold;
text-align: center;
background-color: rgba(0, 0, 0, 0.55);
opacity: 0;
pointer-events: none;
border-radius:5px;
transition: .2s;
}
</style>
<body>
<div id="tooltip">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="geotiff.min.js"></script>
<script src="d3-marching-squares.min.js"></script>
<script src="raster-streamlines.js"></script>
<script src="path-properties.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>
<script>
var width = 680,
height = 500,
barbSize = 40;
var projection = d3.geoConicConformal()
.rotate([82, 0])
.center([0, 34.83158])
.parallels([30, 60])
.scale(2300)
.translate([width / 2, height / 2]);
var canvas = d3.select("body").append("canvas")
.attr("width", width)
.attr("height", height);
var context = canvas.node().getContext("2d");
d3.request("wrf.tiff")
.responseType('arraybuffer')
.get(function(error, tiffData){
d3.json("world-110m.json", function(error, topojsonData) {
var countries = topojson.feature(topojsonData, topojsonData.objects.countries);
var path = d3.geoPath()
.projection(projection).context(context);
var path2 = d3.geoPath()
.projection(projection);
context.beginPath();
context.strokeStyle = "#777";
context.fillStyle = "#aaa";
path(countries);
context.fill();
context.stroke();
var tiff = GeoTIFF.parse(tiffData.response);
var image = tiff.getImage();
var rasters = image.readRasters();
var tiepoint = image.getTiePoints()[0];
var pixelScale = image.getFileDirectory().ModelPixelScale;
var geoTransform = [tiepoint.x, pixelScale[0], 0, tiepoint.y, 0, -1*pixelScale[1]];
var uData = new Array(image.getHeight());
var vData = new Array(image.getHeight());
var spdData = new Array(image.getHeight());
for (var j = 0; j<image.getHeight(); j++){
uData[j] = new Array(image.getWidth());
vData[j] = new Array(image.getWidth());
spdData[j] = new Array(image.getWidth());
for (var i = 0; i<image.getWidth(); i++){
uData[j][i] = rasters[0][i + j*image.getWidth()];
vData[j][i] = rasters[1][i + j*image.getWidth()];
spdData[j][i] = 1.943844492 * Math.sqrt(uData[j][i]*uData[j][i] + vData[j][i]*vData[j][i]);
}
}
var intervalsSpd = [0, 5, 10, 15, 20, 25, 30, 35, 40];
var bandsSpd = rastertools.isobands(spdData, geoTransform, intervalsSpd);
var colorScale = d3.scaleSequential(d3.interpolateBuPu);
bandsSpd.features.forEach(function(d, i) {
context.beginPath();
context.globalAlpha = 0.7;
context.fillStyle = colorScale(intervalsSpd[i]/40);
path(d);
context.fill();
});
var lines = rs.streamlines(uData,vData, geoTransform);
lines.features.forEach(function(d) {
var properties = spp.svgPathProperties(path2(d));
var arrowPos = properties.getPropertiesAtLength(properties.getTotalLength()/2);
var arrowDegrees = Math.atan(arrowPos.tangentY/arrowPos.tangentX);
context.beginPath();
context.strokeStyle = "#000000";
path(d);
context.stroke();
context.beginPath();
context.moveTo(arrowPos.x, arrowPos.y);
context.lineTo(arrowPos.x-10*arrowPos.tangentX + 6*arrowPos.tangentY,arrowPos.y-10*arrowPos.tangentY - 6*arrowPos.tangentX);
context.moveTo(arrowPos.x, arrowPos.y);
context.lineTo(arrowPos.x-10*arrowPos.tangentX - 6*arrowPos.tangentY,arrowPos.y-10*arrowPos.tangentY + 6*arrowPos.tangentX);
context.stroke();
});
canvas.on("click", function() {
var screenCoords = d3.mouse(this);
var coords = projection.invert(screenCoords);
var xTiff = (coords[0] - geoTransform[0])/geoTransform[1];
var yTiff = (coords[1] - geoTransform[3])/geoTransform[5];
var uValue = uData[Math.round(yTiff)][Math.round(xTiff)];
var vValue = vData[Math.round(yTiff)][Math.round(xTiff)];
var spd = Math.sqrt(uValue*uValue + vValue*vValue);
var dir = 270 + (Math.atan2(-vValue,uValue)*180/Math.PI);
if(dir<0){dir = dir + 360;}
d3.select("#tooltip")
.style("left", screenCoords[0] + "px")
.style("top", screenCoords[1] + "px")
.style("opacity", 1)
.html("Wind speed: " + spd.toFixed(1) + " m/s <br/>Wind dir: " + dir.toFixed(0) +"º");
});
});
});
</script>
</body>
// http://geoexamples.com/path-properties/ Version 0.1.1. Copyright 2016 Roger Veciana i Rovira.
!function(t,h){"object"==typeof exports&&"undefined"!=typeof module?h(exports):"function"==typeof define&&define.amd?define(["exports"],h):h(t.spp=t.spp||{})}(this,function(t){"use strict";function h(t){var h=t.match(l);return h?h.map(Number):[]}function n(t,h,n,s,u,g,c,x){this.a={x:t,y:h},this.b={x:n,y:s},this.c={x:u,y:g},this.d={x:c,y:x},c&&x?(this.getArcLength=y,this.getPoint=a,this.getDerivative=e):(this.getArcLength=o,this.getPoint=r,this.getDerivative=i),this.init()}function i(t,h,n){return{x:2*(1-n)*(t[1]-t[0])+2*n*(t[2]-t[1]),y:2*(1-n)*(h[1]-h[0])+2*n*(h[2]-h[1])}}function e(t,h,n){var i=r([3*(t[1]-t[0]),3*(t[2]-t[1]),3*(t[3]-t[2])],[3*(h[1]-h[0]),3*(h[2]-h[1]),3*(h[3]-h[2])],n);return i}function s(t,h,n,i,e){for(var s=1,r=t/h;s>.008;){var a=n(i,e,r);s=Math.abs(t-a)/h,r+=(t-a)/h}return r}function r(t,h,n){var i=(1-n)*(1-n)*t[0]+2*(1-n)*n*t[1]+n*n*t[2],e=(1-n)*(1-n)*h[0]+2*(1-n)*n*h[1]+n*n*h[2];return{x:i,y:e}}function a(t,h,n){var i=(1-n)*(1-n)*(1-n)*t[0]+3*(1-n)*(1-n)*n*t[1]+3*(1-n)*n*n*t[2]+n*n*n*t[3],e=(1-n)*(1-n)*(1-n)*h[0]+3*(1-n)*(1-n)*n*h[1]+3*(1-n)*n*n*h[2]+n*n*n*h[3];return{x:i,y:e}}function o(t,h,n){void 0===n&&(n=1);var i=t[0]-2*t[1]+t[2],e=h[0]-2*h[1]+h[2],s=2*t[1]-2*t[0],r=2*h[1]-2*h[0],a=4*(i*i+e*e),o=4*(i*s+e*r),u=s*s+r*r,g=o/(2*a),c=u/a,y=n+g,x=c-g*g;return Math.sqrt(a)/2*(y*Math.sqrt(y*y+x)-g*Math.sqrt(g*g+x)+x*Math.log(Math.abs((y+Math.sqrt(y*y+x))/(g+Math.sqrt(g*g+x)))))}function u(t,h){return L[t][h]}function g(t,h,n){var i,e,s,r=n.length-1;if(0===r)return 0;if(0===t){for(e=0,s=0;s<=r;s++)e+=u(r,s)*Math.pow(1-h,r-s)*Math.pow(h,s)*n[s];return e}for(i=new Array(r),s=0;s<r;s++)i[s]=r*(n[s+1]-n[s]);return g(t-1,h,i)}function c(t,h,n){var i=g(1,n,t),e=g(1,n,h),s=i*i+e*e;return Math.sqrt(s)}function y(t,h,n){var i,e,s,r;void 0===n&&(n=1);var a=20;for(i=n/2,e=0,s=0;s<a;s++)r=i*w[a][s]+i,e+=M[a][s]*c(t,h,r);return i*e}function x(t,h,n,i){this.x0=t,this.x1=h,this.y0=n,this.y1=i}var f={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},p=/([astvzqmhlc])([^astvzqmhlc]*)/gi,v=function(t){var n=[];return t.replace(p,function(t,i,e){var s=i.toLowerCase();for(e=h(e),"m"===s&&e.length>2&&(n.push([i].concat(e.splice(0,2))),s="l",i="m"===i?"l":"L");e.length>=0;){if(e.length===f[s])return e.unshift(i),n.push(e);if(e.length<f[s])throw new Error("malformed path data");n.push([i].concat(e.splice(0,f[s])))}}),n},l=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi,d=function(t,h,i,e,s,r,a,o){return new n(t,h,i,e,s,r,a,o)};n.prototype={constructor:n,init:function(){this.length=this.getArcLength([this.a.x,this.b.x,this.c.x,this.d.x],[this.a.y,this.b.y,this.c.y,this.d.y])},getTotalLength:function(){return this.length},getPointAtLength:function(t){var h=s(t,this.length,this.getArcLength,[this.a.x,this.b.x,this.c.x,this.d.x],[this.a.y,this.b.y,this.c.y,this.d.y]);return this.getPoint([this.a.x,this.b.x,this.c.x,this.d.x],[this.a.y,this.b.y,this.c.y,this.d.y],h)},getTangentAtLength:function(t){var h,n=s(t,this.length,this.getArcLength,[this.a.x,this.b.x,this.c.x,this.d.x],[this.a.y,this.b.y,this.c.y,this.d.y]),i=this.getDerivative([this.a.x,this.b.x,this.c.x,this.d.x],[this.a.y,this.b.y,this.c.y,this.d.y],n),e=Math.sqrt(i.x*i.x+i.y*i.y);return h=e>0?{x:i.x/e,y:i.y/e}:{x:0,y:0}},getPropertiesAtLength:function(t){var h,n=s(t,this.length,this.getArcLength,[this.a.x,this.b.x,this.c.x,this.d.x],[this.a.y,this.b.y,this.c.y,this.d.y]),i=this.getDerivative([this.a.x,this.b.x,this.c.x,this.d.x],[this.a.y,this.b.y,this.c.y,this.d.y],n),e=Math.sqrt(i.x*i.x+i.y*i.y);h=e>0?{x:i.x/e,y:i.y/e}:{x:0,y:0};var r=this.getPoint([this.a.x,this.b.x,this.c.x,this.d.x],[this.a.y,this.b.y,this.c.y,this.d.y],n);return{x:r.x,y:r.y,tangentX:h.x,tangentY:h.y}}};var w=[[],[],[-.5773502691896257,.5773502691896257],[0,-.7745966692414834,.7745966692414834],[-.33998104358485626,.33998104358485626,-.8611363115940526,.8611363115940526],[0,-.5384693101056831,.5384693101056831,-.906179845938664,.906179845938664],[.6612093864662645,-.6612093864662645,-.2386191860831969,.2386191860831969,-.932469514203152,.932469514203152],[0,.4058451513773972,-.4058451513773972,-.7415311855993945,.7415311855993945,-.9491079123427585,.9491079123427585],[-.1834346424956498,.1834346424956498,-.525532409916329,.525532409916329,-.7966664774136267,.7966664774136267,-.9602898564975363,.9602898564975363],[0,-.8360311073266358,.8360311073266358,-.9681602395076261,.9681602395076261,-.3242534234038089,.3242534234038089,-.6133714327005904,.6133714327005904],[-.14887433898163122,.14887433898163122,-.4333953941292472,.4333953941292472,-.6794095682990244,.6794095682990244,-.8650633666889845,.8650633666889845,-.9739065285171717,.9739065285171717],[0,-.26954315595234496,.26954315595234496,-.5190961292068118,.5190961292068118,-.7301520055740494,.7301520055740494,-.8870625997680953,.8870625997680953,-.978228658146057,.978228658146057],[-.1252334085114689,.1252334085114689,-.3678314989981802,.3678314989981802,-.5873179542866175,.5873179542866175,-.7699026741943047,.7699026741943047,-.9041172563704749,.9041172563704749,-.9815606342467192,.9815606342467192],[0,-.2304583159551348,.2304583159551348,-.44849275103644687,.44849275103644687,-.6423493394403402,.6423493394403402,-.8015780907333099,.8015780907333099,-.9175983992229779,.9175983992229779,-.9841830547185881,.9841830547185881],[-.10805494870734367,.10805494870734367,-.31911236892788974,.31911236892788974,-.5152486363581541,.5152486363581541,-.6872929048116855,.6872929048116855,-.827201315069765,.827201315069765,-.9284348836635735,.9284348836635735,-.9862838086968123,.9862838086968123],[0,-.20119409399743451,.20119409399743451,-.3941513470775634,.3941513470775634,-.5709721726085388,.5709721726085388,-.7244177313601701,.7244177313601701,-.8482065834104272,.8482065834104272,-.937273392400706,.937273392400706,-.9879925180204854,.9879925180204854],[-.09501250983763744,.09501250983763744,-.2816035507792589,.2816035507792589,-.45801677765722737,.45801677765722737,-.6178762444026438,.6178762444026438,-.755404408355003,.755404408355003,-.8656312023878318,.8656312023878318,-.9445750230732326,.9445750230732326,-.9894009349916499,.9894009349916499],[0,-.17848418149584785,.17848418149584785,-.3512317634538763,.3512317634538763,-.5126905370864769,.5126905370864769,-.6576711592166907,.6576711592166907,-.7815140038968014,.7815140038968014,-.8802391537269859,.8802391537269859,-.9506755217687678,.9506755217687678,-.9905754753144174,.9905754753144174],[-.0847750130417353,.0847750130417353,-.2518862256915055,.2518862256915055,-.41175116146284263,.41175116146284263,-.5597708310739475,.5597708310739475,-.6916870430603532,.6916870430603532,-.8037049589725231,.8037049589725231,-.8926024664975557,.8926024664975557,-.9558239495713977,.9558239495713977,-.9915651684209309,.9915651684209309],[0,-.16035864564022537,.16035864564022537,-.31656409996362983,.31656409996362983,-.46457074137596094,.46457074137596094,-.600545304661681,.600545304661681,-.7209661773352294,.7209661773352294,-.8227146565371428,.8227146565371428,-.9031559036148179,.9031559036148179,-.96020815213483,.96020815213483,-.9924068438435844,.9924068438435844],[-.07652652113349734,.07652652113349734,-.22778585114164507,.22778585114164507,-.37370608871541955,.37370608871541955,-.5108670019508271,.5108670019508271,-.636053680726515,.636053680726515,-.7463319064601508,.7463319064601508,-.8391169718222188,.8391169718222188,-.912234428251326,.912234428251326,-.9639719272779138,.9639719272779138,-.9931285991850949,.9931285991850949],[0,-.1455618541608951,.1455618541608951,-.2880213168024011,.2880213168024011,-.4243421202074388,.4243421202074388,-.5516188358872198,.5516188358872198,-.6671388041974123,.6671388041974123,-.7684399634756779,.7684399634756779,-.8533633645833173,.8533633645833173,-.9200993341504008,.9200993341504008,-.9672268385663063,.9672268385663063,-.9937521706203895,.9937521706203895],[-.06973927331972223,.06973927331972223,-.20786042668822127,.20786042668822127,-.34193582089208424,.34193582089208424,-.469355837986757,.469355837986757,-.5876404035069116,.5876404035069116,-.6944872631866827,.6944872631866827,-.7878168059792081,.7878168059792081,-.8658125777203002,.8658125777203002,-.926956772187174,.926956772187174,-.9700604978354287,.9700604978354287,-.9942945854823992,.9942945854823992],[0,-.1332568242984661,.1332568242984661,-.26413568097034495,.26413568097034495,-.3903010380302908,.3903010380302908,-.5095014778460075,.5095014778460075,-.6196098757636461,.6196098757636461,-.7186613631319502,.7186613631319502,-.8048884016188399,.8048884016188399,-.8767523582704416,.8767523582704416,-.9329710868260161,.9329710868260161,-.9725424712181152,.9725424712181152,-.9947693349975522,.9947693349975522],[-.06405689286260563,.06405689286260563,-.1911188674736163,.1911188674736163,-.3150426796961634,.3150426796961634,-.4337935076260451,.4337935076260451,-.5454214713888396,.5454214713888396,-.6480936519369755,.6480936519369755,-.7401241915785544,.7401241915785544,-.820001985973903,.820001985973903,-.8864155270044011,.8864155270044011,-.9382745520027328,.9382745520027328,-.9747285559713095,.9747285559713095,-.9951872199970213,.9951872199970213]],M=[[],[],[1,1],[.8888888888888888,.5555555555555556,.5555555555555556],[.6521451548625461,.6521451548625461,.34785484513745385,.34785484513745385],[.5688888888888889,.47862867049936647,.47862867049936647,.23692688505618908,.23692688505618908],[.3607615730481386,.3607615730481386,.46791393457269104,.46791393457269104,.17132449237917036,.17132449237917036],[.4179591836734694,.3818300505051189,.3818300505051189,.27970539148927664,.27970539148927664,.1294849661688697,.1294849661688697],[.362683783378362,.362683783378362,.31370664587788727,.31370664587788727,.22238103445337448,.22238103445337448,.10122853629037626,.10122853629037626],[.3302393550012598,.1806481606948574,.1806481606948574,.08127438836157441,.08127438836157441,.31234707704000286,.31234707704000286,.26061069640293544,.26061069640293544],[.29552422471475287,.29552422471475287,.26926671930999635,.26926671930999635,.21908636251598204,.21908636251598204,.1494513491505806,.1494513491505806,.06667134430868814,.06667134430868814],[.2729250867779006,.26280454451024665,.26280454451024665,.23319376459199048,.23319376459199048,.18629021092773426,.18629021092773426,.1255803694649046,.1255803694649046,.05566856711617366,.05566856711617366],[.24914704581340277,.24914704581340277,.2334925365383548,.2334925365383548,.20316742672306592,.20316742672306592,.16007832854334622,.16007832854334622,.10693932599531843,.10693932599531843,.04717533638651183,.04717533638651183],[.2325515532308739,.22628318026289723,.22628318026289723,.2078160475368885,.2078160475368885,.17814598076194574,.17814598076194574,.13887351021978725,.13887351021978725,.09212149983772845,.09212149983772845,.04048400476531588,.04048400476531588],[.2152638534631578,.2152638534631578,.2051984637212956,.2051984637212956,.18553839747793782,.18553839747793782,.15720316715819355,.15720316715819355,.12151857068790319,.12151857068790319,.08015808715976021,.08015808715976021,.03511946033175186,.03511946033175186],[.2025782419255613,.19843148532711158,.19843148532711158,.1861610000155622,.1861610000155622,.16626920581699392,.16626920581699392,.13957067792615432,.13957067792615432,.10715922046717194,.10715922046717194,.07036604748810812,.07036604748810812,.03075324199611727,.03075324199611727],[.1894506104550685,.1894506104550685,.18260341504492358,.18260341504492358,.16915651939500254,.16915651939500254,.14959598881657674,.14959598881657674,.12462897125553388,.12462897125553388,.09515851168249279,.09515851168249279,.062253523938647894,.062253523938647894,.027152459411754096,.027152459411754096],[.17944647035620653,.17656270536699264,.17656270536699264,.16800410215645004,.16800410215645004,.15404576107681028,.15404576107681028,.13513636846852548,.13513636846852548,.11188384719340397,.11188384719340397,.08503614831717918,.08503614831717918,.0554595293739872,.0554595293739872,.02414830286854793,.02414830286854793],[.1691423829631436,.1691423829631436,.16427648374583273,.16427648374583273,.15468467512626524,.15468467512626524,.14064291467065065,.14064291467065065,.12255520671147846,.12255520671147846,.10094204410628717,.10094204410628717,.07642573025488905,.07642573025488905,.0497145488949698,.0497145488949698,.02161601352648331,.02161601352648331],[.1610544498487837,.15896884339395434,.15896884339395434,.15276604206585967,.15276604206585967,.1426067021736066,.1426067021736066,.12875396253933621,.12875396253933621,.11156664554733399,.11156664554733399,.09149002162245,.09149002162245,.06904454273764123,.06904454273764123,.0448142267656996,.0448142267656996,.019461788229726478,.019461788229726478],[.15275338713072584,.15275338713072584,.14917298647260374,.14917298647260374,.14209610931838204,.14209610931838204,.13168863844917664,.13168863844917664,.11819453196151841,.11819453196151841,.10193011981724044,.10193011981724044,.08327674157670475,.08327674157670475,.06267204833410907,.06267204833410907,.04060142980038694,.04060142980038694,.017614007139152118,.017614007139152118],[.14608113364969041,.14452440398997005,.14452440398997005,.13988739479107315,.13988739479107315,.13226893863333747,.13226893863333747,.12183141605372853,.12183141605372853,.10879729916714838,.10879729916714838,.09344442345603386,.09344442345603386,.0761001136283793,.0761001136283793,.057134425426857205,.057134425426857205,.036953789770852494,.036953789770852494,.016017228257774335,.016017228257774335],[.13925187285563198,.13925187285563198,.13654149834601517,.13654149834601517,.13117350478706238,.13117350478706238,.12325237681051242,.12325237681051242,.11293229608053922,.11293229608053922,.10041414444288096,.10041414444288096,.08594160621706773,.08594160621706773,.06979646842452049,.06979646842452049,.052293335152683286,.052293335152683286,.03377490158481415,.03377490158481415,.0146279952982722,.0146279952982722],[.13365457218610619,.1324620394046966,.1324620394046966,.12890572218808216,.12890572218808216,.12304908430672953,.12304908430672953,.11499664022241136,.11499664022241136,.10489209146454141,.10489209146454141,.09291576606003515,.09291576606003515,.07928141177671895,.07928141177671895,.06423242140852585,.06423242140852585,.04803767173108467,.04803767173108467,.030988005856979445,.030988005856979445,.013411859487141771,.013411859487141771],[.12793819534675216,.12793819534675216,.1258374563468283,.1258374563468283,.12167047292780339,.12167047292780339,.1155056680537256,.1155056680537256,.10744427011596563,.10744427011596563,.09761865210411388,.09761865210411388,.08619016153195327,.08619016153195327,.0733464814110803,.0733464814110803,.05929858491543678,.05929858491543678,.04427743881741981,.04427743881741981,.028531388628933663,.028531388628933663,.0123412297999872,.0123412297999872]],L=[[1],[1,1],[1,2,1],[1,3,3,1]],b=function(t,h,n,i){return new x(t,h,n,i)};x.prototype.getTotalLength=function(){return Math.sqrt(Math.pow(this.x0-this.x1,2)+Math.pow(this.y0-this.y1,2))},x.prototype.getPointAtLength=function(t){var h=t/Math.sqrt(Math.pow(this.x0-this.x1,2)+Math.pow(this.y0-this.y1,2)),n=(this.x1-this.x0)*h,i=(this.y1-this.y0)*h;return{x:this.x0+n,y:this.y0+i}},x.prototype.getTangentAtLength=function(){var t=Math.sqrt((this.x1-this.x0)*(this.x1-this.x0)+(this.y1-this.y0)*(this.y1-this.y0));return{x:(this.x1-this.x0)/t,y:(this.y1-this.y0)/t}},x.prototype.getPropertiesAtLength=function(t){var h=this.getPointAtLength(t),n=this.getTangentAtLength();return{x:h.x,y:h.y,tangentX:n.x,tangentY:n.y}};var A=function(t){function h(t){if(!t)return null;for(var s,r=v(t),a=[0,0],o=[0,0],u=0;u<r.length;u++)"M"===r[u][0]?(a=[r[u][1],r[u][2]],e.push(null)):"m"===r[u][0]?(a=[r[u][1]+a[0],r[u][2]+a[1]],e.push(null)):"L"===r[u][0]?(n+=Math.sqrt(Math.pow(a[0]-r[u][1],2)+Math.pow(a[1]-r[u][2],2)),e.push(new b(a[0],r[u][1],a[1],r[u][2])),a=[r[u][1],r[u][2]]):"l"===r[u][0]?(n+=Math.sqrt(Math.pow(r[u][1],2)+Math.pow(r[u][2],2)),e.push(new b(a[0],r[u][1]+a[0],a[1],r[u][2]+a[1])),a=[r[u][1]+a[0],r[u][2]+a[1]]):"H"===r[u][0]?(n+=Math.abs(a[0]-r[u][1]),e.push(new b(a[0],r[u][1],a[1],a[1])),a[0]=r[u][1]):"h"===r[u][0]?(n+=Math.abs(r[u][1]),e.push(new b(a[0],a[0]+r[u][1],a[1],a[1])),a[0]=r[u][1]+a[0]):"V"===r[u][0]?(n+=Math.abs(a[1]-r[u][1]),e.push(new b(a[0],a[0],a[1],r[u][1])),a[1]=r[u][1]):"v"===r[u][0]?(n+=Math.abs(r[u][1]),e.push(new b(a[0],a[0],a[1],a[1]+r[u][1])),a[1]=r[u][1]+a[1]):"z"===r[u][0]||"Z"===r[u][0]?(n+=Math.sqrt(Math.pow(r[0][1]-a[0],2)+Math.pow(r[0][2]-a[1],2)),e.push(new b(a[0],r[0][1],a[1],r[0][2])),a=[r[0][1],r[0][2]]):"C"===r[u][0]?(s=new d(a[0],a[1],r[u][1],r[u][2],r[u][3],r[u][4],r[u][5],r[u][6]),n+=s.getTotalLength(),a=[r[u][5],r[u][6]],e.push(s)):"c"===r[u][0]?(s=new d(a[0],a[1],a[0]+r[u][1],a[1]+r[u][2],a[0]+r[u][3],a[1]+r[u][4],a[0]+r[u][5],a[1]+r[u][6]),n+=s.getTotalLength(),a=[r[u][5]+a[0],r[u][6]+a[1]],e.push(s)):"S"===r[u][0]?(s=u>0&&["C","c","S","s"].indexOf(r[u-1][0])>-1?new d(a[0],a[1],2*a[0]-r[u-1][r[u-1].length-4],2*a[1]-r[u-1][r[u-1].length-3],r[u][1],r[u][2],r[u][3],r[u][4]):new d(a[0],a[1],a[0],a[1],r[u][1],r[u][2],r[u][3],r[u][4]),n+=s.getTotalLength(),a=[r[u][3],r[u][4]],e.push(s)):"s"===r[u][0]?(s=u>0&&["C","c","S","s"].indexOf(r[u-1][0])>-1?new d(a[0],a[1],a[0]+s.d.x-s.c.x,a[1]+s.d.y-s.c.y,a[0]+r[u][1],a[1]+r[u][2],a[0]+r[u][3],a[1]+r[u][4]):new d(a[0],a[1],a[0],a[1],a[0]+r[u][1],a[1]+r[u][2],a[0]+r[u][3],a[1]+r[u][4]),n+=s.getTotalLength(),a=[r[u][3]+a[0],r[u][4]+a[1]],e.push(s)):"Q"===r[u][0]?(s=new d(a[0],a[1],r[u][1],r[u][2],r[u][3],r[u][4]),n+=s.getTotalLength(),e.push(s),a=[r[u][3],r[u][4]],o=[r[u][1],r[u][2]]):"q"===r[u][0]?(s=new d(a[0],a[1],a[0]+r[u][1],a[1]+r[u][2],a[0]+r[u][3],a[1]+r[u][4]),n+=s.getTotalLength(),o=[a[0]+r[u][1],a[1]+r[u][2]],a=[r[u][3]+a[0],r[u][4]+a[1]],e.push(s)):"T"===r[u][0]?(s=u>0&&["Q","q","T","t"].indexOf(r[u-1][0])>-1?new d(a[0],a[1],2*a[0]-o[0],2*a[1]-o[1],r[u][1],r[u][2]):new b(a[0],r[u][1],a[1],r[u][2]),e.push(s),n+=s.getTotalLength(),o=[2*a[0]-o[0],2*a[1]-o[1]],a=[r[u][1],r[u][2]]):"t"===r[u][0]&&(s=u>0&&["Q","q","T","t"].indexOf(r[u-1][0])>-1?new d(a[0],a[1],2*a[0]-o[0],2*a[1]-o[1],a[0]+r[u][1],a[1]+r[u][2]):new b(a[0],a[0]+r[u][1],a[1],a[1]+r[u][2]),n+=s.getTotalLength(),o=[2*a[0]-o[0],2*a[1]-o[1]],a=[r[u][1]+a[0],r[u][2]+a[0]],e.push(s)),i.push(n);return h}var n=0,i=[],e=[];h.getTotalLength=function(){return n},h.getPointAtLength=function(t){var h=s(t);return e[h.i].getPointAtLength(h.fraction)},h.getTangentAtLength=function(t){var h=s(t);return e[h.i].getTangentAtLength(h.fraction)},h.getPropertiesAtLength=function(t){var h=s(t);return e[h.i].getPropertiesAtLength(h.fraction)};var s=function(t){t<0?t=0:t>n&&(t=n);for(var h=i.length-1;i[h]>=t&&i[h]>0;)h--;return h++,{fraction:t-i[h-1],i:h}};return h(t)};t.svgPathProperties=A,t.parse=v,t.Bezier=d,Object.defineProperty(t,"__esModule",{value:!0})});
// raster-streamlines Version 0.0.1. Copyright 2016 Roger Veciana i Rovira.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.rs = global.rs || {})));
}(this, (function (exports) { 'use strict';
var streamlines = function(uData, vData, geotransform, flip){
var output = { "type": "FeatureCollection",
"features": []
};
var num_lines = 0;
var inst = new Streamlines(uData, vData);
if(!geotransform){
geotransform = [0,1,0,0,0,1];
} else if(geotransform.length !== 6){
throw new Error('Bad geotransform');
}
//Iterate different points to start lines while available pixels
var pixel = true;
var line = true;
var pos = 0;
var x, y;
while(pixel){
if(pos%4 === 0){
x = 0;
y = 0;
} else if(pos%4 === 1){
x = uData[0].length - 1;
y = uData.length - 1;
} else if(pos%4 === 2){
x = uData[0].length - 1;
y = 0;
} else{
x = 0;
y = uData.length - 1;
}
pixel = inst.findEmptyPixel(x,y,1);
line = inst.getLine(pixel.x, pixel.y, flip);
if(line){
output.features.push({"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": inst.applyGeoTransform(line, geotransform)},
"properties": {"num_line": num_lines}
});
num_lines++;
}
pos++;
}
return output;
};
function Streamlines(uData, vData){
if(uData.length <= 1 || vData.length <= 1 || uData[0].length <= 1 || vData[0].length <= 1){
throw new Error('Raster is too small');
}
this.uData = uData;
this.vData = vData;
this.usedPixels = [];
for(var i = 0; i<uData.length; i++){
var line = [];
for(var j = 0; j<uData[0].length; j++){
line.push(false);
}
this.usedPixels.push(line);
}
}
Streamlines.prototype.findEmptyPixel = function(x0, y0, dist) {
//Explores around the init pixel creating squares to find an empty pixel
if(this.isPixelFree(x0, y0, dist)){
return {x:x0, y:y0};
}
var maxDist = this.uData[0].length + this.uData.length;
for(var d = 2; d <= maxDist + 1; d=d+2){
for(var pd = 0; pd<d; pd++){
if(this.isPixelFree(pd+1+x0-d/2, y0-d/2, dist)){return {x:pd+1+x0-d/2, y:y0-d/2};}
if(this.isPixelFree(x0-d/2, pd+y0-d/2, dist)){return {x:x0-d/2, y:pd+y0-d/2};}
if(this.isPixelFree(d+x0-d/2, pd+1+y0-d/2, dist)){return {x:d+x0-d/2, y:pd+1+y0-d/2};}
if(this.isPixelFree(pd+x0-d/2, d+y0-d/2, dist)){return {x:pd+x0-d/2, y:d+y0-d/2};}
}
}
return false;
};
Streamlines.prototype.isPixelFree = function(x0, y0, dist) {
if(x0<0 || x0>=this.usedPixels[0].length || y0<0 || y0 >= this.usedPixels.length){
return false;
}
for(var i=-dist; i<=dist;i++){
for(var j=-dist; j<=dist;j++){
if(y0+j>=0 &&y0+j<this.usedPixels.length && x0+i>=0 && x0+i<this.usedPixels[y0].length){
if(this.usedPixels[y0+j][x0+i]){
return false;
}
}
}
}
return true;
};
Streamlines.prototype.getLine = function(x0, y0, flip) {
var lineFound = false;
var x = x0;
var y = y0;
var values;
var outLine = [[x,y]];
if(flip){flip = 1;} else {flip = -1;}
while(x >= 0 && x < this.uData[0].length && y >= 0 && y < this.uData.length){
values = this.getValueAtPoint(x, y);
x = x + values.u;
y = y + flip * values.v; //The wind convention says v goes from bottom to top
if(values.u === 0 && values.v === 0){this.usedPixels[y0][x0] = true; break;} //Zero speed points are problematic
if(x < 0 || y < 0 || x>= this.uData[0].length|| y >= this.uData.length || this.usedPixels[Math.floor(y)][Math.floor(x)]){break;}
outLine.push([x,y]);
lineFound = true;
this.usedPixels[Math.floor(y)][Math.floor(x)] = true;
}
//repeat the operation but backwards, so strange effects in some cases are avoided.
x = x0;
y = y0;
while(x >= 0 && x < this.uData[0].length && y >= 0 && y < this.uData.length){
values = this.getValueAtPoint(x, y);
x = x - values.u;
y = y - flip * values.v; //The wind convention says v goes from bottom to top
if(values.u === 0 && values.v === 0){this.usedPixels[y0][x0] = true; break;} //Zero speed points are problematic
if(x < 0 || y < 0 || x>= this.uData[0].length || y >= this.uData.length || this.usedPixels[Math.floor(y)][Math.floor(x)]){break;}
outLine.unshift([x,y]);
lineFound = true;
this.usedPixels[Math.floor(y)][Math.floor(x)] = true;
}
if(lineFound){
this.usedPixels[y0][x0] = true;
return outLine;
} else {
return false;
}
};
Streamlines.prototype.applyGeoTransform = function(line, geotransform) {
var outLine = [];
for(var i = 0; i<line.length; i++){
outLine.push([geotransform[0] + geotransform[1] * line[i][0] + geotransform[2] * line[i][1], geotransform[3] + geotransform[4] * line[i][0] + geotransform[5] * line[i][1]]);
}
return outLine;
};
Streamlines.prototype.getValueAtPoint = function(x, y) {
var u, v, mdl, distTotal;
var dist1 = Math.sqrt((Math.floor(x) - x) * (Math.floor(x) - x) + (Math.floor(y) - y) * (Math.floor(y) - y));
var dist2 = Math.sqrt((Math.floor(x) - x) * (Math.floor(x) - x) + (Math.ceil(y) - y) * (Math.ceil(y) - y));
var dist3 = Math.sqrt((Math.ceil(x) - x) * (Math.ceil(x) - x) + (Math.ceil(y) - y) * (Math.ceil(y) - y));
var dist4 = Math.sqrt((Math.ceil(x) - x) * (Math.ceil(x) - x) + (Math.floor(y) - y) * (Math.floor(y) - y));
if(dist1 < 0.01){
u = this.uData[Math.floor(y)][Math.floor(x)];
v = this.vData[Math.floor(y)][Math.floor(x)];
} else if(dist2 < 0.01){
u = this.uData[Math.ceil(y)][Math.floor(x)];
v = this.vData[Math.ceil(y)][Math.floor(x)];
} else if(dist3 < 0.01){
u = this.uData[Math.ceil(y)][Math.ceil(x)];
v = this.vData[Math.ceil(y)][Math.ceil(x)];
} else if(dist4 < 0.01){
u = this.uData[Math.floor(y)][Math.ceil(x)];
v = this.vData[Math.floor(y)][Math.ceil(x)];
} else {
distTotal = 0;
u = 0;
v = 0;
if(this.uData[Math.floor(y)] && this.uData[Math.floor(y)][Math.floor(x)]){
u+=this.uData[Math.floor(y)][Math.floor(x)]/dist1;
v+=this.vData[Math.floor(y)][Math.floor(x)]/dist1;
distTotal+=(1/dist1);
}
if(this.uData[Math.ceil(y)] && this.uData[Math.ceil(y)][Math.floor(x)]){
u+=this.uData[Math.ceil(y)][Math.floor(x)]/dist2;
v+=this.vData[Math.ceil(y)][Math.floor(x)]/dist2;
distTotal+=(1/dist2);
}
if(this.uData[Math.ceil(y)] && this.uData[Math.ceil(y)][Math.ceil(x)]){
u+=this.uData[Math.ceil(y)][Math.ceil(x)]/dist3;
v+=this.vData[Math.ceil(y)][Math.ceil(x)]/dist3;
distTotal+=(1/dist3);
}
if(this.uData[Math.floor(y)] && this.uData[Math.floor(y)][Math.ceil(x)]){
u+=this.uData[Math.floor(y)][Math.ceil(x)]/dist4;
v+=this.vData[Math.floor(y)][Math.ceil(x)]/dist4;
distTotal+=(1/dist4);
}
u = u/distTotal;
v = v/distTotal;
}
mdl = Math.sqrt(u*u+v*v);
if(mdl!==0 && distTotal !== 0){
return {u:u/mdl, v:v/mdl};
} else {
return {u:0, v:0};
}
};
exports.streamlines = streamlines;
Object.defineProperty(exports, '__esModule', { value: true });
})));
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment