<div dir="ltr"><div style="font-size:small" class="gmail_default">Noticed that the message containing the query wasn't coupled to my latest post, so here it is again:<br></div><div style="font-size:small" class="gmail_default"><br></div><div style="font-size:small" class="gmail_default">SELECT ST_isvalid(simplifiedgeo2),* FROM (<br>SELECT  <br>    foo2.ne_id,<br>    <a href="http://foo2.name">foo2.name</a>,<br>    CASE<br>        WHEN ST_isvalid(foo2.simplifiedgeo) THEN foo2.simplifiedgeo<br>        ELSE ST_makevalid(foo2.simplifiedgeo)<br>    END AS simplifiedgeo2<br>   FROM (<br>     SELECT<br>       ST_simplifypreservetopology(foo.geom,<br>         LEAST(<br>           ST_xmax(foo.shiftedgeo::box3d) - ST_xmin(foo.shiftedgeo::box3d), ST_ymax(foo.shiftedgeo::box3d) - ST_ymin(foo.shiftedgeo::box3d))<br>         ) AS simplifiedgeo,<br>       foo.ne_id,<br>       <a href="http://foo.name">foo.name</a>,<br>       foo.geom<br>     FROM (<br>        SELECT<br>          natearth.ne_id,<br>          natearth.geom,<br>          <a href="http://natearth.name">natearth.name</a>,<br>          CASE<br>              WHEN (<br>                ST_xmax(ST_shiftlongitude(natearth.geom)::box3d) - ST_xmin(ST_shiftlongitude(natearth.geom)::box3d))<br>                <<br>                (ST_xmax(natearth.geom::box3d) - ST_xmin(natearth.geom::box3d)<br>              ) THEN ST_shiftlongitude(natearth.geom)<br>              ELSE natearth.geom<br>          END AS shiftedgeo<br>          FROM (<br>             SELECT<br>                ne_10m_admin_0_countries_lakes.ne_id,<br>                ne_10m_admin_0_countries_lakes.geom,<br>                <a href="http://ne_10m_admin_0_countries_lakes.name">ne_10m_admin_0_countries_lakes.name</a><br>              FROM ne_10m_admin_0_countries_lakes<br>          UNION ALL<br>             SELECT<br>                ne_10m_admin_1_states_provinces_lakes.ne_id,<br>                ne_10m_admin_1_states_provinces_lakes.geom,<br>                <a href="http://ne_10m_admin_1_states_provinces_lakes.name">ne_10m_admin_1_states_provinces_lakes.name</a><br>             FROM ne_10m_admin_1_states_provinces_lakes<br>          ) natearth<br>     ) foo<br>   ) foo2<br>) as fff<br>WHERE NOT ST_isvalid(simplifiedgeo2)</div><div style="font-size:small" class="gmail_default"><br></div><div style="font-size:small" class="gmail_default"><br></div><div style="font-size:small" class="gmail_default">P.S. when replying, could you also include my mail address?<br></div></div>