0

I have a file in British National Grid coordinates (EPSG 27700) which I'm trying to convert to WGS84 (EPSG 4326)

My first attempt was to transform in the usual way

import geopandas as gpd
file = '27700.gpkg'
sh = gpd.read_file(file)
sh = sh.to_crs(epsg = 4326)
sh.to_file('out')

Now this runs just fine, but when I open the resulting file in QGIS I see that the files in fact do not overlap!

The only reason I can think of is that the re projection used by QGIS is different than the one used by pyproj.

I then tried all reprojections available for pyproj as follows

from pyproj.transformer import TransformerGroup
import geopandas as gpd
import numpy as np
from functools import partial
from shapely.geometry import Point
from shapely.ops import transform


trans_group = TransformerGroup("epsg:27700","epsg:4326")

#you can see there are multiple trasnsformers possible
print(trans_group)


file = '27700'
sh = gpd.read_file(file)


i=0
for i in np.arange(len(trans_group.transformers)):
 transformer = partial(transform, trans_group.transformers[i].transform)
 sh_new = sh.copy()
 sh_new.set_geometry(sh.geometry.apply(transformer),  inplace=True, crs = 4326)

 sh_new['geometry'] = sh_new.geometry.apply(swap_xy)

 sh_new.to_file('out' + str(i))    

But when opening these output files in QGIS non of them matched!

I also tried ogr2ogr

ogr2ogr out.gpkg -t_srs "EPSG:4326" in.gpkg

Again the output file does not match the input file.

Can there be some reason why my pyproj uses a wrong formula? Is there anyway to update the projection formulas that my pyproj is using?

In this image you can see that the original and new file indeed do not fully overlap (one is in red the other in gray) enter image description here

1
  • 2
    Could it be that either your pyproj or your QGIS is using a gridshift file that the other system does not have, and therefore they select different transformations?
    – user30184
    Commented Nov 11, 2022 at 8:27

1 Answer 1

1

user30184 is right. My Proj instalation was missing a grid file. Placing that in the data folder solved the problem!

cd /.local/lib/python3.8/site-packages/pyproj/proj_dir/share/proj

wget https://cdn.proj.org/uk_os_OSTN15_NTv2_OSGBtoETRS.tif

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.