Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Script runs in ArcMap but fails in Geoprocessing Service

$
0
0
This script works well when I run in in ArcMap, but when I create a geoprocessing service it fails. I have to create a geoprocessing service because I will use this in a Javascript webmap. Do you guys have any idea why it fails?



Also, in the python script I am not adding any parameters because in the javascript, the edit tool automatically creates a window for the users to enter data when they digitize the data. And the Stewardship feature class that is being pulled from a SDE geodatabase now will be replaced by the same data in a feature service, so I am not sure if this is the right way to do it anyway. Should I test it now with data directly from a feature service or is it ok to do this way? And Is it ok not to have any parameters? Thank you for any help! I have never used geoprocessing services, so I am just learning and any help is appreciated.

Code:

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Stewardship_From_ModelBuilder2.py
# Created on: 2013-09-03 10:53:25.00000
#  (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------

# Set the necessary product code
# import arcinfo


# Import arcpy module
import arcpy
from arcpy import env


# Local variables:

Stewardship = "Database Connections\Connection to tfsgis-iisd01.sde\sars.DBO.Stewardship"
Stewardship_FeatureToPoint1 = "\\\\tfscs-fp03\\Users\\iwilson\\Documents\\ArcGIS\\Default.gdb\\Stewardship_FeatureToPoint1"
Counties = "D:\\ArcGISData\\SARS\\Python_10April2013\\SARS.gdb\\Counties"
# Process: Feature To Point
arcpy.FeatureToPoint_management(Stewardship, Stewardship_FeatureToPoint1, "CENTROID")
arcpy.MakeFeatureLayer_management("Counties", "Counties_lyr")
arcpy.MakeFeatureLayer_management("Stewardship", "Stewardship_lyr")
# Process: Select Layer By Location (2)feat
arcpy.SelectLayerByLocation_management("Counties_lyr", "CONTAINS", Stewardship_FeatureToPoint1, "", "NEW_SELECTION")

countycode = tuple(arcpy.da.SearchCursor("Counties_lyr", "FIPS_TXT"))[0][0]
urows = arcpy.da.UpdateCursor(Stewardship, "County")
for urow in urows:
    urow[0] = countycode
    urows.updateRow(urow)

del urows, urow


import time
from datetime import datetime, date
#sim_date_counter = 1

with arcpy.da.UpdateCursor("Stewardship_lyr", ("FFY","DateStart")) as rows:
  for row in rows:
    #get the value of the date

    FFY = row[0]
    FFYnumber = int(FFY)
    #convert to string
    DateStart = row[1]
    DateStartstr = str(DateStart)
    arcpy.AddMessage(DateStartstr)
    # Get only the month
    # To get only the first two characters:
    DateStart2 = DateStartstr[0:2]
    arcpy.AddMessage(DateStart2)
    if "/" in DateStart2:
                # if for example 6/28/2013
            DateStart3 = DateStart[0:1]
            FFYnumbercount = FFYnumber
            arcpy.AddMessage(DateStart3)
            arcpy.AddMessage(FFYnumbercount)
    if "/" not in DateStart2:
        # if for example 10/10/2013
        DateStart4 = int(DateStart2)
        FFYnumbercount = FFYnumber + 1

        arcpy.AddMessage(DateStart4)
        arcpy.AddMessage(FFYnumbercount)
    row[0] = str(FFYnumbercount)

    rows.updateRow(row)


Viewing all articles
Browse latest Browse all 2485

Trending Articles