0

I'm trying to cast a geography Polygon to a MultiPolygon resulting from a 'geographic' intersection with a circle on Earth of a 10'000m radius, but PostGIS is raising this error when using ST_Multi on that resulting Polygon:

ERROR:  function st_multi(geography) does not exist
LINE 2:  ST_Multi(
         ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883
Character: 15

The message is not 100% clear to me, because ST_Multi does exist as I successfully used it on many other queries on that same database.

So, I have the feeling that it is simply not able to work on a 'geography' polygon (or maybe the error lies somewhere else?).

Here's a minimal reproducible code snippet (postgis 3.1 / postgres 13.1):

SELECT CAST(
  ST_Multi(
    ST_Intersection(
      ST_Simplify(
        ST_MakePolygon(
          ST_Force2D(
            ST_GeomFromGeoJSON(
              '{"type":"LineString",
              "coordinates":[
                  [8,48,45],
                  [8.1,47.2,45],
                  [8.2,47.3,45],
                  [8,48,45]
                ],
              "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'
            )
          )
        ),
        0.001
      ),
      ST_buffer(
        ST_SetSRID(
          CAST(ST_MakePoint(8.1, 47.2) AS GEOGRAPHY), '4326'),
        10000
      )
    )
  ) AS GEOMETRY
);

How would you cast a Polygon to a MultiPolygon in that particular case?

1
  • 1
    This is even more minimal and works with geography: SELECT ST_AsEWKT(ST_Multi(ST_Buffer(ST_GeomFromText('POINT (1 1)',4326),0.1))::geography); – user30184 Mar 25 at 18:42
0

I figure out that apparently, ST_Multi does not appreciate to work on a geography feature.

Therefore, I actually have to use ST_Multi after casting the geography to a proper geometry feature (i.e. outside the cast function, and not inside).

This is working:

SELECT ST_Multi(
  CAST(
    ST_Intersection(
      ST_Simplify(
        ST_MakePolygon(
          ST_Force2D(
            ST_GeomFromGeoJSON(
              '{"type":"LineString",
              "coordinates":[
                  [8,48,45],
                  [8.1,47.2,45],
                  [8.2,47.3,45],
                  [8,48,45]
                ],
              "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'
            )
          )
        ),
        0.001
      ),
      ST_buffer(
        ST_SetSRID(
          CAST(ST_MakePoint(8.1, 47.2) AS GEOGRAPHY), '4326'),
        10000
      )
    ) AS GEOMETRY
  )
);

And if I encapsulate all this into ST_GeometryType it successfully tells:

st_geometrytype (text)
"ST_MultiPolygon"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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