2

I'm building a UI that lets users draw areas (polygons) on a MapboxGL element. I want to compare those areas to an existing data set I have in PostGIS, however, I cannot seem to get turf and PostGIS to even agree on the total area of the polygon provided by a user:

PostGIS: 14701611.155977905, // query: ST_Area(ST_GeomFromGeoJSON(:aoi), true)
Turf: 14799215.578582546 // `turf.area(geometry)`

I'm struggling a little bit with understanding what's happening here. My hunch is it has something to do with projections, but I've been banging my head against the wall for a good hour to no effect... What is wrong here?

The geometry:

{
      "type": "Polygon",
      "coordinates": [
        [
          [
            -69.064776,
            4.981217,
            0
          ],
          [
            -69.069477,
            4.984136,
            0
          ],
          [
            -69.073963,
            4.989301,
            0
          ],
          [
            -69.074252,
            4.98981,
            0
          ],
          [
            -69.07699,
            4.988452,
            0
          ],
          [
            -69.079889,
            4.987015,
            0
          ],
          [
            -69.081971,
            4.983309,
            0
          ],
          [
            -69.083359,
            4.980838,
            0
          ],
          [
            -69.083552,
            4.979404,
            0
          ],
          [
            -69.084036,
            4.975821,
            0
          ],
          [
            -69.085744,
            4.971048,
            0
          ],
          [
            -69.084575,
            4.969083,
            0
          ],
          [
            -69.083114,
            4.966626,
            0
          ],
          [
            -69.083623,
            4.962135,
            0
          ],
          [
            -69.083201,
            4.962047,
            0
          ],
          [
            -69.081252,
            4.961794,
            0
          ],
          [
            -69.080878,
            4.961746,
            0
          ],
          [
            -69.079933,
            4.961623,
            0
          ],
          [
            -69.078147,
            4.961391,
            0
          ],
          [
            -69.06858,
            4.960149,
            0
          ],
          [
            -69.066451,
            4.959873,
            0
          ],
          [
            -69.066256,
            4.959847,
            0
          ],
          [
            -69.061958,
            4.959289,
            0
          ],
          [
            -69.061057,
            4.959172,
            0
          ],
          [
            -69.058629,
            4.958857,
            0
          ],
          [
            -69.039705,
            4.956401,
            0
          ],
          [
            -69.038326,
            4.956222,
            0
          ],
          [
            -69.029772,
            4.955111,
            0
          ],
          [
            -69.028812,
            4.954987,
            0
          ],
          [
            -69.028857,
            4.955197,
            0
          ],
          [
            -69.028861,
            4.955221,
            0
          ],
          [
            -69.029493,
            4.958833,
            0
          ],
          [
            -69.029578,
            4.959319,
            0
          ],
          [
            -69.029206,
            4.959969,
            0
          ],
          [
            -69.028607,
            4.961016,
            0
          ],
          [
            -69.02801,
            4.962059,
            0
          ],
          [
            -69.02773,
            4.962549,
            0
          ],
          [
            -69.027644,
            4.962699,
            0
          ],
          [
            -69.027489,
            4.963268,
            0
          ],
          [
            -69.026686,
            4.966215,
            0
          ],
          [
            -69.026553,
            4.966704,
            0
          ],
          [
            -69.026652,
            4.967636,
            0
          ],
          [
            -69.026674,
            4.967843,
            0
          ],
          [
            -69.027058,
            4.971459,
            0
          ],
          [
            -69.030307,
            4.975713,
            0
          ],
          [
            -69.033587,
            4.978177,
            0
          ],
          [
            -69.034227,
            4.978636,
            0
          ],
          [
            -69.036922,
            4.977719,
            0
          ],
          [
            -69.042902,
            4.976175,
            0
          ],
          [
            -69.049287,
            4.975202,
            0
          ],
          [
            -69.054334,
            4.976761,
            0
          ],
          [
            -69.056742,
            4.976344,
            0
          ],
          [
            -69.060258,
            4.977912,
            0
          ],
          [
            -69.064776,
            4.981217,
            0
          ]
        ]
      ]
    }
0

1 Answer 1

2

This answer might help you

Just to be clear it is difficult to get the exact same result when calculating areas with methods from different toolboxes. They might use different constants and/or as you mentioned different projections

2
  • So... that's... very confusing for users haha. I've tried the calculation in the answer you linked to (and it indeed produces the same result as PostGIS does), but that means Google Earth, which some of our customers use, shows them a different area than we do... I guess my question is, who's right? PostGIS or Google Earth & Mapbox?
    – Steven
    May 25, 2023 at 12:08
  • That is indeed very confusing and unfortunately my answer will not be any clearer. It all depends on the eye who sees. You could argue that both are correct, the problem only occurs when comparing two measurements that are done differently. Meaning that we are comparing apples with oranges. From experience I try, to the best of my capabilities to limit everything to the same projection and methods so that I never have to compare between different map providers. May 25, 2023 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.