Home  Postgress   Srid 4326 a ...

SRID 4326 and WGS 84 in Postgress

Let's use a common example to show how SRID 4326 works with PostGIS.

Imagine you want to store the location of the famous Eiffel Tower in your PostGIS database.


1. Defining the Location Data (WGS 84 Coordinates)

The real-world, GPS-friendly location of the Eiffel Tower is:

These two numbers (48.8584 and 2.2945) are meaningless to the computer on their own. The database needs the SRID 4326 code to understand what they represent.


2. Storing the Data in PostGIS

When you insert this data into a table (let's call it landmarks), you use a PostGIS function that attaches the $\text{SRID 4326}$ to the coordinates:

SQL FunctionExplanation
ST_MakePoint(2.2945, 48.8584)This creates a $\text{POINT}$ geometry object from the longitude and latitude. (Note: PostGIS traditionally lists Longitude first, then Latitude.)
ST_SetSRID(..., 4326)This wraps the $\text{POINT}$ and specifically stamps it with the $\text{4326}$ code, telling the database: "This is a GPS coordinate (WGS 84) in degrees."

The command to insert the location looks like this:

INSERT INTO landmarks (name, location)
VALUES (
    'Eiffel Tower',
    ST_SetSRID(ST_MakePoint(2.2945, 48.8584), 4326)
);

What the Database Sees:

The $\text{location}$ column now holds a piece of data that looks something like this (in $\text{Well-Known Text}$ format):

$$\text{SRID=4326;POINT(2.2945 48.8584)}$$


3. Using the SRID for Calculation

Because the database knows the data is in $\text{SRID 4326}$, you can perform highly accurate geographic calculations.

For example, to calculate the distance from the Eiffel Tower to another point (say, the Louvre Museum at $2.3376^{\circ}$ $\text{E}$, $48.8606^{\circ}$ $\text{N}$) and get the result in meters, PostGIS knows exactly how to convert the WGS 84 degrees into a metric distance:

SELECT
    ST_Distance(
        eiffel.location,
        ST_SetSRID(ST_MakePoint(2.3376, 48.8606), 4326)
    ) AS distance_in_meters
FROM
    landmarks eiffel
WHERE
    eiffel.name = 'Eiffel Tower';

-- RESULT: Approximately 3880 meters (or 3.88 km)
Published on: Sep 30, 2025, 08:56 AM  
 

Comments

Add your comment