GithubHelp home page GithubHelp logo

Comments (4)

karimbahgat avatar karimbahgat commented on September 2, 2024

The from_url() argument must point to a url containing a raw string of wkt or proj4. The link you're giving it is some type custom json dictionary specific to prj2epsg.org, and the wkt projection is only described inside the 'wkt' json entry.

You can only use from_url() if the prj2epsg API provides a raw link to the wkt. Otherwise you would have to manually load and parse the json dictionary from the url, and then send the 'wkt' entry to pycrs. Easier would be to parse the crs code 2278 from the link itself and send it to from_epsg().

from pycrs.

dazza-codes avatar dazza-codes commented on September 2, 2024

I'm not familiar with this project and limited for time to contribute a full PR, but maybe this helps a little:

def requests_retry_session(session: requests.Session = None) -> requests.Session:
    if session is None:
        session = requests.Session()
    retry = Retry(
        total=10,
        read=10,
        connect=10,
        backoff_factor=0.3,
        status_forcelist=(500, 502, 504),
    )
    https_adapter = session.get_adapter("https://")
    https_adapter.max_retries = retry
    http_adapter = session.get_adapter("http://")
    http_adapter.max_retries = retry
    return session


def wkt_to_epsg_lookup(wkt: str) -> dict:
    """Well Known Text search for matching EPSG code, using
    http://prj2epsg.org/search.json

    Arguments:
        wkt {str} -- A Well Known Text representation for a CRS

    Returns:
        [dict] -- {'code': str, 'name': str, 'url': str}
        if there is an exact match, otherwise it returns {}
    """
    session = requests_retry_session()
    search_uri = "http://prj2epsg.org/search.json"
    query = {"mode": "wkt", "terms": wkt}
    response = session.get(search_uri, params=query, timeout=60)

    if response.status_code == requests.codes.ok:
        epsg = response.json()
    else:
        logging.error("prj2epsg search error %s - %s", response.status_code, query)
        epsg = {}

    if epsg.get("exact"):
        return epsg["codes"][0]
    return {}

LMK if something like that could be a useful PR of some form and where that code might slot into PyCRS (there are some pytest tests for this that also use PyVCR to record the HTTP traffic).

from pycrs.

karimbahgat avatar karimbahgat commented on September 2, 2024

@darrenleeweber that would actually be a good addition. PyCRS currently can parse an EPSG code and output to some other form, but not the opposite, ie outputting to the (most likely) EPSG code, as your code above does.

If you submit a PR I would gladly merge it! My only requests:

  • Remove the dependency on 'requests' + the retry function. The same can be achieved with the builtin urllib, and we don't need the retry functionality.
  • I would probably add it as a 'wkt_to_epsg()' function in 'utils.py'.

Later I could then probably add a 'to_epsg()' method to the toplevel CRS class that calls on this utils function.

from pycrs.

karimbahgat avatar karimbahgat commented on September 2, 2024

I guess this was fixed in #47 .

from pycrs.

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.