Comments (4)
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.
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.
@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.
I guess this was fixed in #47 .
from pycrs.
Related Issues (20)
- Exception: The specified projection name 'Meter' could not be found HOT 3
- Exception: 'Unknown' object has no attribute 'metermultiplier' HOT 1
- Support 'Lambert_Conformal_Conic_2SP' HOT 2
- Why can't parse 3857? HOT 4
- Why can't parse 3857? HOT 2
- How to parse '{"proj": "aea", "lat_1": 25, "lat_2": 47, "lat_0": 0, "lon_0": 105, "x_0": 0, "y_0": 0, "datum": "WGS84", "units": "m", "no_defs": true}' HOT 9
- Point transform issue HOT 12
- Update to epsg.io as the source for crs codes HOT 2
- BUG: proj4 parser is case sensitive HOT 1
- CRS equality operator HOT 1
- How to get EPSG code from Shapefile? HOT 11
- Error in proj4 format in conversion from WKT to Proj4
- Parser issue
- Unable to get projection from EPSG HOT 1
- prj2epsg.org seems out of service HOT 2
- the specified projection name 'Gauss_Kruger' could not be found in the list of supported projections HOT 3
- Add CF projection conversion
- Release as Python 3 source wheel on PyPI? HOT 1
- Whats up?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pycrs.