POST
|
Thanks, I changed from dbf to a gdb table, and it works fine now.
... View more
03-27-2012
11:01 AM
|
0
|
0
|
244
|
POST
|
Hi, I wrote a script that updates a feature class from SQL server. It is exactly the same script as http://forums.arcgis.com/threads/45954-Can-t-view-created-feature-class except I am connecting to a different database, and the template FC is different. I noticed when I include field names longer then 10 characters, the code chokes And I get the "File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\_base.py", line 35, in __setattr__ return setattr(self._arc_object, attr, ao) RuntimeError: ERROR 999999: Error executing function." error. I can't figure out the problem especially since the previosu code also contained feature names > 10 characters. Does anyone have a suggestion about this? THanks, BArt import arcpy
import pyodbc
from arcpy import env
cnxn = pyodbc.connect('Driver={SQL Server Native Client 10.0};UID=user;PWD=Password;SERVER=spk-db11sac.spk.ds.usace.army.mil; DATABASE=FTO_OE; APP=MyApp')
cursor=cnxn.cursor()
cursor.execute("select Grid_ID, UniqueID, Date_Found, Quantity, Northing, Easting, Depth, Grid_Alias, AAR_ID, Initial_ID, Final_ID, Risk_Code, MM_Type, Contractor, Burial_Pit, Weight from dbo.View_MEC_FeatureClass") #,Report_Type, Operation_Class,Operation_ID, Report_Date, AAR_Description, Original_MM_Nomenclature, Model_Description, Survey_Instrument, Modification_Notes,")
rows = cursor.fetchall()
env.overwriteOutput = True
env.workspace = r"G:\Temp\Bart\fort_ord.gdb"
template = r"G:\Fort_Ord_GIS\Master_Coverage\Fort_Ord.gdb\env_haz_remediation\oe_item_point"
config_keyword = ""
OETabl = arcpy.CreateTable_management(r"G:\Temp\Bart", "OETabl.dbf", template)
Wcur = arcpy.InsertCursor(OETabl)
for row in rows:
t_row = Wcur.newRow()
t_row.UniqueID = row.UniqueID
t_row.Date_Found = row.Date_Found
#t_row.Operation_Class = row.Operation_Class !!!GET ERROR MESSAGE ON COMMENTED OUT LINES!!!
#t_row.Operation_ID = row.Operation_ID
t_row.Grid_ID = row.Grid_ID
t_row.AAR_ID = row.AAR_ID
t_row.Report_Type = row.Report_Type
#t_row.Report_Date = row.Report_Date
#t_row.AAR_Description = row.AAR_Description
t_row.Northing = row.Northing
t_row.Easting = row.Easting
t_row.Quantity = row.Quantity
t_row.Depth = row.Depth
t_row.Weight = row.Weight
t_row.Initial_ID = row.Initial_ID
t_row.Final_ID = row.Final_ID
#t_row.Model_Description = row.Model_Description
t_row.Risk_Code = row.Risk_Code
t_row.MM_Type = row.MM_Type
t_row.Contractor = row.Contractor
t_row.Burial_Pit = row.Burial_Pit
#t_row.Survey_Instrument = row.Survey_Instrument
#t_row.Modification_Notes = row.Modification_Notes
#t_row.Original_MM_Nomenclature = row.Original_MM_Nomenclature
Wcur.insertRow(t_row)
try:
in_Table = OETabl
x_coords = "Easting"
y_coords = "Northing"
out_layer = "OE_layer"
saved_layer = r"G:\Temp\Bart\Layers\OE.lyr"
spRef = r"C:\Program Files (x86)\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\State Plane\NAD 1983 (US Feet)\NAD 1983 StatePlane California IV FIPS 0404 (US Feet).prj"
arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_layer, spRef)
saved_layer2 = arcpy.SaveToLayerFile_management(out_layer, saved_layer)
except:
print arcpy.GetMessages()
inFeatures = saved_layer2
outLocation = r"G:\Temp\Bart\Scratch.gdb"
outFeatureClass = "OEupdate"
outFC = outLocation + "\\" + outFeatureClass
if arcpy.Exists(outFC)==True:
arcpy.Delete_management(outFC)
arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outLocation, outFeatureClass)
cnxn.commit()
cursor.close()
cnxn.close()
del row
del rows
del cursor
del cnxn
... View more
03-15-2012
03:38 PM
|
0
|
2
|
440
|
POST
|
Hi Bart, Add the following line of code: env.overwriteOutput = True Yes, I already have it in the script at the beginning. I tried copying it down before the featureclasstofeaturecalss command, but it didn't work.
... View more
01-03-2012
09:37 AM
|
0
|
0
|
538
|
POST
|
Ok, Got it, thanks a lot! My last question (hepefully) is this; instead of creating a new feature class in a database, I want to update, or replace an existing one. The code below gives me ExecuteError: ERROR 999999: Error executing function. The table already exists. Failed to execute (FeatureClassToFeatureClass). And here's my (almost) final code: import arcpy
#reload(arcpy)
import pyodbc
from arcpy import env
cnxn = pyodbc.connect('Driver={SQL Server Native Client 10.0};UID=user;PWD=Password;SERVER=spk-db11sac.spk.ds.usace.army.mil; DATABASE=ftord; APP=MyApp')
cursor=cnxn.cursor()
cursor.execute("select aquifer, site_id, well_name, station_name, well_type, welltype_desc, northing, easting, coord_source, toc, ground_elev, top_screen_depth, bot_screen_depth, total_depth, diameter, installer, date_inst, date_aban, destroyed, purge_vol, norm_dtw, pump_depth, comments, well_status, destruction_rationale, date_destroyed, ref_document, destruct_permit_number from dbo.Wells_view")
rows = cursor.fetchall()
env.overwriteOutput = True
env.workspace = r"G:\Fort_Ord_GIS\Master_Coverage\Fort_Ord.gdb"
#env.workspace = r"G:\Temp\Bart\fort_ord.gdb"
template = r"G:\Fort_Ord_GIS\Master_Coverage\Fort_Ord.gdb\improvement_well\water_well_point"
config_keyword = ""
#config_keyword = "TEXT_UTF16"
WellsTabl = arcpy.CreateTable_management(r"G:\Temp\Bart", "WellsTabl.dbf", template)
Wcur = arcpy.InsertCursor(WellsTabl)
for row in rows:
#print row.well_name
t_row = Wcur.newRow()
t_row.well_id = row.well_name
t_row.feat_name = row.well_name
t_row.watwel_d = row.well_type
t_row.well_typ_d = row.welltype_desc
t_row.well_sta_d = row.well_status
t_row.totaldepth = row.total_depth
t_row.gsurf_elev = row.ground_elev
t_row.date_inst = row.date_inst
t_row.norm_dtw = row.norm_dtw
t_row.pump_depth = row.pump_depth
t_row.destructio = row.destruction_rationale
t_row.date_destr = row.date_destroyed
t_row.ref_docume = row.ref_document
t_row.destruct_p = row.destruct_permit_number
t_row.refer_elev = row.toc
t_row.hole_dia = row.diameter
t_row.narrative = row.comments
t_row.cas_sdepth = row.top_screen_depth
t_row.cas_edepth = row.bot_screen_depth
t_row.contrct_id = row.installer
t_row.capacity = row.purge_vol
t_row.destructio = row.destroyed
#t_row.comp_date = row.date_inst
t_row.coord_x = row.easting
t_row.coord_y = row.northing
Wcur.insertRow(t_row)
try:
in_Table = WellsTabl
x_coords = "coord_x"
y_coords = "coord_y"
out_layer = "Wells_layer"
saved_layer = r"G:\Temp\Bart\Layers\Wells2.lyr"
spRef = r"C:\Program Files (x86)\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\State Plane\NAD 1983 (US Feet)\NAD 1983 StatePlane California IV FIPS 0404 (US Feet).prj"
arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_layer, spRef)
saved_layer2 = arcpy.SaveToLayerFile_management(out_layer, saved_layer)
except:
print arcpy.GetMessages()
inFeatures = saved_layer2
#outLocation = r"G:\Temp\Bart\Scratch.gdb"
outLocation = r"G:\Temp\Bart\fort_ord.gdb\improvement_well"
#outFeatureClass = "Wells_update2"
outFeatureClass = "water_well_point"
arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outLocation, outFeatureClass)
cnxn.commit()
cursor.close()
cnxn.close()
del row
del rows
del cursor
del cnxn
... View more
12-30-2011
01:57 PM
|
0
|
0
|
538
|
POST
|
Charles, care to give a bit more details for those of us who are still struggling with this error. Thanks, Bart
... View more
12-21-2011
01:48 PM
|
0
|
0
|
402
|
POST
|
Thanks Jake, I followed your suggestions, and the code works, but there is still one issue I am having aproblem with. When I try to define projection I get: ERROR 000622: Failed to execute (Make XY Event Layer). Parameters are not valid. ERROR 000628: Cannot set input into parameter spatial_reference. When I comment it out, the code runs, but the new feature class has, obviously, no defined projection. Looking through the other forum posts, I see other folks had similar issues when running stand alone python script. Suggestions? import arcpy
#reload(arcpy)
import pyodbc
from arcpy import env
cnxn = pyodbc.connect('Driver={SQL Server Native Client 10.0};UID=ID;PWD=Password;SERVER=spk-db11sac.spk.ds.usace.army.mil; DATABASE=ftord; APP=MyApp')
cursor=cnxn.cursor()
cursor.execute("select aquifer, site_id, well_name, station_name, well_type, welltype_desc, northing, easting, coord_source, toc, ground_elev, top_screen_depth, bot_screen_depth, total_depth, diameter, installer, date_inst, date_aban, destroyed, purge_vol, norm_dtw, pump_depth, comments, well_status, destruction_rationale, date_destroyed, ref_document, destruct_permit_number from dbo.Wells_view")
rows = cursor.fetchall()
env.overwriteOutput = True
env.workspace = r"G:\Fort_Ord_GIS\Master_Coverage\Fort_Ord.gdb"
template = r"G:\Fort_Ord_GIS\Master_Coverage\Fort_Ord.gdb\improvement_well\water_well_point"
config_keyword = ""
WellsTabl = arcpy.CreateTable_management(r"G:\Temp\Bart", "WellsTabl.dbf", template)
Wcur = arcpy.InsertCursor(WellsTabl)
for row in rows:
#print row.well_name
t_row = Wcur.newRow()
t_row.well_id = row.well_name
t_row.well_typ_d = row.welltype_desc
t_row.coord_x = row.easting
t_row.coord_y = row.northing
Wcur.insertRow(t_row)
try:
in_Table = WellsTabl
x_coords = "coord_x"
y_coords = "coord_y"
out_layer = "Wells_layer"
saved_layer = r"G:\Temp\Bart\Layers\Wells.lyr"
#spRef = r"C:\Program Files (x86)\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\State Plane\NAD 1983 (US Feet)\NAD_1983_StatePlane_California_IV_FIPS_0404_Feet (US Feet).prj"
arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_layer, spRef)
print arcpy.GetCount_management(out_Layer)
arcpy.SaveToLayerFile_management(out_layer, saved_layer)
except:
print arcpy.GetMessages()
inFeatures = saved_layer
outLocation = r"G:\Temp\Bart\Scratch.gdb"
outFeatureClass = "Wells_update"
arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outLocation, outFeatureClass)
cnxn.commit()
cursor.close()
cnxn.close()
del row
del rows
del cursor
del cnxn
... View more
12-20-2011
02:00 PM
|
0
|
0
|
538
|
POST
|
Hi Bart, Looking at your code it doesn't appear that you insert geometry any where... JSkinn3, Could you point me to an example how one does that? I'm a newbie to Python. Thanks, BArt
... View more
12-16-2011
10:18 AM
|
0
|
0
|
538
|
POST
|
Hi, I've written a script that connects to a SQL Server via pyodbc, and creates a feature class from a table. The code runs fine, but one in Arc, I don't see my feature class, although the attributes are all there. I am new to python, and can't figure out what I am missing.
import arcpy
#reload(arcpy)
import pyodbc
from arcpy import env
cnxn = pyodbc.connect('Driver={SQL Server Native Client 10.0};UID=ID;PWD=Password;SERVER=spk-db11sac.spk.ds.usace.army.mil; DATABASE=ftord; APP=MyApp')
cursor=cnxn.cursor()
cursor.execute("select aquifer, site_id, well_name, station_name, well_type, welltype_desc, northing, easting, coord_source, toc, ground_elev, top_screen_depth, bot_screen_depth, total_depth, diameter, installer, date_inst, date_aban, destroyed, purge_vol, norm_dtw, pump_depth, comments, well_status, destruction_rationale, date_destroyed, ref_document, destruct_permit_number from dbo.Wells_view")
rows = cursor.fetchall()
env.overwriteOutput = True
env.workspace = r"G:\Fort_Ord_GIS\Master_Coverage\Fort_Ord.gdb"
template = r"G:\Fort_Ord_GIS\Master_Coverage\Fort_Ord.gdb\improvement_well\water_well_point"
Wells = arcpy.CreateFeatureclass_management(r"G:\Temp\Bart\scratch.gdb", "ODB11", "POINT",'', "DISABLED", "DISABLED", template)
#arcpy.AddField_management(Wells,'SubTypeIdentifier','TEXT')
arcpy.AddField_management(Wells,'PKWellID','TEXT')
arcpy.AddField_management(Wells,'PKMApID','TEXT')
arcpy.AddField_management(Wells,'FKMetalID','TEXT')
arcpy.AddField_management(Wells,'FKMediaID','TEXT')
arcpy.AddField_management(Wells,'FKCoordbtID','TEXT')
arcpy.AddField_management(Wells,'FKMnwellID','TEXT')
arcpy.AddField_management(Wells,'WellCatDOM','TEXT')
arcpy.AddField_management(Wells,'WellTypDOM','TEXT')
arcpy.AddField_management(Wells,'WellStaDOM','TEXT')
arcpy.AddField_management(Wells,'CaseMatDOM','TEXT')
arcpy.AddField_management(Wells,'ConstTyDOM','TEXT')
#arcpy.AddField_management(Wells,'HoleDia','TEXT')
arcpy.AddField_management(Wells,'DiaUOM','TEXT')
#arcpy.AddField_management(Wells,'Depthto1st','TEXT')
#arcpy.AddField_management(Wells,'Depthtowat','TEXT')
#arcpy.AddField_management(Wells,'Depthtobdk','TEXT')
#arcpy.AddField_management(Wells,'Totaldepth','TEXT')
#arcpy.AddField_management(Wells,'ReferElev','TEXT')
#arcpy.AddField_management(Wells,'ElevUOM','TEXT')
arcpy.AddField_management(Wells,'DepthUOM','TEXT')
#arcpy.AddField_management(Wells,'Capacity','TEXT')
arcpy.AddField_management(Wells,'CapacUOM','TEXT')
arcpy.AddField_management(Wells,'FKWpumpID','TEXT')
arcpy.AddField_management(Wells,'FKWpumpID','TEXT')
arcpy.AddField_management(Wells,'FKTankID','TEXT')
arcpy.AddField_management(Wells,'FKInstInID','TEXT')
arcpy.AddField_management(Wells,'FKBuildngID','TEXT')
arcpy.AddField_management(Wells,'FKProjectID','TEXT')
arcpy.AddField_management(Wells,'FKStationID','TEXT')
arcpy.AddField_management(Wells,'FKFulzoneID','TEXT')
arcpy.AddField_management(Wells,'FKWatsectID','TEXT')
arcpy.AddField_management(Wells,'FKGaszoneID','TEXT')
arcpy.AddField_management(Wells,'FKHcszoneID','TEXT')
arcpy.AddField_management(Wells,'FKStosectID','TEXT')
arcpy.AddField_management(Wells,'Narrative','TEXT')
Wcur = arcpy.InsertCursor(Wells)
for row in rows:
#print row.well_name
t_row = Wcur.newRow()
t_row.PKWellID = row.well_name
t_row.WellStaDOM = row.welltype_desc
Wcur.insertRow(t_row)
#for row in rows:
#t_row = Wcur.newRow()
#t_row.PKWellID2 = row.station_name
#Wcur.insertRow(t_row)
cnxn.commit()
cursor.close()
cnxn.close()
del row
del rows
del cursor
del cnxn
Help greatly appreciated in advance. BArt
... View more
12-14-2011
02:42 PM
|
0
|
11
|
1294
|
POST
|
Hi, I am trying to connect to an external SQL server with a table with an x and y fields using pyodbc. Next I am making an XYEventLayer using arcpy, and then converting the XYEventLayer to a feature class. When I run the code outside of ArcView it chokes and says the dataset is not supported or does not exist. I am not sure if calling the APP keyword is the correct way to do this. When I use the ???arcpy.ListDatasets()??? command I just get ???()??? return. Thank you in advance for your help import arcpy
import pyodbc
from arcpy import env
cnxn = pyodbc.connect('Driver={SQL Server Native Client 10.0};UID=user;PWD=Pass;SERVER=****.usace.army.mil; DATABASE=ftord; APP=MyApp')
arcpy.env.workspace= 'MyApp'
in_Table = "dbo.Wells_view"
y_coords = "northing"
x_coords = "easting"
out_layer = "wells"
arcpy.env.overwriteOutput = 'true'
saved_Layer = r"G:\Temp\Bart\layers\Wells.lyr"
arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_layer)
arcpy.FeatureClassToFeatureClass_conversion("Wells", r"G:\Temp\Bart\scratch.gdb", "wells")
... View more
08-15-2011
04:08 PM
|
0
|
1
|
921
|
POST
|
Howdie, I just wrote my first python script that copies an even layer to a shp (yay!). It works fine when I run it in python window with the mxd already open. However, if I run the code without opening the mxd, I get the dataset "does not exist" error message, and if I run it outside of ArcMap entirely, I get a bunch of error messages. Ultimately, I want to schedule a task that runs the python script like an executable. I understand that the first case is probably due to the fact that I don't have a full path, but it is an event layer, so I am not sure what to put in the path. Any help would be greatly appreciated. Thanks, import arcpy
#set the overwrite option
arcpy.env.overwriteOutput = 'true'
#define the mxd
mxd = arcpy.mapping.MapDocument(r"G:\Temp\Bart\mxds\Parcel_map.mxd")
#copy specified layer to a new shapefile
arcpy.CopyFeatures_management("Transfer Status","G:\Temp\Bart\Shapefiles\PyTest6.shp")
... View more
07-21-2011
04:07 PM
|
0
|
1
|
589
|
POST
|
Hi , I'm unable to define new template locations in the registry. When I go to HKEY_LOCAL_MACHINE\Software\ESRI\Desktop10.0 I don't see any other options. I am running ArcMap 10 on win 7 64 bit. I did not have this issue with XP. Thanks in advance for your help.
... View more
06-17-2011
10:57 AM
|
0
|
0
|
329
|
POST
|
Hi. I've been using the CalulateAcres.dll script (http://arcscripts.esri.com/details.asp?dbid=12307) all the way through version 10 on XP. Recently we've upgraded to 64 bit running on Win 7. For a reason unknown to me, I can no longer add that dll or others to ArcMap. Any ideas on getting around this issue? I am not sure if it is Win 7, or 64bit issue. Thanks in advance.
... View more
06-08-2011
12:40 PM
|
0
|
4
|
1802
|
POST
|
"With python it's easy to access the toolbox, but how would we access a) the zoom to layer command, and b) the file export map tool, which is a very handy way to effectively merge lots of 24 bit color rasters simply by opening them all and exporting the overall map at great resolution." Hi Jim, I was wandering if you were successful in writing that python script.I am trying to do something similar. I'd apprecaite you reply, thanks.
... View more
11-02-2010
01:43 PM
|
0
|
0
|
404
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|