Skip to content
Commits on Source (4)
......@@ -3,8 +3,17 @@ Changes
All issue numbers are relative to https://github.com/Toblerity/Fiona/issues.
1.8.3 (TBD)
-----------
1.8.4 (2018-12-10)
------------------
- 3D geometries can now be transformed with a specified precision (#523).
- A bug producing a spurious DriverSupportError for Shapefiles with a "time"
field (#692) has been fixed.
- Patching of the GDAL_DATA environment variable was accidentally left in place
in 1.8.3 and now has been removed.
1.8.3 (2018-11-30)
------------------
- The RASTERIO_ENV config environment marker this project picked up from
Rasterio has been renamed to FIONA_ENV (#665).
......
fiona (1.8.4-1) unstable; urgency=medium
* Team upload.
* New upstream release.
-- Bas Couwenberg <sebastic@debian.org> Tue, 11 Dec 2018 09:48:55 +0100
fiona (1.8.3-1) unstable; urgency=medium
* Team upload.
......
......@@ -101,7 +101,7 @@ import uuid
__all__ = ['bounds', 'listlayers', 'open', 'prop_type', 'prop_width']
__version__ = "1.8.3"
__version__ = "1.8.4"
__gdal_version__ = get_gdal_release_name()
gdal_version = get_gdal_version_tuple()
......
......@@ -327,7 +327,6 @@ cdef class GDALEnv(ConfigEnv):
if path:
self.update_config_options(GDAL_DATA=path)
os.environ['GDAL_DATA'] = path
log.debug("GDAL_DATA not found in environment, set to %r.", path)
if 'PROJ_LIB' not in os.environ:
......
......@@ -154,37 +154,66 @@ def _transform_geom(
_csl.CSLDestroy(options)
_crs.OSRRelease(src)
_crs.OSRRelease(dst)
else:
g = geom
if precision >= 0:
if g['type'] == 'Point':
x, y = g['coordinates']
coords = list(g['coordinates'])
x, y = coords[:2]
x = round(x, precision)
y = round(y, precision)
new_coords = [x, y]
if len(coords) == 3:
z = coords[2]
new_coords.append(round(z, precision))
elif g['type'] in ['LineString', 'MultiPoint']:
xp, yp = zip(*g['coordinates'])
coords = list(zip(*g['coordinates']))
xp, yp = coords[:2]
xp = [round(v, precision) for v in xp]
yp = [round(v, precision) for v in yp]
if len(coords) == 3:
zp = coords[2]
zp = [round(v, precision) for v in zp]
new_coords = list(zip(xp, yp, zp))
else:
new_coords = list(zip(xp, yp))
elif g['type'] in ['Polygon', 'MultiLineString']:
new_coords = []
for piece in g['coordinates']:
xp, yp = zip(*piece)
coords = list(zip(*piece))
xp, yp = coords[:2]
xp = [round(v, precision) for v in xp]
yp = [round(v, precision) for v in yp]
if len(coords) == 3:
zp = coords[2]
zp = [round(v, precision) for v in zp]
new_coords.append(list(zip(xp, yp, zp)))
else:
new_coords.append(list(zip(xp, yp)))
elif g['type'] == 'MultiPolygon':
parts = g['coordinates']
new_coords = []
for part in parts:
inner_coords = []
for ring in part:
xp, yp = zip(*ring)
coords = list(zip(*ring))
xp, yp = coords[:2]
xp = [round(v, precision) for v in xp]
yp = [round(v, precision) for v in yp]
if len(coords) == 3:
zp = coords[2]
zp = [round(v, precision) for v in zp]
inner_coords.append(list(zip(xp, yp, zp)))
else:
inner_coords.append(list(zip(xp, yp)))
new_coords.append(inner_coords)
g['coordinates'] = new_coords
return g
......@@ -11,9 +11,7 @@ from fiona.ogrext import Session, WritingSession
from fiona.ogrext import buffer_to_virtual_file, remove_virtual_file, GEOMETRY_TYPES
from fiona.errors import (DriverError, SchemaError, CRSError, UnsupportedGeometryTypeError, DriverSupportError)
from fiona.logutils import FieldSkipLogFilter
from fiona._env import driver_count
from fiona._env import (
calc_gdal_version_num, get_gdal_version_num, get_gdal_release_name)
from fiona._env import driver_count, get_gdal_release_name, get_gdal_version_tuple
from fiona.env import Env
from fiona.errors import FionaDeprecationWarning
from fiona.drvsupport import supported_drivers
......@@ -77,8 +75,7 @@ class Collection(object):
raise TypeError("invalid archive: %r" % archive)
# Check GDAL version against drivers
if (driver == "GPKG" and
get_gdal_version_num() < calc_gdal_version_num(1, 11, 0)):
if (driver == "GPKG" and get_gdal_version_tuple() < (1, 11, 0)):
raise DriverError(
"GPKG driver requires GDAL 1.11.0, fiona was compiled "
"against: {}".format(get_gdal_release_name()))
......@@ -409,8 +406,9 @@ class Collection(object):
See GH#572 for discussion.
"""
gdal_version_major = get_gdal_version_num() // 1000000
for field in self._schema["properties"]:
gdal_version_major = get_gdal_version_tuple().major
for field in self._schema["properties"].values():
field_type = field.split(":")[0]
if self._driver == "ESRI Shapefile":
if field_type == "datetime":
......
import fiona
from fiona.errors import SchemaError, UnsupportedGeometryTypeError, \
DriverSupportError
from fiona.schema import FIELD_TYPES, normalize_field_type
import os
import tempfile
import pytest
import fiona
from fiona.errors import SchemaError, UnsupportedGeometryTypeError
from fiona.schema import FIELD_TYPES, normalize_field_type
from fiona.env import calc_gdal_version_num, get_gdal_version_num
from .conftest import requires_only_gdal1, requires_gdal2
def test_schema_ordering_items(tmpdir):
......@@ -147,10 +148,8 @@ def test_unsupported_geometry_type():
'geometry': 'BOGUS',
'properties': {}}}
try:
with pytest.raises(UnsupportedGeometryTypeError):
fiona.open(tmpfile, 'w', **profile)
except UnsupportedGeometryTypeError:
assert True
@pytest.mark.parametrize('x', list(range(1, 10)))
......@@ -158,8 +157,7 @@ def test_normalize_int32(x):
assert normalize_field_type('int:{}'.format(x)) == 'int32'
@pytest.mark.skipif(get_gdal_version_num() < calc_gdal_version_num(2, 0, 0),
reason="64-bit integer fields require GDAL 2+")
@requires_gdal2
@pytest.mark.parametrize('x', list(range(10, 20)))
def test_normalize_int64(x):
assert normalize_field_type('int:{}'.format(x)) == 'int64'
......@@ -197,3 +195,31 @@ def test_normalize_std(x):
def test_normalize_error():
with pytest.raises(SchemaError):
assert normalize_field_type('thingy')
@requires_only_gdal1
@pytest.mark.parametrize('field_type', ['time', 'datetime'])
def test_check_schema_driver_support_shp(tmpdir, field_type):
with pytest.raises(DriverSupportError):
name = str(tmpdir.join('test_scheme.shp'))
items = [('field1', field_type)]
with fiona.open(name, 'w',
driver="ESRI Shapefile",
schema={
'geometry': 'LineString',
'properties': items}) as c:
pass
@requires_only_gdal1
def test_check_schema_driver_support_gpkg(tmpdir):
with pytest.raises(DriverSupportError):
name = str(tmpdir.join('test_scheme.gpkg'))
items = [('field1', 'time')]
with fiona.open(name, 'w',
driver="GPKG",
schema={
'geometry': 'LineString',
'properties': items}) as c:
pass
"""Tests of the transform submodule"""
import math
import pytest
from fiona import transform
@pytest.mark.parametrize(
"geom",
[
{"type": "Point", "coordinates": [0.0, 0.0, 1000.0]},
{
"type": "LineString",
"coordinates": [[0.0, 0.0, 1000.0], [0.1, 0.1, -1000.0]],
},
{
"type": "MultiPoint",
"coordinates": [[0.0, 0.0, 1000.0], [0.1, 0.1, -1000.0]],
},
{
"type": "Polygon",
"coordinates": [
[
[0.0, 0.0, 1000.0],
[0.1, 0.1, -1000.0],
[0.1, -0.1, math.pi],
[0.0, 0.0, 1000.0],
]
],
},
{
"type": "MultiPolygon",
"coordinates": [
[
[
[0.0, 0.0, 1000.0],
[0.1, 0.1, -1000.0],
[0.1, -0.1, math.pi],
[0.0, 0.0, 1000.0],
]
]
],
},
],
)
def test_transform_geom_with_z(geom):
"""Transforming a geom with Z succeeds"""
g2 = transform.transform_geom("epsg:4326", "epsg:3857", geom, precision=3)