title: BigQuery - ST_MAKEPOLYGON() fail with invalid polygon loop
body: <p>I followed the brilliant post  <a href="https://stackoverflow.com/questions/54361149/how-to-catch-st-makepolygon-error-in-bigquery">How to Catch ST_MAKEPOLYGON Error in BigQuery</a><br>
  which eliminate most of the problems, but i still run into an edge situation where the ST_MAKEPOLYGONS() failed with: </p>
  
  <blockquote>
    <p>Invalid polygon loop.</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/ASVj3.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ASVj3.jpg" alt="enter image description here"></a>  </p>
  
  <p>My question is twofold.  </p>
  
  <ul>
  <li>What is the meaning of the error message.  </li>
  <li>How can I detect such a situation in order to avoid this type of error.  </li>
  </ul>
  
  <p>I followed the advice in referenced post, and also introduced another preventive measure, but still run into a problem.</p>
  
  <pre><code>-- remove invalid ratio
      SELECT * 
      FROM(SELECT *,
           SAFE_DIVIDE(ST_DISTANCE(centroid, anchor) , ST_DISTANCE(centroid, location)) AS ratio 
           FROM X4) 
           WHERE ratio BETWEEN -1 AND 1
  </code></pre>