Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter precision of transform_geom() not working for GeometryCollections #971

Open
SaCodematix opened this issue Oct 19, 2020 · 2 comments
Labels
Milestone

Comments

@SaCodematix
Copy link

SaCodematix commented Oct 19, 2020

I do get the error local variable 'new_coords' referenced before assignment when I call transform.transform_geom() with an indicated value for the optional precision parameter other than the default value of -1.

Expected behavior and actual behavior.

I expected to be able to transform a GeometryCollection with the precision of 3 decimal places through the optional parameter precision of transform.transform_geom().

Steps to reproduce the problem.

from fiona import transform

source_crs = "epsg:25832"
dest_src = "epsg:4326"
geom =  {'type': 'GeometryCollection', 'geometries': [{'type': 'LineString', 'coordinates': [(512381.8870945257, 5866313.311218272), (512371.23869999964, 5866322.282500001), (512364.6014999999, 5866328.260199999)]}]}

geom_transformed = transform.transform_geom(source_crs, dest_src, geom)
print("Transformed geom without optional parameter 'precision':", geom_transformed, "\n")

geom_transformed = transform.transform_geom(source_crs, dest_src, geom, precision=-1)
print("Transformed geom with optional default parameter 'precision=-1':", geom_transformed, "\n")

geom_transformed = transform.transform_geom(source_crs, dest_src, geom, precision=3)
print("Transformed geom with optional parameter 'precision=3':", geom_transformed)

Output:

# python3 transform_geom_test.py
Transformed geom without optional parameter 'precision': {'type': 'GeometryCollection', 'geometries': [{'type': 'LineString', 'coordinates': [(9.184271907836777, 52.94630492951154), (9.184113777710168, 52.94638582212857), (9.184015228795353, 52.9464397114269)]}]} 

Transformed geom with optional default parameter 'precision=-1': {'type': 'GeometryCollection', 'geometries': [{'type': 'LineString', 'coordinates': [(9.184271907836777, 52.94630492951154), (9.184113777710168, 52.94638582212857), (9.184015228795353, 52.9464397114269)]}]} 

Traceback (most recent call last):
  File "transform_geom_test.py", line 16, in <module>
    geom_transformed = transform.transform_geom(source_crs, dest_src, geom, precision=3)
  File "/home/sa/anaconda3/envs/wind/lib/python3.8/site-packages/fiona/transform.py", line 92, in transform_geom
    return _transform_geom(
  File "fiona/_transform.pyx", line 220, in fiona._transform._transform_geom
UnboundLocalError: local variable 'new_coords' referenced before assignment

Operating system

Linux Mint 19.3 (Tricia, Ubuntu Bionic)

Fiona and GDAL version and provenance

installed via conda:
Fiona 1.8.17
GDAL 3.1.3
Python 3.8.5

@rbuffat
Copy link
Contributor

rbuffat commented Oct 19, 2020

It looks like the precision parameter does not support "GeometryCollection": https://github.com/Toblerity/Fiona/blob/master/fiona/_transform.pyx#L166-L220

@SaCodematix
Copy link
Author

You are right, @rbuffat, thanks for the hint of this code snippet!
I implemented the rounding myself now, but it would be nice to be able to use this optional precision parameter for GeometryCollections in future releases or at least have a more precise error message :)

@SaCodematix SaCodematix changed the title Parameter precision not working for transform_geom() Parameter precision of transform_geom() not working for GeometryCollections Oct 19, 2020
@rbuffat rbuffat mentioned this issue Nov 17, 2020
@sgillies sgillies added the bug label Nov 17, 2020
@sgillies sgillies added this to the 1.8.18 milestone Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants