Python to create rectangle geometry works in 9.3.1, but doesn't work in 10.0 SP2

305
2
06-20-2011 10:42 AM
deleted-user-Ohz6rwd1kavx
New Contributor III
Hi,

The code at the bottom of the following thread works like a charm in 9.3.1....

http://forums.esri.com/thread.asp?t=280489&c=93&f=1729

... but it doesn't work in 10.0 SP2. In 10.0 SP2, the script executes, but the inserted row has no geometry.

I've included my 10.0 SP2 code below. Anyone know how I can get this to work in 10?

Thanks,

-Cory

# Import system modules
import sys, string, os, arcpy

# Create the Geoprocessor object
ary = arcpy.CreateObject("Array")
pnt = arcpy.CreateObject("Point")

## create rect starting lower right going clockwise
pnt.x = -117.0
pnt.y = 35
ary.add(pnt)

pnt.x = -117.0
pnt.y = 35.75
ary.add(pnt)

pnt.x = -116.25
pnt.y = 35.75
ary.add(pnt)

pnt.x = -116.25
pnt.y = 35
ary.add(pnt)

## redo first point (lower right)
pnt.x = -117.0
pnt.y = 35
ary.add(pnt)
## -------------------------------------------------------------

AOI = "C:\\Temp\\test7.shp"
ScratchWS = "C:\\Temp"

# Process: Create AOI Feature Class...
arcpy.CreateFeatureclass_management(ScratchWS, "test7", "POLYGON", "", "DISABLED", "DISABLED", "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];IsHighPrecision", "", "0", "0", "0")
cur = arcpy.InsertCursor(AOI)
feat = cur.newRow()
feat.shape = ary
cur.insertRow(feat)
0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor
Cory,

See amended code and my notes.

Duncan

# Import system modules
import sys, string, os, arcpy

# Create the Geoprocessor object
# NOTE: DO NOT USE CREATEOBJECT METHOD
ary = arcpy.Array()
pnt = arcpy.Point()

## create rect starting lower right going clockwise
# NOTE: THE x & y PROPERTY ARE IN CAPITALS
pnt.X = -117.0
pnt.Y = 35
ary.add(pnt)

pnt.X = -117.0
pnt.Y = 35.75
ary.add(pnt)

pnt.X = -116.25
pnt.Y = 35.75
ary.add(pnt)

pnt.X = -116.25
pnt.Y = 35 
ary.add(pnt)

## redo first point (lower right)
pnt.X = -117.0
pnt.Y = 35
ary.add(pnt)

## -------------------------------------------------------------

AOI = "C:\\Temp\\test9.shp"
ScratchWS = "C:\\Temp"

# Process: Create AOI Feature Class...
arcpy.CreateFeatureclass_management(ScratchWS, "test9", "POLYGON", "", "DISABLED", "DISABLED", "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];IsHighPrecision", "", "0", "0", "0")
cur = arcpy.InsertCursor(AOI)
feat = cur.newRow()
feat.shape = ary
cur.insertRow(feat)
0 Kudos
deleted-user-Ohz6rwd1kavx
New Contributor III
Hi Duncan,

Huge thanks sir.

I made the recommended adjustments to my script, and it now runs flawlessly in 10.0 SP2.

Not using CreateObject seemed to be the trick.

Thanks,

-Cory
0 Kudos