Skip to content

Commit

Permalink
Avoid printing representations of NULL objects (#1445)
Browse files Browse the repository at this point in the history
* Avoid printing representations of NULL objects

Resolves #1444

* Update change log
  • Loading branch information
sgillies authored Sep 14, 2024
1 parent bf841d7 commit d3ec687
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 18 deletions.
9 changes: 7 additions & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ Changes

All issue numbers are relative to https://github.com/Toblerity/Fiona/issues.

Next (TBD)
----------
1.10.1 (TBD)
------------

Bug fixes:

- Logging in the CRS class no longer tries to print representations of NULL
objects when searching for authority matches (#1445).

1.10.0 (2024-09-03)
-------------------
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PYTHON_VERSION ?= 3.10
GDAL ?= ubuntu-small-3.9.0
PYTHON_VERSION ?= 3.12
GDAL ?= ubuntu-small-3.9.2
all: deps clean install test

.PHONY: docs
Expand Down
19 changes: 5 additions & 14 deletions fiona/crs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -487,31 +487,25 @@ cdef class CRS:
cdef int *confidences = NULL
cdef int num_matches = 0
cdef int i = 0
cdef char *c_code = NULL
cdef char *c_name = NULL

results = defaultdict(list)

try:
osr = exc_wrap_pointer(OSRClone(self._osr))

matches = OSRFindMatches(osr, NULL, &num_matches, &confidences)

for i in range(num_matches):
confidence = confidences[i]
c_code = OSRGetAuthorityCode(matches[i], NULL)
c_name = OSRGetAuthorityName(matches[i], NULL)

if c_code == NULL:
log.debug("returned authority code was null")
if c_name == NULL:
log.debug("returned authority name was null")

if c_code != NULL and c_name != NULL and confidence >= confidence_threshold:
log.debug(
"Matched. confidence=%r, c_code=%r, c_name=%r",
confidence, c_code, c_name)
code = c_code.decode('utf-8')
name = c_name.decode('utf-8')
results[name].append(code)

return results

finally:
Expand Down Expand Up @@ -966,23 +960,20 @@ cdef class CRS:
cdef int *confidences = NULL
cdef int num_matches = 0
cdef int i = 0
cdef char *c_code = NULL
cdef char *c_name = NULL

results = defaultdict(list)

try:
osr = exc_wrap_pointer(OSRClone(self._osr))

matches = OSRFindMatches(osr, NULL, &num_matches, &confidences)

for i in range(num_matches):
confidence = confidences[i]
c_code = OSRGetAuthorityCode(matches[i], NULL)
c_name = OSRGetAuthorityName(matches[i], NULL)

log.debug(
"Matched. confidence=%r, c_code=%r, c_name=%r",
confidence, c_code, c_name)

if c_code != NULL and c_name != NULL and confidence >= confidence_threshold:
code = c_code.decode('utf-8')
name = c_name.decode('utf-8')
Expand Down
38 changes: 38 additions & 0 deletions tests/test_crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,41 @@ def test_to_wkt__invalid_version():
def test_from_func_deprecations(func, arg):
with pytest.warns(FionaDeprecationWarning):
_ = func(arg)


def test_xx():
"""Create a CRS from WKT with a vertical datum."""
wkt = """
COMPD_CS["NAD83(CSRS) / UTM zone 10N + CGVD28 height",
PROJCS["NAD83(CSRS) / UTM zone 10N",
GEOGCS["NAD83(CSRS)",
DATUM["NAD83_Canadian_Spatial_Reference_System",
SPHEROID["GRS 1980",6378137,298.257222101,
AUTHORITY["EPSG","7019"]],
AUTHORITY["EPSG","6140"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4617"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",-123],
PARAMETER["scale_factor",0.9996],
PARAMETER["false_easting",500000],
PARAMETER["false_northing",0],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AXIS["Easting",EAST],
AXIS["Northing",NORTH],
AUTHORITY["EPSG","3157"]],
VERT_CS["CGVD28 height",
VERT_DATUM["Canadian Geodetic Vertical Datum of 1928",2005,
AUTHORITY["EPSG","5114"]],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AXIS["Gravity-related height",UP],
AUTHORITY["EPSG","5713"]]]
"""
val = crs.CRS.from_wkt(wkt)
assert val.wkt.startswith("COMPD_CS")

0 comments on commit d3ec687

Please sign in to comment.