How the ST_SetSRID Tool works, and what it assumes
ST_SetSRID attaches a spatial reference id to a geometry and changes nothing else: the coordinates are exactly the same numbers afterwards. It is a statement about what those numbers already mean. The tool writes the result as EWKT, SRID=27700;POLYGON (...), or as the SQL that does the same in PostGIS (ST_SetSRID(ST_GeomFromText(...), 27700)) or SQL Server (geometry::STGeomFromText(..., 27700)), with quotes in the WKT escaped for SQL.
Because the statement can be wrong, the tool checks it where it can, using the offline EPSG subset. A geographic SRID on coordinates outside the degree range is reported as a problem; a projected SRID on coordinates that all look like degrees gets a warning, since they would be read as metres a few steps from the projection's origin. For a projected SRID, the middle of the geometry is converted to longitude and latitude with that system's definition, so you can see whether it lands where the data belongs. The output itself is never transformed.
If what you need is different numbers, not a different label, the tool is ST_Transform. Confusing the two is one of the most common spatial database mistakes: setting SRID 4326 on British National Grid metres puts a site in London somewhere off the edge of the world.
Where this comes up in GIS work
- Preparing an INSERT for a geometry column that has a declared SRID.
- Fixing data loaded with SRID 0 by labelling it with the system it is really in.
- Catching the mistake of setting 4326 on coordinates that are metres, or a projected SRID on degrees.
- Turning plain WKT into EWKT for a tool or API that expects the SRID prefix.
A worked example
The example is a rectangle in British National Grid metres:
Input: POLYGON ((530060 180380, 530320 180380, 530320 180560, 530060 180560, 530060 180380))
SRID: 27700
Output: SRID=27700;POLYGON ((530060 180380, 530320 180380, 530320 180560, 530060 180560, 530060 180380))
The check places its middle at 51.50817, -0.12544, beside Charing Cross in central London, which fits the system's area of use. Set 4326 on the same numbers instead and the tool reports that 530,060 cannot be a longitude.
Using the ST_SetSRID Tool
- Paste a geometry as WKT, EWKT or GeoJSON, or select Load example.
- Enter the SRID the coordinates are already in, such as 4326 or 27700.
- Choose the output: EWKT, PostGIS SQL or SQL Server SQL.
- Select Set SRID, or press Ctrl + Enter (Cmd + Enter on a Mac).
- Read the checks below the output, then copy or download it.
When the output looks wrong
- The SRID is geographic but the coordinates reach hundreds of thousands
- The coordinates are metres in a projected system, not degrees, so labelling them 4326 would put them off the edge of the world. Find the system they came from with the EPSG Lookup and set that SRID instead.
- Every coordinate here looks like degrees
- You set a projected SRID on longitude and latitude. ST_SetSRID does not convert anything, so the degrees would be read as a few metres from the projection's origin. Set 4326, then use ST_Transform to reach the projected system.
- EPSG code not in the offline dataset
- The SRID is still set exactly as entered, but its units and area could not be checked. Make sure your database's spatial_ref_sys table has the code, or the insert will fail.
Questions about the ST_SetSRID Tool
What is the difference between ST_SetSRID and ST_Transform?
ST_SetSRID only labels a geometry: the numbers stay the same and you are stating what system they are in. ST_Transform converts the numbers from one system to another. Using ST_SetSRID where ST_Transform was needed is one of the commonest spatial database mistakes.
What is EWKT?
PostGIS's extended WKT, which puts the SRID in front of the geometry: SRID=4326;POINT (-0.1276 51.5072). ST_GeomFromEWKT reads it, and it is often the simplest way to pass a geometry with its SRID in one string.
What does SRID 0 mean?
Unknown. A geometry with SRID 0 has no coordinate system, so functions that need one, such as ST_Transform, refuse it until an SRID is set.
How is the location check done?
For a projected SRID, the middle of the geometry is converted to longitude and latitude with that system's definition, so you can see whether it lands where the data should be. It is a sanity check on the SRID, not a transformation of the output.
Is my data uploaded?
No. Everything runs in your browser.