Hi Avinash,
Thanks for the quick response,Please find below details.
Please find below script to import .cnv files to SDE Database.
import os
... import re
... import csv
... import arcpy
... import unicodedata
... import numpy
... import seabird
... from seabird.cnv import fCNV
...
... instance= arcpy.GetParameterAsText(0)
... username= arcpy.GetParameterAsText(1)
... password= arcpy.GetParameterAsText(2)
...
connection=arcpy.CreateDatabaseConnection_management(arcpy.env.scratchFolder,"ncaor_linux","ORACLE",instance,"DATABASE_AUTH",username,password,"DO_NOT_SAVE_USERNAME")
...
... ctdinput = arcpy.GetParameterAsText(3)
... if ctdinput == '#' or not ctdinput:
... ctdinput = r"E:\Temp\CTDB12.cnv"
...
... file=os.path.basename(ctdinput)
... inputfile=os.path.splitext(file)[0]
... extension=os.path.splitext(file)[1]
...
...
... geographicprojection=r"GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"
...
... projection=r"PROJCS['WGS_1984_UTM_Zone_42S',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',10000000.0],PARAMETER['Central_Meridian',69.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]"
...
... ctdprojection = arcpy.GetParameterAsText(4)
... if ctdprojection == '#' or not ctdprojection:
... ctdprojection = projection
...
...
... cruise_no = arcpy.GetParameterAsText(5)
... if cruise_no == '#' or not cruise_no:
... cruise_no = "SK14145" # provide a default value if unspecified
...
... file_id= arcpy.GetParameterAsText(6)
... if file_id== '#' or not file_id:
... file_id= "ctd"# provide a default value if unspecified
... #Replace the name of input file
...
... inputfile="A_"+file_id
...
...
... m=0
... longindex=0
... latindex=0
... depthindex=0
... dateindex=0
... timeindex=0
... csvvaluelist=[]
... csvfileheaderlist=[]
... data=[]
... featureclass_scratchL=arcpy.env.scratchGDB+os.sep+cruise_no+"_"+inputfile +"_fc"
... outputfcLine=str(connection)+os.sep+"SDE."+cruise_no+"_"+inputfile +"_fc"
... array=[]
...
... headerstring=""
... inputcnvfile= fCNV(ctdinput)
... keys=inputcnvfile.keys()
... rawdata=inputcnvfile.raw_data().values()
... headerdata=inputcnvfile.raw_header()
... deleteidentical=arcpy.env.scratchGDB+os.sep+"fc_projected"
...
...
... def writetocsvandSDE():
... datatocsv=[]
... CSVdir = arcpy.env.scratchFolder
... realCSVdir = os.path.realpath(CSVdir)
... foupath = os.path.join(realCSVdir+os.sep+inputfile+".csv")
... fou = open(foupath, 'wb')
... a = csv.writer(fou)
... for i in range(0,len(csvvaluelist)):
... datatocsv= [csvvaluelist]
... a.writerows(datatocsv)
... fou.close()
... csvfilepath=os.path.join(arcpy.env.scratchFolder+os.sep+inputfile+".csv")
... eventlayer=arcpy.MakeXYEventLayer_management(csvfilepath,long,lat,"fc_layerfile",geographicprojection,depth)
... outputfc=os.path.join(str(connection)+os.sep+cruise_no+"_"+inputfile+"_fc")
... projectedfc=arcpy.Project_management(eventlayer,os.path.join(arcpy.env.scratchGDB+os.sep+"fc_projected"),ctdprojection,"",geographicprojection,"NO_PRESERVE_SHAPE")
... # Process: Copy Features to output sde
... fc_copy=arcpy.CopyFeatures_management(projectedfc,outputfc,"","","","")
... deleteidentical=arcpy.DeleteIdentical_management(projectedfc,"\""+long+";"+lat+"\"", "", "0")
...
...
... for j in range(0,len(keys)):
... headerstring=headerstring+" "+keys
...
... data.append(headerstring.strip())
...
... for row in rawdata:
... array.append(str(row))
...
... rawdata=re.split('\n',str(array[0]))
...
...
...
... for raw in rawdata:
... raw=re.sub( '\s+', ' ', raw).strip()
... data.append(raw)
...
... for k in range(0,len(data)):
... celldata=[]
... rowdata=data.split()
... for t in range(0,len(rowdata)):
... celldata.append(rowdata)
... if re.match('long.*',rowdata,re.IGNORECASE):
... longindex=t
... long=rowdata
... elif re.match('lat.*',rowdata,re.IGNORECASE):
... latindex=t
... lat=rowdata
... elif re.match('depth.*',rowdata,re.IGNORECASE):
... depthindex=t
... depth=rowdata
... csvvaluelist.append(celldata)
... writetocsvandSDE()
...
... arcpy.SetParameterAsText(7,deleteidentical)
... arcpy.SetParameterAsText(8,headerdata)