简体   繁体   中英

How to import Tif in Popen

I want to import a tif file with Popen and then open it with gdal.open because I want to use other gdal utilities afterwards. The import with Popen seems to work. But for the line 'src_ds=gdal.Open(src_filename)' I get the following error:

    return _gdal.Open(*args)
RuntimeError: not a string

Code

from osgeo import gdal,ogr
import struct

from subprocess import Popen, PIPE, STDOUT
user = "user"
host = "host"

dem = Popen(
    ["ssh", "{}@{}".format(user, host), "tif.tiff"], shell= True
)
dem.wait()

src_filename = dem
shp_filename = out_file1


src_ds=gdal.Open(src_filename)
gt=src_ds.GetGeoTransform()
rb=src_ds.GetRasterBand(1)

Thanks

In your code "dem" is a Popen object and not a string representing a filename, so gdal cannot read it.

If the image is on a remote server then you need to either copy the data over the network or run your code on the remote server. You could use subprocess with scp to copy the image data first, and there is also the paramiko library to do this directly within python without starting a new process; see How to scp in python? .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM