Geographic Information Systems Asked on August 2, 2021
Tried many ways
A.
import os
import subprocess
from subprocess import PIPE, run
db_name = 'agro_dss'
db_host = 'localhost'
db_port = '5432'
db_user = 'postgres'
db_password = 'imd123#'
os.environ['PATH'] = r';C:Program FilesPostgreSQL13bin'
os.environ['PGHOST'] = db_host
os.environ['PGPORT'] = db_port
os.environ['PGUSER'] = db_user
os.environ['PGPASSWORD'] = db_password
os.environ['PGDATABASE'] = db_name
cmd = 'raster2pgsql -s 4326 -C -t auto -M D:AdvisoryRaster*.tif -F public.polys | psql -U {} -d {} -h {} -p {}'.format(db_user,db_name,db_host,db_port)
subprocess.call(cmd, shell=True)
result = run(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(result.returncode, result.stdout, result.stderr)
The error is
1 ERROR: Unable to read raster file: public.polys
B.
from osgeo import gdal, osr
import psycopg2
import subprocess
import sys, os
fileName = r"D:AdvisoryRasterMODIS_All_India_NDVI_2001_01_01.tif"
check_proj = gdal.Open(fileName)
proj = osr.SpatialReference(wkt=check_proj.GetProjection())
projection=str(proj.GetAttrValue('AUTHORITY',1))
input_path = r"D:AdvisoryRaster"
os.environ['PATH'] = r';C:Program FilesPostgreSQL13bin'
os.environ['PGHOST'] = 'localhost'
os.environ['PGPORT'] = '5432'
os.environ['PGUSER'] = 'postgres'
os.environ['PGPASSWORD'] = 'imd123#'
os.environ['PGDATABASE'] = 'agro_dss'
for raster in os.listdir(input_path):
if raster.endswith(".tif"):
name = raster.split(".tif")[0]
raster = os.path.join(input_path, raster)
rastername = str(name)
rasterlayer = rastername.lower()
conn = psycopg2.connect(database="agro_dss", user="postgres", host="localhost", password="imd123#", port=5432)
cursor = conn.cursor()
print(cursor," connection suscessfull")
cmds = 'raster2pgsql -s '+projection+' -I -C -M "'+raster+'" -F -t auto'+' public.'+name+' | psql -d agro_dss -U postgres -p 5432 -h localhost'
subprocess.call(cmds, shell=True)
result = run(cmds, stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(result.returncode, result.stdout, result.stderr)
The error is
1 ERROR: Unable to read raster file: public.polys
Sought many answers:
but did not come up with the solution
How to rectify this?
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP