Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Toblerity/Fiona
Browse files Browse the repository at this point in the history
  • Loading branch information
sgillies committed Jun 19, 2024
2 parents 6a9ce8c + cd70508 commit e0715b4
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 73 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1
uses: ossf/scorecard-action@dc50aa9510b46c811795eb24b2f1ba02a914e534 # v2.3.3
with:
results_file: results.sarif
results_format: sarif
Expand All @@ -59,14 +59,14 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@1746f4ab65b179e0ea60a494b83293b640dd5bba # v4.3.2
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@c7f9125735019aa87cfc361530512d50ea439c71 # v3.25.1
uses: github/codeql-action/upload-sarif@23acc5c183826b7a8a97bce3cecc52db901f8251 # v3.25.10
with:
sarif_file: results.sarif
50 changes: 27 additions & 23 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ main, 'maint-*' ]
paths:
- '.github/workflows/tests.yaml'
- '.github/workflows/tests.yml'
- 'requirements*.txt'
- 'setup.py'
- 'setup.cfg'
Expand All @@ -15,7 +15,7 @@ on:
pull_request:
branches: [ main, 'maint-*' ]
paths:
- '.github/workflows/tests.yaml'
- '.github/workflows/tests.yml'
- 'requirements*.txt'
- 'setup.py'
- 'setup.cfg'
Expand Down Expand Up @@ -92,61 +92,65 @@ jobs:
fail-fast: true
matrix:
include:
- os: [macos-13, macos-14]
- os: macos-13
python-version: '3.11'
- os: macos-14
python-version: '3.11'
- os: windows-latest
python-version: '3.11'
steps:
- uses: actions/checkout@v4.1.3
- uses: actions/checkout@v4

- name: Conda Setup
uses: s-weigand/setup-conda@v1
uses: conda-incubator/setup-miniconda@v3
with:
conda-channels: conda-forge
miniforge-variant: Mambaforge
miniforge-version: latest
use-mamba: true
auto-update-conda: true
use-only-tar-bz2: false

- name: Install Env (OSX)
if: matrix.os == 'macos-latest'
shell: bash
if: matrix.os == 'macos-13' || matrix.os == 'macos-14'
shell: bash -l {0}
run: |
conda config --prepend channels conda-forge
conda config --set channel_priority strict
conda create -n test python=${{ matrix.python-version }} libgdal geos=3.10.3 cython=3
source activate test
conda create -n test python=${{ matrix.python-version }} libgdal geos=3.11 cython=3
conda activate test
python -m pip install -e . || python -m pip install -e .
python -m pip install -r requirements-dev.txt
- name: Install Env (Windows)
if: matrix.os == 'windows-latest'
shell: bash
shell: bash -l {0}
run: |
conda config --prepend channels conda-forge
conda config --set channel_priority strict
conda create -n test python=${{ matrix.python-version }} libgdal geos=3.10.3 cython=3
source activate test
GDAL_VERSION="3.5" python setup.py build_ext -I"C:\\Miniconda\\envs\\test\\Library\\include" -lgdal_i -L"C:\\Miniconda\\envs\\test\\Library\\lib" install
conda create -n test python=${{ matrix.python-version }} libgdal geos=3.11 cython=3
conda activate test
GDAL_VERSION="3.7" python setup.py build_ext -I"/c/Users/runneradmin/miniconda3/envs/test/Library/include" -lgdal -L"/c/Users/runneradmin/miniconda3/envs/test/Library/lib" install
python -m pip install -r requirements-dev.txt
- name: Check and Log Environment
shell: bash
shell: bash -l {0}
run: |
source activate test
conda activate test
python -V
conda info
conda list
- name: Test with Coverage (Windows)
if: matrix.os == 'windows-latest'
shell: bash
shell: bash -l {0}
run: |
source activate test
conda activate test
pytest -v -m "not wheel" -rxXs --cov fiona --cov-report term-missing
- name: Test with Coverage (OSX)
if: matrix.os == 'macos-13' || matrix.os == 'macos-14'
shell: bash
if: matrix.os == 'macos-13'
shell: bash -l {0}
run: |
source activate test
conda activate test
python -m pytest -v -m "not wheel" -rxXs --cov fiona --cov-report term-missing
- uses: codecov/codecov-action@v3
6 changes: 3 additions & 3 deletions ci/rstcheck/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ idna==3.7
# via requests
imagesize==1.4.1
# via sphinx
jinja2==3.1.3
jinja2==3.1.4
# via sphinx
markupsafe==2.1.3
# via jinja2
Expand All @@ -38,7 +38,7 @@ pygments==2.16.1
# via
# rich
# sphinx
requests==2.31.0
requests==2.32.0
# via sphinx
rich==12.6.0
# via typer
Expand Down Expand Up @@ -76,5 +76,5 @@ types-docutils==0.19.1.9
# via rstcheck-core
typing-extensions==4.7.1
# via pydantic
urllib3==2.0.7
urllib3==2.2.2
# via requests
56 changes: 27 additions & 29 deletions fiona/_geometry.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ log.addHandler(NullHandler())
# mapping of GeoJSON type names to OGR integer geometry types
GEOJSON2OGR_GEOMETRY_TYPES = dict((v, k) for k, v in GEOMETRY_TYPES.items())

cdef set LINEAR_GEOM_TYPES = {
OGRGeometryType.CircularString.value,
OGRGeometryType.CompoundCurve.value,
OGRGeometryType.CurvePolygon.value,
OGRGeometryType.MultiCurve.value,
OGRGeometryType.MultiSurface.value,
# OGRGeometryType.Curve.value, # Abstract type
# OGRGeometryType.Surface.value, # Abstract type
}

cdef set PS_TIN_Tri_TYPES = {
OGRGeometryType.PolyhedralSurface.value,
OGRGeometryType.TIN.value,
OGRGeometryType.Triangle.value
}


cdef int ogr_get_geometry_type(void *geometry):
# OGR_G_GetGeometryType with NULL geometry support
if geometry == NULL:
Expand Down Expand Up @@ -137,14 +154,11 @@ cdef class GeomBuilder:
parts = []
j = 0
count = OGR_G_GetGeometryCount(geom)

while j < count:
part = OGR_G_GetGeometryRef(geom, j)
code = base_geometry_type_code(ogr_get_geometry_type(part))
if code in (
OGRGeometryType.PolyhedralSurface.value,
OGRGeometryType.TIN.value,
OGRGeometryType.Triangle.value,
):
code = base_geometry_type_code(OGR_G_GetGeometryType(part))
if code in PS_TIN_Tri_TYPES:
OGR_G_RemoveGeometry(geom, j, False)
# Removing a geometry will cause the geometry count to drop by one,
# and all “higher” geometries will shuffle down one in index.
Expand Down Expand Up @@ -186,11 +200,7 @@ cdef class GeomBuilder:

# We need to take ownership of the geometry before we can call
# OGR_G_ForceToPolygon or OGR_G_ForceToMultiPolygon
if code in (
OGRGeometryType.PolyhedralSurface.value,
OGRGeometryType.TIN.value,
OGRGeometryType.Triangle.value,
):
if code in PS_TIN_Tri_TYPES:
cogr_geometry = OGR_F_StealGeometry(feature)
return self.build(cogr_geometry)

Expand All @@ -206,28 +216,16 @@ cdef class GeomBuilder:

# We convert special geometries (Curves, TIN, Triangle, ...)
# to GeoJSON compatible geometries (LineStrings, Polygons, MultiPolygon, ...)
if code in (
OGRGeometryType.CircularString.value,
OGRGeometryType.CompoundCurve.value,
OGRGeometryType.CurvePolygon.value,
OGRGeometryType.MultiCurve.value,
OGRGeometryType.MultiSurface.value,
# OGRGeometryType.Curve.value, # Abstract type
# OGRGeometryType.Surface.value, # Abstract type
):
if code in LINEAR_GEOM_TYPES:
geometry_to_dealloc = OGR_G_GetLinearGeometry(geom, 0.0, NULL)
code = base_geometry_type_code(ogr_get_geometry_type(geometry_to_dealloc))
geom = geometry_to_dealloc
elif code in (
OGRGeometryType.PolyhedralSurface.value,
OGRGeometryType.TIN.value,
OGRGeometryType.Triangle.value,
):
if code in (OGRGeometryType.PolyhedralSurface.value, OGRGeometryType.TIN.value):
geometry_to_dealloc = OGR_G_ForceToMultiPolygon(geom)
elif code == OGRGeometryType.Triangle.value:
elif code in PS_TIN_Tri_TYPES:
if code == OGRGeometryType.Triangle.value:
geometry_to_dealloc = OGR_G_ForceToPolygon(geom)
code = base_geometry_type_code(ogr_get_geometry_type(geometry_to_dealloc))
else:
geometry_to_dealloc = OGR_G_ForceToMultiPolygon(geom)
code = base_geometry_type_code(OGR_G_GetGeometryType(geometry_to_dealloc))
geom = geometry_to_dealloc
self.ndims = OGR_G_GetCoordinateDimension(geom)

Expand Down
2 changes: 1 addition & 1 deletion fiona/drvsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
# multi-layer
# ("OpenAir", "r"),
# (Geo)Parquet
("Parquet", "raw"),
("Parquet", "rw"),
# PCI Geomatics Database File PCIDSK No No Yes, using internal PCIDSK SDK (from GDAL 1.7.0)
("PCIDSK", "raw"),
# PDS PDS No Yes Yes
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def copy_data_tree(datadir, destdir):
" setup.py to locate needed GDAL files.\nMore"
" information is available in the README.")
else:
logging.warn("Failed to get options via gdal-config: %s", str(e))
logging.warning("Failed to get options via gdal-config: %s", str(e))

# Get GDAL API version from environment variable.
if 'GDAL_VERSION' in os.environ:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def calc_bounds(records):
ys.append(r.geometry["coordinates"][1])
return min(xs), max(xs), min(ys), max(ys)

with fiona.open(path, "w", driver=driver, schema=schema) as c:
with fiona.open(path, "w", crs="OGC:CRS84", driver=driver, schema=schema) as c:
c.writerecords(records1)

try:
Expand Down
29 changes: 18 additions & 11 deletions tests/test_memoryfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def test_mapinfo_raises():
for driver in supported_drivers
if _driver_supports_mode(driver, "w")
and supports_vsi(driver)
and driver not in {"MapInfo File"}
and driver not in {"MapInfo File", "TileDB"}
],
)
def test_write_memoryfile_drivers(driver, testdata_generator):
Expand All @@ -226,7 +226,7 @@ def test_write_memoryfile_drivers(driver, testdata_generator):
schema, crs, records1, _, _ = testdata_generator(driver, range1, [])

with MemoryFile() as memfile:
with memfile.open(driver=driver, schema=schema) as c:
with memfile.open(driver=driver, crs="OGC:CRS84", schema=schema) as c:
c.writerecords(records1)

with memfile.open(driver=driver) as c:
Expand Down Expand Up @@ -267,7 +267,7 @@ def test_multiple_layer_memoryfile(testdata_generator):
for driver in supported_drivers
if _driver_supports_mode(driver, "a")
and supports_vsi(driver)
and driver not in {"MapInfo File"}
and driver not in {"MapInfo File", "TileDB"}
],
)
def test_append_memoryfile_drivers(driver, testdata_generator):
Expand All @@ -277,16 +277,23 @@ def test_append_memoryfile_drivers(driver, testdata_generator):
schema, crs, records1, records2, _ = testdata_generator(driver, range1, range2)

with MemoryFile() as memfile:
with memfile.open(driver=driver, schema=schema) as c:
with memfile.open(driver=driver, crs="OGC:CRS84", schema=schema) as c:
c.writerecords(records1)

with memfile.open(mode='a', driver=driver, schema=schema) as c:
c.writerecords(records2)

with memfile.open(driver=driver) as c:
assert driver == c.driver
items = list(c)
assert len(items) == len(range1 + range2)
# The parquet dataset does not seem to support append mode
if driver == "Parquet":
with memfile.open(driver=driver) as c:
assert driver == c.driver
items = list(c)
assert len(items) == len(range1)
else:
with memfile.open(mode='a', driver=driver, schema=schema) as c:
c.writerecords(records2)

with memfile.open(driver=driver) as c:
assert driver == c.driver
items = list(c)
assert len(items) == len(range1 + range2)


def test_memoryfile_driver_does_not_support_vsi():
Expand Down
4 changes: 3 additions & 1 deletion tests/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ def get_records(driver, range):
tmpdir = tempfile.mkdtemp()
path = os.path.join(tmpdir, get_temp_filename(driver))

with fiona.open(path, "w", driver=driver, schema=schema, **create_kwargs) as c:
with fiona.open(
path, "w", driver=driver, crs="OGC:CRS84", schema=schema, **create_kwargs
) as c:
c.writerecords(records)
yield path
shutil.rmtree(tmpdir)
Expand Down

0 comments on commit e0715b4

Please sign in to comment.