Esri / spatial-framework-for-hadoop

The Spatial Framework for Hadoop allows developers and data scientists to use the Hadoop data processing system for spatial data analysis.
Apache License 2.0
363 stars 160 forks source link

ST_Area returns negative values #110

Closed chaosmail closed 7 years ago

chaosmail commented 7 years ago

Hi guys,

When computing the Area of a single Polygon as MultiPolygon, the resulting area is negative.

SELECT
  ST_Area(ST_MultiPolygon(array(0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0)))
FROM src LIMIT 1;

>OK
> -1.0
> Time taken: 3.583 seconds, Fetched: 1 row(s)

When using a Polygon, it is working properly.

SELECT
  ST_Area(ST_Polygon(0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0))
FROM src LIMIT 1;
> OK
> 1.0
> Time taken: 0.845 seconds, Fetched: 1 row(s)

Best, Christoph

randallwhitman commented 7 years ago

Thanks for reporting this - will need looking into. Also, I have reproduced the reported output.

randallwhitman commented 7 years ago

Contrast:

select ST_Area(ST_MultiPolygon('multipolygon(((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 1.0, 0.0 0.0)))')); 1.0 select ST_Area(ST_MultiPolygon(array(0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0))); 1.0

randallwhitman commented 7 years ago

In ST_Polygon, we obviate ordering/orientation issues constructing from number pairs, by generating WKT. We could do the same in ST_MultiPolygon. comments @climbage ?

climbage commented 7 years ago

Seems reasonable

randallwhitman commented 7 years ago

Also, ST_MultiPolygon erroneously sets y=x for the first point listed.

select ST_AsText(ST_MultiPolygon(array(0.0, 1.0, 1.0, 1.0, 1.0, 0.0))); MULTIPOLYGON (((0 0, 1 0, 1 1, 0 0)))