Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Release History
===============

.. Unreleased Changes
* ``reproject_vector`` will skip copying field values from the base layer
to the target if doing so would raise a RuntimeError,
such as when a string value cannot be represented by UTF-8.
https://github.com/natcap/pygeoprocessing/issues/418

2.4.7 (2025-01-23)
------------------
Expand Down
17 changes: 14 additions & 3 deletions src/pygeoprocessing/geoprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ def reproject_vector(

target_sr = osr.SpatialReference(target_projection_wkt)

# create a new shapefile from the orginal_datasource
# create a new vector from the orginal_datasource
target_driver = ogr.GetDriverByName(driver_name)
target_vector = target_driver.CreateDataSource(target_path)

Expand Down Expand Up @@ -2277,8 +2277,19 @@ def reproject_vector(
# source field
for target_index, base_index in (
target_to_base_field_id_map.items()):
target_feature.SetField(
target_index, base_feature.GetField(base_index))
try:
target_feature.SetField(
target_index, base_feature.GetField(base_index))
except RuntimeError:
try:
target_feature.SetFieldBinary(
target_index,
base_feature.GetFieldAsBinary(base_index))
except RuntimeError as runtime_error:
LOGGER.debug(
f"Skipping copy field value for feature {feature_index}, "
f"field {layer_dfn.GetFieldDefn(base_index).GetName()} "
f"due to: {runtime_error}")

target_layer.CreateFeature(target_feature)
target_feature = None
Expand Down