import arcpy, os from arcpy import env import sys import time try: t0 = time.clock() env.workspace = r"C:\ags\python" sdeConn = arcpy.ArcSDESQLExecute(r"C:\ags\gp\gisselect_cdodb_t.sde") sql = "SELECT lon, lat, snow FROM gis.snow_sum_partitioned WHERE date_time = to_date('19991231','yyyymmdd') AND snow IS NOT NULL" try: # execute SQL statement sdeReturn = sdeConn.execute(sql) except Exception, ErrorDesc: print ErrorDesc sdeReturn = False # if return value is a list (a list of lists), display each list as a row from the table being queried. if isinstance(sdeReturn, list): # set spatial reference prjFile = "geo_wgs84.prj" spatialRef = arcpy.SpatialReference(prjFile) tmpWorkspace = "in_memory" outXYfc = "XY_FeatureClass" # create in_memory empty feature class arcpy.CreateFeatureclass_management(tmpWorkspace, outXYfc , "POINT", "", "", "", spatialRef) # build tmp FC path and add new field for values to interpolate tmpFC = os.path.join(tmpWorkspace, outXYfc) arcpy.AddField_management(tmpFC, "Snow", "DOUBLE") # create insert cursor inCur = arcpy.InsertCursor(tmpFC) for rec in sdeReturn: pnt = arcpy.Point(rec[0], rec[1]) row = inCur.newRow() row.Shape = pnt row.Snow = rec[2] inCur.insertRow(row) del inCur, row # Set layer symbology symbology_layer = "snow_symbology.lyr" arcpy.ApplySymbologyFromLayer_management(outXYfc, symbology_layer) else: # If the return value was not a list, the statement was most likely a DDL statment. Check its status. if sdeReturn == True: print "SQL statement: " + sql + " ran sucessfully." else: print "SQL statement: " + sql + " FAILED." except Exception, ErrorDesc: print Exception, ErrorDesc except: print "Problem executing SQL."
gp.createtable_management("IN_MEMORY", "TempDT", "", "") cxRows = cursor.fetchall() #the cursor here was already filled. rowcount = cursor.rowcount for row in range(1, rowcount - 1): tables = gp.ListTables() for tbl in tables: if tbl=="TempDT": ### add the fields for i in range(0, len(cursor.description)): val1 = str(cursor.description[0]) val2 = str(cursor.description[1]) val3 = str(cursor.description[2]) if val2=="<type 'cx_Oracle.STRING'>": fldType = "Text" val3 = cursor.description[2] gp.AddField(tbl, str(cursor.description[0]), fldType, val3) if val2=="<type 'cx_Oracle.NATIVE_FLOAT'>": fldType = "Float" gp.AddField(tbl, str(cursor.description[0]), fldType) if val2=="<type 'cx_Oracle.DATETIME'>": fldType = "Date" gp.AddField(tbl, str(cursor.description[0]), fldType) ### now populate the table insRows = gp.InsertCursor(tblNew) for cxRow in cxRows: insRow = insRows.newRow() for i in range(0, len(cursor.description)): insRow.setvalue(str(cursor.description[0]), cxRow) insRows.insertRow(insRow) cursor.close() db.close()
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.