2

I'm building an API where user can insert a number (3857, 27700,etc.) and my API will give the projected bounds. I'm using pyproj's

crs_number = 27700    
crs_custom = CRS.from_user_input(crs_number)
crs_custom.area_of_use.bounds

this function is giving me bounds but it is showing bounds like

-8.82,49.79,1.92,60.94

instead of

-90619.29,10097.13,612435.55,1234954.16

How do I get the expected bounds?

3
  • The area_of_use.bounds are in WGS84 so that property is consistent across all CRSs, so just project them to your target if that's what you're looking for
    – mikewatt
    Mar 19, 2021 at 20:00
  • How can I project? Mar 19, 2021 at 20:00
  • There are examples in the docs: pyproj4.github.io/pyproj/stable/…
    – mikewatt
    Mar 19, 2021 at 20:40

1 Answer 1

1

Here is simple solution following the @mikewatt advise

from pyproj import CRS, Transformer

in_crs = CRS.from_epsg(4326)
out_crs = CRS.from_epsg(3857)
x_min, y_min, x_max, y_max = out_crs.area_of_use.bounds

Then project your bottom left corner and top right corner in the output crs :

proj = Transformer.from_crs(4326, 3857, always_xy=True)
bl = proj.transform(x_min, y_min)
tr = proj.transform(x_max, y_max)

Edit

Following this question I asked on github and thanks to @snowman you can use :

from pyproj import CRS, Transformer

crs = CRS("EPSG:3857")
transformer = Transformer.from_crs(crs.geodetic_crs, crs, always_xy=True)
transformer.transform_bounds(*crs.area_of_use.bounds)

you can find the issue and the PR on github.

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.