Select to view content in your preferred language

create specified point with python

3568
6
05-10-2010 01:14 AM
alifardy
Emerging Contributor
with python, i want to create point feature class. how to create point in specified coordinate but not from a file which contain coordinate. i have try to make the script but there was an error " 'list' object is not callable. ". anyone have an explanation?

# Process: Add Field...
gp.AddField_management(InputFC__2_, "V", "DOUBLE", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")

# Process: Calculate Field...
gp.CalculateField_management(InputFC, "V", " * ", "VB", "")

# Process: Summary Statistics...
gp.Statistics_analysis(InputFC__3_, InputFC_Statistics_dbf, "D SUM;V SUM", "")

# create the output feature class using the spatial reference object
gp.CreateFeatureClass(New_Folder,OutputFC,"Point","ENABLED","DISABLED",spatialRef)

gp.AddField_management(OutputFC,"D","DOUBLE","", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
gp.AddField_management(OutputFC__2_,"H","DOUBLE","", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")

rows = gp.SearchCursor(InputFC_Statistics_dbf)
row = rows.Next()
while row:
count1 = row.SUM_V
count2 = row.SUM_D

prows = gp.InsertCursor(OutputFC__3_)
# create point object to create feature
pnt = gp.CreateObject("Point")
pnt.id = 1
pnt.x = 566020
pnt.y = 252044

prow = prows.NewRow()
prow.Shape = Point
prow.Dt = count2
prow.H = count1 / count2
Point.Add(pnt)
prows.InsertRow(prow)
row = rows.Next()

del prow, prows
del row, rows
0 Kudos
6 Replies
DarshaHardy
Emerging Contributor
What version of ArcGIS are you using (otherwise folks may provide helpful advice you can't implement)?

Could you edit your post to wrap the code in a code tag so the indentation is visible.

Can you step through the code in your code editor to see what line it falls over on?
0 Kudos
alifardy
Emerging Contributor
Actually I use Argis 9.3. sorry, i can't edit the indentation in the script, but i mark it with red colour. probably the problem occur in "create feature class" command, or in "insert cursor", this is confusing.

# Process: Add Field...
gp.AddField_management(InputFC__2_, "V", "DOUBLE", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")

# Process: Calculate Field...
gp.CalculateField_management(InputFC, "V", " * ", "VB", "")

# Process: Summary Statistics...
gp.Statistics_analysis(InputFC__3_, InputFC_Statistics_dbf, "D SUM;V SUM", "")

# create the output feature class using the spatial reference object
gp.CreateFeatureClass(New_Folder,OutputFC,"Point", "ENABLED","DISABLED",spatialRef)

gp.AddField_management(OutputFC,"D","DOUBLE","", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
gp.AddField_management(OutputFC__2_,"H","DOUBLE"," ", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")

rows = gp.SearchCursor(InputFC_Statistics_dbf)
row = rows.Next()
while row:
count1 = row.SUM_V
count2 = row.SUM_D

prows = gp.InsertCursor(OutputFC__3_)
# create point object to create feature
pnt = gp.CreateObject("Point")
pnt.id = 1
pnt.x = 566020
pnt.y = 252044

prow = prows.NewRow()
prow.Shape = Point
prow.Dt = count2
prow.H = count1 / count2
Point.Add(pnt)
prows.InsertRow(prow)
row = rows.Next()

del prow, prows
del row, rows
0 Kudos
DarshaHardy
Emerging Contributor
Are you not able to step though your code in debugging mode to see where your error occurs?

Try breaking things down into smaller pieces, maybe CreateFeatureclass is falling over on something as simple as the a typo in the folder path
0 Kudos
GünterDörffel
Frequent Contributor
Hi,

I wont check through all your code, but there actually is one very prominent error:

you coded:

prows = gp.InsertCursor(OutputFC__3_)
# create point object to create feature
pnt = gp.CreateObject("Point")
pnt.id = 1
pnt.x = 566020
pnt.y = 252044

prow = prows.NewRow()
prow.Shape = Point
prow.Dt = count2
prow.H = count1 / count2
Point.Add(pnt)
prows.InsertRow(prow)
row = rows.Next()


which wont work, since you assign Point to the shape of the newly added record ... this does not exist!

try:
prows = gp.InsertCursor(OutputFC__3_)
# create point object to create feature
pnt = gp.CreateObject("Point")
pnt.id = 1
pnt.x = 566020
pnt.y = 252044

prow = prows.NewRow()
prow.Shape = pnt


here - to continue I'd use:
prow.SetValue("Dt", count2)
prow.SetValue("H" , count1 / count2)

this line here is wrong anyway and obsolete now
Point.Add(pnt)


this should be the correct end of your code:
prows.InsertRow(prow)
row = rows.Next()


so altogether this section should read:
prows = gp.InsertCursor(OutputFC__3_)
pnt = gp.CreateObject("Point")
pnt.id = 1
pnt.x = 566020
pnt.y = 252044

prow = prows.NewRow()
prow.Shape = pnt
prow.SetValue("Dt", count2)
prow.SetValue("H" , count1 / count2)
prows.InsertRow(prow)
row = rows.Next()


Hope this helps
Regards
Guenter
0 Kudos
alifardy
Emerging Contributor
Thanks to Guenter Doerffel, but there is another error with the script, "create feature class" process still didn't work. the error message is:

<class 'arcgisscripting.ExecuteError'>: ERROR 000622: Failed to execute (Create Feature Class). Parameters are not valid.
ERROR 000623: Invalid value type for parameter has_z.

all data type in calculation process is "DOUBLE", and input feature class doesn't has Z values. is the problem in the input file or in script?
0 Kudos
DarshaHardy
Emerging Contributor
I think you're missing a value for the (optional) template parameter in CreateFeaturecClass

CreateFeatureClass_management (out_path, out_name, geometry_type, template, has_m, has_z, spatial_reference, config_keyword, spatial_grid_1, spatial_grid_2, spatial_grid_3)
0 Kudos