Geographic Information Systems Asked on April 29, 2021
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?
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" |
Answered by s.k on April 29, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP