# How Can I set projection to numpy array input from Python API?

**URL:** <https://forum.orfeo-toolbox.org/t/how-can-i-set-projection-to-numpy-array-input-from-python-api/1749>\
**Category:** OTB Usage\
**Created:** [March 31, 2024, 8:04am UTC](https://forum.orfeo-toolbox.org/t/how-can-i-set-projection-to-numpy-array-input-from-python-api/1749 "2024-03-31T08:04:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amano-takahisa](https://forum.orfeo-toolbox.org/user_avatar/forum.orfeo-toolbox.org/amano-takahisa/32/384_2.png) [@amano-takahisa](https://forum.orfeo-toolbox.org/u/amano-takahisa)\
**Post date:** [March 31, 2024, 8:04am UTC](https://forum.orfeo-toolbox.org/t/how-can-i-set-projection-to-numpy-array-input-from-python-api/1749/1 "2024-03-31T08:04:29Z")

</div>

## Context

I am trying to use Segmentation app from Python API.  
Input raster data is passed as numpy array, but I couldn’t find a way to give projection information to the app.

I know that I can generate geotiff with projection metadatas with rasterio, and give the file as app’s input.  
But, since the input data is created from upstream process, I want to avoid the array to write on a disk as a file such as GeoTiff to reduce I/O overhead.

### Configuration setup

Minimum setup which I tried so far:

```python
import numpy as np
import otbApplication as otb

params = {
    'filter': 'meanshift',
    'mode': 'vector',
}
array = np.random.random(30000).reshape(100, 100, 3)
app = otb.Registry.CreateApplication('Segmentation')
app.SetVectorImageFromNumpyArray('in', array)
app.SetParameters(params)
app.Execute()

```

and raise following error.

```auto
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[37], line 12
     10 app.SetVectorImageFromNumpyArray('in', array)
     11 app.SetParameters(params)
---> 12 app.Execute()
     13 # app_out = ExtractROI.GetVectorImageAsNumpyArray('out')
     14 # app_out

File ~/Documents/git/cellcounter/otb/lib/otb/python/otbApplication.py:2445, in Application.Execute(self)
   2444 def Execute(self):
-> 2445 return _otbApplication.Application_Execute(self)

RuntimeError: Exception thrown in otbApplication Application_Execute: ../Modules/Core/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx:152:
itk::ERROR: No OGR driver known to OTB to create and handle a DataSource named <>.

```

---

<div class="post-metadata">

**Author:** ![amano-takahisa](https://forum.orfeo-toolbox.org/user_avatar/forum.orfeo-toolbox.org/amano-takahisa/32/384_2.png) [@amano-takahisa](https://forum.orfeo-toolbox.org/u/amano-takahisa)\
**Post date:** [March 31, 2024, 2:20pm UTC](https://forum.orfeo-toolbox.org/t/how-can-i-set-projection-to-numpy-array-input-from-python-api/1749/2 "2024-03-31T14:20:37Z")

</div>

> [@amano-takahisa](#):
>
> ```auto
> params = {
> 'filter': 'meanshift',
> 'mode': 'vector',
> }
> 
> ```

I found that I need to add output shapefile path for vector mode, otherwise use raster mode, as follows.

The issue was not related to projections but missing some required args.

```python
params = {
    'filter': 'meanshift',
    'mode': 'vector',
    'mode.vector.out': 'out.shp',
}

```

```python
params = {
    'filter': 'meanshift',
    'mode': 'raster',
}

```
