<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Spatial operation error using ST_Intersection() with ST_Transform() in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/spatial-operation-error-using-st-intersection-with-st-transform/qaa-p/13846991#M4877834</link>
    <description>&lt;P&gt;One possible cause of this type of error is that the input geometries are invalid.  Checking for invalid geometries is not performed when a geometry is loaded/created.&lt;/P&gt;
&lt;P&gt;From&lt;/P&gt;
&lt;PRE class="codehilite"&gt;&lt;CODE&gt;SELECT
gp.*
,gp.GEOMETRY.ST_IsValid()
,gp.GEOMETRY.ST_Transform(3857) AS GP_3857
,GP_3857.ST_IsValid()
,zp.*
,zp.GEOMETRY.ST_IsValid()
,zp.GEOMETRY.ST_Transform(3857) AS ZP_3857
,zp_3857.ST_IsValid()
//,GP_3857.ST_Intersection(ZP_3857) AS INTERSECTION
FROM Test_GeometryPart gp, Test_GeometryPart zp
WHERE gp.GEO_ID = 43055
AND zp.GEO_ID = 1485884;


&lt;P&gt;Note the zp_3857 is not valid.  From:&lt;/P&gt;
&lt;/CODE&gt;&lt;PRE class="codehilite"&gt;&lt;CODE&gt;&lt;CODE&gt;call st_geometry_dump( 
(SELECT
zp.GEOMETRY.ST_Transform(3857) AS ZP_3857
FROM Test_GeometryPart zp
WHERE zp.GEO_ID = 1485884 ),
'validate=full' )


&lt;P&gt;We can see that:&lt;/P&gt;
&lt;/CODE&gt;&lt;/CODE&gt;&lt;PRE class="codehilite"&gt;&lt;CODE&gt;&lt;CODE&gt;&lt;CODE&gt;Polygon ((-8960237.976 5357495.7335, -8960237.9758 5357495.7332, 
-8960237.9758 5357495.7333, -8960237.976 5357495.7335))


&lt;P&gt;has the error: Curve 0 of polygon is not a ring (near "Polygon ((-8960237.976 5357495.7335, -8960237.9758 5357495.7332, -8960237.9758 5357495.7333, -8960237.976 5357495.7335))")&lt;/P&gt;
&lt;P&gt;Hmm...  This ring looks closed to me (start point is exactly end point).  I will look further.&lt;/P&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/PRE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 19 Nov 2014 10:20:03 GMT</pubDate>
    <dc:creator>ian_mchardy</dc:creator>
    <dc:date>2014-11-19T10:20:03Z</dc:date>
    <item>
      <title>Spatial operation error using ST_Intersection() with ST_Transform()</title>
      <link>https://community.sap.com/t5/technology-q-a/spatial-operation-error-using-st-intersection-with-st-transform/qaq-p/13846990</link>
      <description>&lt;P&gt;I'm getting an error with the ST_Intersection() function that makes no sense to me.  The error is:
&lt;/P&gt;&lt;PRE&gt;&lt;P&gt;&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;There was an error reading the results of the SQL statement.
The displayed results may be incorrect or incomplete.
Invalid polygon: ring is not closed (near 'CompoundCurve ((-8960237.9725
5357495.7308, -8960233.9554 5357492.7047, -8960232.568 5357491.5778,
-8960231.9835 5357491.1286, ')
SQLCODE=-1485, ODBC 3 State="HY000"&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;
If you look at the example below, there is a Polygon and a MultiPolygon and I am checking whether or not they intersect.
I believe all of the polygons involved are closed (i.e., start==end), but the error implies otherwise.&lt;P&gt;&lt;/P&gt;
&lt;PRE&gt;-------------------------------------------------------------------------------------------------
DROP TABLE IF EXISTS Test_GeometryPart;
CREATE TABLE Test_GeometryPart (
    "GEO_ID" BIGINT NOT NULL,
    "GEOMETRY" ST_Geometry(SRID=4269) NOT NULL,
) IN "system";

INSERT INTO "DBA"."Test_GeometryPart" ("GEO_ID","GEOMETRY") VALUES(43055,'Polygon ((-80.490979899999999 43.490733200000001, -80.491207399999993 43.490490100000002, -80.491187199999999 43.490479700000002, -80.491133399999995 43.490449599999998, -80.491082000000006 43.4904175, -80.490839100000002 43.490647500000001, -80.490960900000005 43.490721600000001, -80.490979899999999 43.490733200000001))');
INSERT INTO "DBA"."Test_GeometryPart" ("GEO_ID","GEOMETRY") VALUES(1485884,'MultiPolygon (((-80.491187230078907 43.490479716207119, -80.49115111388835 43.490459908120179, -80.491116014830851 43.490439150960938, -80.491081981067708 43.490417473797557, -80.49083911081506 43.490647468049133, -80.490960867340746 43.490721593241055, -80.491187230078907 43.490479716207119)), ((-80.491187231297985 43.490479717105607, -80.491187230086396 43.490479715314088, -80.491187230078907 43.490479716207119, -80.491187231297985 43.490479717105607)))');

COMMIT;

SELECT
gp.*
,gp.GEOMETRY.ST_Transform(3857) AS GP_3857
,zp.*
,zp.GEOMETRY.ST_Transform(3857) AS ZP_3857
,GP_3857.ST_Intersection(ZP_3857) AS INTERSECTION
FROM Test_GeometryPart gp, Test_GeometryPart zp
WHERE gp.GEO_ID = 43055
AND zp.GEO_ID = 1485884;
-------------------------------------------------------------------------------------------------

&lt;/PRE&gt;

&lt;P&gt;I'm running SQL Anywhere 16.0.0.1948 Developer Edition under Windows 7 (I believe it is the latest version since 'Check-for-Updates' reports no updates).
Is this a bug?  Has anyone else seen this?&lt;/P&gt;
&lt;P&gt;Terry&lt;/P&gt;</description>
      <pubDate>Tue, 18 Nov 2014 15:48:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/spatial-operation-error-using-st-intersection-with-st-transform/qaq-p/13846990</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-11-18T15:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial operation error using ST_Intersection() with ST_Transform()</title>
      <link>https://community.sap.com/t5/technology-q-a/spatial-operation-error-using-st-intersection-with-st-transform/qaa-p/13846992#M4877835</link>
      <description>&lt;P&gt;I'm no spatial expert at all but I (wildly!) guess the error may result from the fact that the spatial transformation seems to turn the closed polygons into a not really closed one.&lt;/P&gt;
&lt;P&gt;If you test for intersection with the original 4269 SRID you do not get that error (though I can't tell whether the result is correct):&lt;/P&gt;
&lt;PRE&gt;SELECT
   gp.GEOMETRY
   ,zp.GEOMETRY
   ,gp.GEOMETRY.ST_Intersection(zp.GEOMETRY) AS INTERSECTION
FROM Test_GeometryPart gp, Test_GeometryPart zp
WHERE gp.GEO_ID = 43055
   AND zp.GEO_ID = 1485884;
&lt;/PRE&gt;

&lt;HR /&gt;
&lt;P&gt;Another wild guess: When simply viewing the original geometries in the Spatial Viewer with SRID 3857, the second row seems to return an error, at least with 16.0.0.1915 (SQLCODE -1486 "Invalid polygon: ring has zero area (near '%1')").&lt;/P&gt;</description>
      <pubDate>Wed, 19 Nov 2014 03:52:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/spatial-operation-error-using-st-intersection-with-st-transform/qaa-p/13846992#M4877835</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2014-11-19T03:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial operation error using ST_Intersection() with ST_Transform()</title>
      <link>https://community.sap.com/t5/technology-q-a/spatial-operation-error-using-st-intersection-with-st-transform/qaa-p/13846991#M4877834</link>
      <description>&lt;P&gt;One possible cause of this type of error is that the input geometries are invalid.  Checking for invalid geometries is not performed when a geometry is loaded/created.&lt;/P&gt;
&lt;P&gt;From&lt;/P&gt;
&lt;PRE class="codehilite"&gt;&lt;CODE&gt;SELECT
gp.*
,gp.GEOMETRY.ST_IsValid()
,gp.GEOMETRY.ST_Transform(3857) AS GP_3857
,GP_3857.ST_IsValid()
,zp.*
,zp.GEOMETRY.ST_IsValid()
,zp.GEOMETRY.ST_Transform(3857) AS ZP_3857
,zp_3857.ST_IsValid()
//,GP_3857.ST_Intersection(ZP_3857) AS INTERSECTION
FROM Test_GeometryPart gp, Test_GeometryPart zp
WHERE gp.GEO_ID = 43055
AND zp.GEO_ID = 1485884;


&lt;P&gt;Note the zp_3857 is not valid.  From:&lt;/P&gt;
&lt;/CODE&gt;&lt;PRE class="codehilite"&gt;&lt;CODE&gt;&lt;CODE&gt;call st_geometry_dump( 
(SELECT
zp.GEOMETRY.ST_Transform(3857) AS ZP_3857
FROM Test_GeometryPart zp
WHERE zp.GEO_ID = 1485884 ),
'validate=full' )


&lt;P&gt;We can see that:&lt;/P&gt;
&lt;/CODE&gt;&lt;/CODE&gt;&lt;PRE class="codehilite"&gt;&lt;CODE&gt;&lt;CODE&gt;&lt;CODE&gt;Polygon ((-8960237.976 5357495.7335, -8960237.9758 5357495.7332, 
-8960237.9758 5357495.7333, -8960237.976 5357495.7335))


&lt;P&gt;has the error: Curve 0 of polygon is not a ring (near "Polygon ((-8960237.976 5357495.7335, -8960237.9758 5357495.7332, -8960237.9758 5357495.7333, -8960237.976 5357495.7335))")&lt;/P&gt;
&lt;P&gt;Hmm...  This ring looks closed to me (start point is exactly end point).  I will look further.&lt;/P&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/PRE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Nov 2014 10:20:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/spatial-operation-error-using-st-intersection-with-st-transform/qaa-p/13846991#M4877834</guid>
      <dc:creator>ian_mchardy</dc:creator>
      <dc:date>2014-11-19T10:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial operation error using ST_Intersection() with ST_Transform()</title>
      <link>https://community.sap.com/t5/technology-q-a/spatial-operation-error-using-st-intersection-with-st-transform/qaa-p/13846993#M4877836</link>
      <description>&lt;P&gt;Clearly, I'm not a spatial expert either, and your suggestion is just what I needed.  Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Nov 2014 10:21:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/spatial-operation-error-using-st-intersection-with-st-transform/qaa-p/13846993#M4877836</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-11-19T10:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial operation error using ST_Intersection() with ST_Transform()</title>
      <link>https://community.sap.com/t5/technology-q-a/spatial-operation-error-using-st-intersection-with-st-transform/qaa-p/13846994#M4877837</link>
      <description>&lt;P&gt;It looks to me as if, when calculating ZP_3857 the ST_Transform() function breaks the polygon. That is, zp.GEOMETRY is valid but ZP_3857 is not?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Nov 2014 12:34:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/spatial-operation-error-using-st-intersection-with-st-transform/qaa-p/13846994#M4877837</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-11-19T12:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial operation error using ST_Intersection() with ST_Transform()</title>
      <link>https://community.sap.com/t5/technology-q-a/spatial-operation-error-using-st-intersection-with-st-transform/qaa-p/13846995#M4877838</link>
      <description>&lt;P&gt;Agreed that before the ST_Transform the geometry is reported as valid and after the ST_Transform it is not valid.  We are looking further.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Nov 2014 12:41:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/spatial-operation-error-using-st-intersection-with-st-transform/qaa-p/13846995#M4877838</guid>
      <dc:creator>ian_mchardy</dc:creator>
      <dc:date>2014-11-19T12:41:10Z</dc:date>
    </item>
  </channel>
</rss>

