I have two tables in a AWS Postgres server (I am querying using DBeaver).
Table 1 is a shapefile which I imported from an S3 bucket called
uk_counties, which lists a geometry for all counties in the UK (SRID = 27700 - shapefile can be found here).Table 2 is called
demand_originand contains the fieldsorigin_city(places in the UK) and two fieldslatitudeandlongitude(which contains the latitutde and logitudes of places inorigin_city).
By joining uk_counties (the shapefile) and demand_origin, I want to assign a county to the places in the UK by finding where their respective lat longs intersect with the shapefiles for the counties.
The problem is that this join kept appearing empty. After much investigation, it appears that the geometries in the shapefile are mapped to the Gulf of Guinea (in and around lat = 0, long = 0).
See shapefile for Leicester as an example:
My guess here is that the geometries are using northings/westings as opposed to lat/longs, hence PostGIS is mapping these shapes to around lat=0, long=0, and as such potentially needs to be recalibrated.
Here is a snippet of what the geometries look like for Leicester and other counties:
| ctyua23nm | geometry |
|---|---|
| York | POLYGON ((464216.99650000036 462110.9015999995, 464266.20299999975 462093.0965999998, 464270.3008000003 462094.3962999992, 464289.8992999997 4 |
| Derby | POLYGON ((434972.3005999997 341311.7999000009, 434986.3008000003 341310.40029999986, 435000.0536000002 341314.6991000008, 435015.29860000033 3 |
| Cambridgeshire | MULTIPOLYGON (((529832.0997000001 300053.7999000009, 529880.2013999997 300039.1041000001, 529903.7987000002 300036.6048000008, 529914.20399999 |
What's the issue?

FWIW, when I downloaded the Shapefile from the link above, and imported it like so:
I obtain a much different schema:
And I can easily get a correct latitude & longitude value:
It might easier for you to just reimport the Shapefile, as I'm not sure how you've imported it.
If you're stuck with your current schema, please continue.
Correct.
SRID 27700 / EPSG:27700 aligns to the Ordnance Survey National Grid (OSGB) or more commonly known as the British National Grid (BNG). It basically uses projected eastings and northings, which are in metres - not latitude and longitude, which are in degrees.
You can see this by running:
Note
UNIT["metre",AXIS["Easting", EAST]andAXIS["Northing", NORTH].You most likely want to project your data to use SRID 4326 / EPSG:4326, which aligns to WGS84 i.e. the standard for GPS.
It's a 2D geographic coordinate system i.e. uses latitude and longitude.
To project your SRID 27700 table to latitude and longitude coordinates (SRID 4326), firstly verify that the SRID for your
geometrycolumn is set to SRID 27700 usingFind_SRID.The output should be:
If not, set the SRID for the column using
UpdateGeometrySRID:Then, use
ST_Transformfunction in PostGIS to do the conversion:Once done, we can then get latitude & longitudes from the geometry by :
ST_Centroidto get the centroid of the geometry - a pointST_Yfunction to obtain the latitudeST_Xfunction to obtain the longitude.Let's create 2 new columns to store the data:
And then, filling the columns...
Now, you have 2 new columns:
latitudelongitudeThe new columns should have correct values:
And last but not least, to come full circle with the Leicester example...
Here's Leicester!