Beispiel #1
0
def test_get_instance_from_gdal_layer(mocker):
    f = mocker.patch.object(macros, '_get_field_type_by_name')
    f.return_value = {}
    f = mocker.patch.object(macros, '_get_get_field_values')
    f.return_value = lambda x: []
    mock_class = MagicMock()
    mock_gdal_layer = MagicMock()
    mock_gdal_layer.GetFeatureCount.return_value = 1
    mock_gdal_layer.GetNextFeature.return_value = None
    mock_transform_gdal_geometry = MagicMock()
    t = _get_instance_from_gdal_layer(mock_class, mock_gdal_layer,
                                      mock_transform_gdal_geometry)
    assert not len(t.geometries)
    mock_transformed_gdal_geometry = MagicMock()
    mock_transformed_gdal_geometry.ExportToWkb.side_effect = WKBReadingError()
    mock_transform_gdal_geometry.return_value = mock_transformed_gdal_geometry
    mock_feature = MagicMock()
    mock_gdal_layer.GetNextFeature.return_value = mock_feature
    t = _get_instance_from_gdal_layer(mock_class, mock_gdal_layer,
                                      mock_transform_gdal_geometry)
    assert not len(t.geometries)
Beispiel #2
0
def deserialize_wkb(data):
    geom = lgeos.GEOSGeomFromWKB_buf(c_char_p(data), c_size_t(len(data)))
    if not geom:
        raise WKBReadingError(
            "Could not create geometry because of errors while reading input.")
    return geom