Arcgisscripting in ArcGIS10.1

6869
6
Jump to solution
04-24-2012 06:40 AM
ScottBlankenbeckler
Occasional Contributor
I recently installed the ArcGIS 10.1 pre-release and now one of my python scripts is no longer working. Is arcgisscripting no longer supported? Or did they change the functionality?

 gp = arcgisscripting.create(9.3) ... ... while sRow:      pt = sRow.GetValue(shapeName).GetPart(0) ...


Now throws an error..


File "S:\scripts\test.py", line 91, in convertPointsToLine
pt = sRow.GetValue(shapeName).GetPart(0)
AttributeError: 'NoneType' object has no attribute 'GetPart'
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JasonScheirer
Occasional Contributor III
This was actually a fix for what was previously a bug -- a NULL geometry has no parts, so it no longer returns a Geometry object, but None.

Split this up:

pt = row.getValue(shapeField).getPart(0)

into:

val = row.getValue(shapeField) if val:     pt = val.getPart(0) else:     pt = None


Everything written using arcgisscripting should continue to work, this is a weird corner case where your script was depending on incorrect behavior in arcgisscripting that was hard to test against.

View solution in original post

0 Kudos
6 Replies
MathewCoyle
Frequent Contributor
Did it work in 10?

I'll work with the assumption that it didn't since it has some incorrect formatting even for 10.

Try this

shapeField = desc.shapeFieldName
sRow = arcpy.SearchCursor(fc)
for row in sRow:
    pt = row.getValue(shapeField).getPart(0)
0 Kudos
ScottBlankenbeckler
Occasional Contributor
Actually it does work in 10.0.  I only included the line which appears to be broken now in 10.1. But for clarification I will include all of the code up to the point where it breaks.

import arcgisscripting
import os
import types
def convertPoints(inPts, outFeatures, IDField, cursorSort, close):
    gp = arcgisscripting.create(9.3)
    gp.OverWriteOutput = 1
    # Input point FC
    # Output FC
    # Feature Field
    # Sort Field
    # Close Line or Leave Open
#    inPts       = gp.GetParameterAsText(0)
#    outFeatures = gp.GetParameterAsText(1)
#    IDField     = gp.GetParameterAsText(2)
    sortField   = '#'#gp.GetParameterAsText(3)
    closeLine   = "false"#gp.GetParameterAsText(4)
    if IDField in ["", "#"]: IDField = None
    if sortField in ["", "#"]:
        cursorSort = IDField
    else:
        if IDField:
            cursorSort = IDField + ";" + sortField
        else:
            cursorSort = sortField
    if types.TypeType(closeLine) != types.BooleanType:
        if closeLine.lower() == "false":
            close = False
        else:
            close = True
    convertPointsToLine(gp, inPts, outFeatures, IDField, cursorSort, close)
def enableParam(hasMZ):
    if hasMZ:
        return "ENABLED"
    else:
        return "DISABLED"
            
def convertPointsToLine(gp, inPts, outFeatures, IDField, cursorSort, close):
    #try:
    if 1 == 1:
        # Assign empty values to cursor and row objects
        iCur, sRow, sCur, feat = None, None, None, None
        desc = gp.Describe(inPts)
        shapeName = desc.ShapeFieldName
        # Create the output feature class
        #
        outPath, outFC = os.path.split(outFeatures)
        gp.CreateFeatureclass_management(outPath, outFC, "POLYLINE", "",
                                         enableParam(desc.hasM),
                                         enableParam(desc.hasZ),
                                         inPts)
        # If there is an IDField, add the equivalent to the output
        #
        if IDField:
            f = gp.ListFields(inPts, IDField)[0]
            tMap = {'Integer': 'LONG', 'String': 'TEXT', 'SmallInteger': 'SHORT'}
            fType = f.type
            if tMap.has_key(fType):
                fType = tMap[fType]
            fName = gp.ValidateFieldName(f.name, outPath)
            gp.AddField_management(outFeatures, fName, fType, f.precision, f.scale, f.length,
                                   f.aliasName, f.isNullable, f.required, f.domain)
        # Open an insert cursor for the new feature class
        #
        iCur = gp.InsertCursor(outFeatures)
        sCur = gp.SearchCursor(inPts, "", None, cursorSort, cursorSort)
        sRow = sCur.Next()
        # Create an array and point object needed to create features
        #
        array = gp.CreateObject("Array")
        pt = gp.CreateObject("Point")
        pt2 = gp.CreateObject("Point")
        # Initialize a variable for keeping track of a feature's ID.
        #
        ID = -1
        while sRow:
            pt = sRow.GetValue(shapeName).GetPart(0)
            
            # If last point and this point are at identical locations
            # nudge it about 1.5 meters to make a line                  
            if pt2.X == pt.X and pt2.Y == pt.Y:
                pt.Y = pt.Y + 0.00001
                pt.X = pt.X + 0.00001


I have been running this code for months in 10.0 with no problems. But once I installed 10.1 it no longer works.  ESRI changed something, what I don't know but it broke my code and now I have to figure out how to fix it.
0 Kudos
MathewCoyle
Frequent Contributor
Rewrite it using arcpy instead of arcgisscripting would be my suggestion. Have you tried creating the gp without forcing to 9.3?
gp = arcgisscripting.create()


A while ago a post here by Esri stated it would still be available in 10.1, so not sure what the issue is as I haven't dabble in 10.1 myself yet.
http://forums.arcgis.com/threads/44713-Confirm-deprecation-of-arcgisscripting-at-10.1
0 Kudos
ScottBlankenbeckler
Occasional Contributor
Rewrite it using arcpy instead of arcgisscripting would be my suggestion. Have you tried creating the gp without forcing to 9.3?
gp = arcgisscripting.create()


A while ago a post here by Esri stated it would still be available in 10.1, so not sure what the issue is as I haven't dabble in 10.1 myself yet.
http://forums.arcgis.com/threads/44713-Confirm-deprecation-of-arcgisscripting-at-10.1


I am hoping that I wont have to rewrite it with arcpy, but its not looking good. As for not forcing the 9.3.. That doesn't work either as the script calls functionality that was not supported in earlier releases (f = gp.ListFields(inPts, IDField)[0]).

BTW the original script was downloaded from here http://arcscripts.esri.com/details.asp?dbid=15945 It has been modified slightly to handle points which geocode at the same location (i.e. apartments and suites), so an error is not thrown for 0 distance lines.
0 Kudos
JasonScheirer
Occasional Contributor III
This was actually a fix for what was previously a bug -- a NULL geometry has no parts, so it no longer returns a Geometry object, but None.

Split this up:

pt = row.getValue(shapeField).getPart(0)

into:

val = row.getValue(shapeField) if val:     pt = val.getPart(0) else:     pt = None


Everything written using arcgisscripting should continue to work, this is a weird corner case where your script was depending on incorrect behavior in arcgisscripting that was hard to test against.
0 Kudos
JayJohnson2
Occasional Contributor