<p dir="ltr">### Answer:</p>
<p dir="ltr">To detect if an SRID refers to a **geodetic (geographic) CRS** in PostGIS, here are the best approaches:</p>
<p dir="ltr">---</p>
<p dir="ltr">### 1) **Checking if `srtext` starts with "GEOGCS"?** <br>
While `srtext` for geodetic CRSs (e.g., WGS84) starts with `GEOGCS` in its WKT definition (e.g., `GEOGCS["WGS 84", ...]`), this method has caveats: <br>
- **It’s not foolproof**: The `srtext` format can vary (e.g., whitespace, custom definitions). <br>
- **Not future-proof**: Relies on text parsing, which may break if WKT conventions change. </p>
<p dir="ltr">Example query (works in most cases, but not fully robust): <br>
```sql <br>
SELECT srid, srtext <br>
FROM spatial_ref_sys <br>
WHERE srtext LIKE 'GEOGCS%'; -- Filters geodetic CRSs<br>
```</p>
<p dir="ltr">---</p>
<p dir="ltr">### 2) **Use the built-in PostGIS function `ST_IsGeographic()`** ✅ <br>
PostGIS provides **`ST_IsGeographic(srid)`** to directly check if an SRID is geodetic. This is the **recommended method** because: <br>
- It uses PostGIS’s internal logic (no text parsing). <br>
- Handles edge cases and custom definitions. </p>
<p dir="ltr">**Examples:** <br>
```sql <br>
SELECT ST_IsGeographic(4326); -- Returns TRUE (WGS84, geodetic) <br>
SELECT ST_IsGeographic(3857); -- Returns FALSE (Web Mercator, projected) <br>
```</p>
<p dir="ltr">**To find all geodetic SRIDs:** <br>
```sql <br>
SELECT srid, auth_name, srtext <br>
FROM spatial_ref_sys <br>
WHERE ST_IsGeographic(srid) = TRUE; <br>
```</p>
<p dir="ltr">---</p>
<p dir="ltr">### Key Takeaways: <br>
- **Avoid parsing `srtext`**: Use `ST_IsGeographic()` for reliability. <br>
- **Works in PostGIS 2.2+**: Ensure your PostGIS version supports this function. </p>
<p dir="ltr">Let me know if you need further details! 😊</p>
<br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">Le mar. 29 avr. 2025, 22:55, Pettycash dev <<a href="mailto:alphonseessomba60@gmail.com">alphonseessomba60@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Pour répondre à vos questions sur la détection des SRID géodésiques dans PostGIS :</p>
<p dir="ltr">### 1) Vérifier si `srtext` commence par "GEO" ?<br>
**Non, ce n'est pas une méthode fiable.** <br>
Les CRS géodésiques (sphère/ellipsoïde) sont représentés en WKT par `GEOGCS` (ex: `GEOGCS["WGS 84", ...]`). Bien que "GEO" soit présent, il est préférable de vérifier **`srtext LIKE 'GEOGCS%'`** pour éviter les faux positifs. Cependant, cette approche reste fragile (format WKT variable, entrées personnalisées).</p>
<p dir="ltr">---</p>
<p dir="ltr">### 2) Existe-t-il une fonction PostGIS dédiée ?<br>
**Oui, utilisez `ST_IsGeographic(srid)`** (disponible depuis PostGIS 2.2). <br>
Cette fonction retourne **`true`** si le SRID correspond à un CRS géographique (géodésique), et **`false`** pour un CRS projeté ou inconnu.</p>
<p dir="ltr">**Exemple d'utilisation :**<br>
```sql<br>
SELECT ST_IsGeographic(4326); -- Retourne true (WGS84 géodésique)<br>
SELECT ST_IsGeographic(3857); -- Retourne false (Web Mercator projeté)<br>
```</p>
<p dir="ltr">---</p>
<p dir="ltr">### Solution recommandée :<br>
```sql<br>
-- Vérifier directement via ST_IsGeographic()<br>
SELECT srid, auth_name, srtext <br>
FROM spatial_ref_sys <br>
WHERE ST_IsGeographic(srid) = true;<br>
```</p>
<p dir="ltr">Cette méthode est **plus robuste** que l'analyse de `srtext` ou `proj4text`, car elle s'appuie sur la logique interne de PostGIS.</p>
<br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mar. 29 avr. 2025, 22:45, Richard Huesken <<a href="mailto:richard.huesken@gmail.com" target="_blank" rel="noreferrer">richard.huesken@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I'm wondering if there is an easy way to detect if an srid refers to a geodetic CRS, by checking the spatial_ref_sys table.</div><div><br></div><div>1) Would it be safe to assume the srid is a geodetic CRS if the value in the srtext column starts with 'GEO'? It almost seems to be too good to be true...</div><div><br></div><div>2) Did I overlook a Postgis function that returns this information (and if so, which one would that be)?</div><div><br></div><div>Thanks in advance,</div><div><br></div><div>Kind regards</div><div>Richard.</div></div>
</blockquote></div>
</blockquote></div>