Skip to content

ST_Centroid results are wrong for tiny geometries #10629

@mbasmanova

Description

@mbasmanova

ST_Centroid for tiny polygon returns POINT EMPTY and for multi-polygon containing tiny polygon fails with This operation should not be performed on an empty geometry. In some cases, ST_Centroid for a small polygon returns POINT (Infinity -Infinity)

presto> SELECT
    st_area(
        st_geometryfromtext(
            'POLYGON ((4.903234300000006 52.08474289999999, 4.903234265193165 52.084742934806826, 4.903234299999999 52.08474289999999, 4.903234300000006 52.08474289999999))'
        )
    ) as area,
    st_centroid(
        st_geometryfromtext(
            'POLYGON ((4.903234300000006 52.08474289999999, 4.903234265193165 52.084742934806826, 4.903234299999999 52.08474289999999, 4.903234300000006 52.08474289999999))'
        )
    ) as centroid;

         area          |  centroid
-----------------------+-------------
 1.082013892276825E-22 | POINT EMPTY

presto> SELECT st_centroid(
        st_geometryfromtext(
            'MULTIPOLYGON (((4.903234300000006 52.08474289999999, 4.903234265193165 52.084742934806826, 4.903234299999999 52.08474289999999, 4.903234300000006 52.08474289999999)))'
        )
    );

Query 20180517_043212_54343_7a5m9 failed: This operation should not be performed on an empty geometry.
com.esri.core.geometry.GeometryException: This operation should not be performed on an empty geometry.
        at com.esri.core.geometry.Point.getX(Point.java:186)
        at com.facebook.presto.plugin.geospatial.GeoFunctions.computeMultiPolygonCentroid(GeoFunctions.java:914)
        at com.facebook.presto.plugin.geospatial.GeoFunctions.stCentroid(GeoFunctions.java:193)

presto> SELECT
    st_area(
        st_geometryfromtext(
            'POLYGON ((-81.0387349 29.20822, -81.039974 29.210597, -81.0410331 29.2101579, -81.0404758 29.2090879, -81.0404618 29.2090609, -81.040433 29.209005, -81.0404269 29.208993, -81.0404161 29.2089729, -81.0398001 29.20779, -81.0387349 29.20822), (-81.0404229 29.208986, -81.04042 29.2089809, -81.0404269 29.208993, -81.0404229 29.208986)))'
        )
    ) AS area,
    st_centroid(
        st_geometryfromtext(
            'POLYGON ((-81.0387349 29.20822, -81.039974 29.210597, -81.0410331 29.2101579, -81.0404758 29.2090879, -81.0404618 29.2090609, -81.040433 29.209005, -81.0404269 29.208993, -81.0404161 29.2089729, -81.0398001 29.20779, -81.0387349 29.20822), (-81.0404229 29.208986, -81.04042 29.2089809, -81.0404269 29.208993, -81.0404229 29.208986)))'
        )
    ) AS centroid;

         area         |          centroid
----------------------+----------------------------
 3.056987905009077E-6 | POINT (Infinity -Infinity)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions