Is there a way via JS or Python to simply pass an XY to a function and determine if inside or outside a polygon (from a map Service)
I need to do this for Decimal Degrees, DMS, UTM etc.
I can do it like below BUT I would have to list out EVERY node and trying to do this for a complete state
<SPAN class="keyword token">function</SPAN> <SPAN class="token function">inside</SPAN><SPAN class="punctuation token">(</SPAN>point<SPAN class="punctuation token">,</SPAN> vs<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> x <SPAN class="operator token">=</SPAN> point<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> y <SPAN class="operator token">=</SPAN> point<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> inside <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">for</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> i <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> j <SPAN class="operator token">=</SPAN> vs<SPAN class="punctuation token">.</SPAN>length <SPAN class="operator token">-</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">;</SPAN> i <SPAN class="operator token"><</SPAN> vs<SPAN class="punctuation token">.</SPAN>length<SPAN class="punctuation token">;</SPAN> j <SPAN class="operator token">=</SPAN> i<SPAN class="operator token">++</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> xi <SPAN class="operator token">=</SPAN> vs<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> yi <SPAN class="operator token">=</SPAN> vs<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> xj <SPAN class="operator token">=</SPAN> vs<SPAN class="punctuation token">[</SPAN>j<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> yj <SPAN class="operator token">=</SPAN> vs<SPAN class="punctuation token">[</SPAN>j<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> intersect <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>yi <SPAN class="operator token">></SPAN> y<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">!=</SPAN> <SPAN class="punctuation token">(</SPAN>yj <SPAN class="operator token">></SPAN> y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token">&&</SPAN> <SPAN class="punctuation token">(</SPAN>x <SPAN class="operator token"><</SPAN> <SPAN class="punctuation token">(</SPAN>xj <SPAN class="operator token">-</SPAN> xi<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">*</SPAN> <SPAN class="punctuation token">(</SPAN>y <SPAN class="operator token">-</SPAN> yi<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">/</SPAN> <SPAN class="punctuation token">(</SPAN>yj <SPAN class="operator token">-</SPAN> yi<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> xi<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>intersect<SPAN class="punctuation token">)</SPAN> inside <SPAN class="operator token">=</SPAN> <SPAN class="operator token">!</SPAN>inside<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">return</SPAN> inside<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> polygon <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">4040958.21</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">261090.239</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">4399737.773</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">261090.239</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">4399737.773</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1004118.285</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">4040958.21</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1004118.285</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="operator token"><</SPAN><SPAN class="operator token">!</SPAN><SPAN class="operator token">--</SPAN><SPAN class="comment token">// The below are two examples. One of them is inside the other is outside to bounding box</SPAN>
<SPAN class="comment token">// inside --></SPAN>
test <SPAN class="operator token">=</SPAN> <SPAN class="token function">inside</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN> <SPAN class="number token">4147263</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">646445.066</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> polygon<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// true</SPAN>
<SPAN class="operator token"><</SPAN><SPAN class="operator token">!</SPAN><SPAN class="operator token">--</SPAN> <SPAN class="comment token">// outside --></SPAN>
<SPAN class="operator token"><</SPAN><SPAN class="operator token">!</SPAN><SPAN class="operator token">--</SPAN>
test <SPAN class="operator token">=</SPAN> <SPAN class="token function">inside</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN> <SPAN class="number token">4537048</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">694061</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> polygon<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// false</SPAN>
<SPAN class="operator token">--</SPAN><SPAN class="operator token">></SPAN>
<SPAN class="token function">alert</SPAN><SPAN class="punctuation token">(</SPAN>test<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>