Coder Social home page Coder Social logo

Comments (7)

idanmiara avatar idanmiara commented on June 5, 2024 1

@idanmiara Could you explain what I'm doing differently in my comment above where I do as you suggest and it works for me?

Thanks @djhoese, I've must have missed your comment before.
It seems that I've been mistakenly using pyproj.Proj instead of pyproj.CRS (as you did), so now it works.
I will try to make a PR to fix the docs accordingly.

from pyproj.

djhoese avatar djhoese commented on June 5, 2024

@idanmiara Do you have a suggestion of how it should be reworded/updated? Would you be comfortable making a pull request for this? If not, maybe you could post a comment here with the content you want in that section and one of the pyproj maintainers could make the PR.

from pyproj.

idanmiara avatar idanmiara commented on June 5, 2024

Hi @djhoese
I know that proj strings are discouraged and wkt is preferable, so is the following a bug in pyproj or in fiona?

import fiona
import pyproj
from fiona.crs import CRS
from pyproj import Proj

print(f'{fiona.__version__=}')
print(f'{pyproj.__version__=}')

pj = Proj(4326)
pj_str = pj.to_proj4()
wkt_str = pj.to_wkt()

print(f'{pj=}')
print(f'{pj_str=}')
print(f'{wkt_str=}')
print(f'{CRS.from_proj4(pj_str)=}')
print(f'{CRS.from_wkt(wkt_str)=}')  # fails

output:

fiona.__version__='1.9.4.post1'
pyproj.__version__='3.6.1'
pj=<Other Coordinate Operation Transformer: longlat>
Description: PROJ-based coordinate operation
Area of Use:
- undefined
pj_str='+proj=longlat +datum=WGS84 +no_defs'
wkt_str='CONVERSION["PROJ-based coordinate operation",METHOD["PROJ-based operation method: +proj=longlat +datum=WGS84 +no_defs"]]'
CRS.from_proj4(pj_str)=CRS.from_epsg(4326)
ERROR 1: PROJ: internal_proj_crs_get_coordinate_system: Object is not a SingleCRS
Traceback (most recent call last):
  File "fiona/crs.pyx", line 729, in fiona.crs.CRS.from_wkt
  File "fiona/_err.pyx", line 280, in fiona._err.exc_wrap_ogrerr
fiona._err.CPLE_AppDefinedError: PROJ: internal_proj_crs_get_coordinate_system: Object is not a SingleCRS

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 17, in <module>
    print(f'{CRS.from_wkt(wkt_str)=}')  # fails
             ^^^^^^^^^^^^^^^^^^^^^
  File "fiona/crs.pyx", line 731, in fiona.crs.CRS.from_wkt
fiona.errors.CRSError: The WKT could not be parsed. PROJ: internal_proj_crs_get_coordinate_system: Object is not a SingleCRS

from pyproj.

djhoese avatar djhoese commented on June 5, 2024
In [1]: from pyproj import CRS

In [2]: from fiona.crs import CRS as fCRS

In [3]: crs = CRS(4326)

In [4]: fCRS.from_wkt(crs.to_wkt())
Out[4]: CRS.from_epsg(4326)

In [5]: fCRS.from_proj4(crs.to_proj4())
/home/davidh/miniconda3/envs/satpy_py311_2/lib/python3.11/site-packages/pyproj/crs/crs.py:1293: UserWarning: You will likely lose important projection information when converting to a PROJ string from another format. See: https://proj.org/faq.html#what-is-the-best-format-for-describing-coordinate-reference-systems
  proj = self._crs.to_proj4(version=version)
Out[5]: CRS.from_epsg(4326)

from pyproj.

snowman2 avatar snowman2 commented on June 5, 2024

With Fiona 1.9+ and GDAL 3+, the instructions should look similar to rasterio: https://pyproj4.github.io/pyproj/stable/crs_compatibility.html#rasterio

from pyproj.

idanmiara avatar idanmiara commented on June 5, 2024

With Fiona 1.9+ and GDAL 3+, the instructions should look similar to rasterio: https://pyproj4.github.io/pyproj/stable/crs_compatibility.html#rasterio

In the rio example you take a rio wkt and pass it to pyproj:

import rasterio.crs
from pyproj.crs import CRS

with rasterio.Env(OSR_WKT_FORMAT="WKT2_2018"):
    rio_crs = rasterio.crs.CRS.from_epsg(4326)
    proj_crs = CRS.from_wkt(rio_crs.wkt)

which works fine.
But what about the other direction as I did above, why does it fail?

from pyproj.

djhoese avatar djhoese commented on June 5, 2024

@idanmiara Could you explain what I'm doing differently in my comment above where I do as you suggest and it works for me?

from pyproj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.