Select to view content in your preferred language

[ArcGIS 9.3.1] FeatureClass problem in Python

2915
5
10-29-2010 11:36 PM
GELIG
by
Emerging Contributor
hi all,

I verified that I work under ArcGIS 9.3.1.
My code dont work,I dont understand why ! I become crazy. Someone could help me ?
Very simple code:
 mygp = load(version=9.3) # load geoprocessor
 mygp.OverWriteOutput = True
 desc = mygp.describe("c:\temp\VillageSurvey.mdb\Land")
 mygp.AddMessage(str(desc.Extent)) #that is ok
 fcs = mygp.FeatureClass # dont work ! same case for FIDSet property for a layer

Msg is <type 'exceptions.AttributeError'>: Object: Tool or environment <FeatureClass> not found

thanks for any help !
0 Kudos
5 Replies
RichardFairhurst
MVP Alum
hi all,

I verified that I work under ArcGIS 9.3.1.
My code dont work,I dont understand why ! I become crazy. Someone could help me ?
Very simple code:
 mygp = load(version=9.3) # load geoprocessor
 mygp.OverWriteOutput = True
 desc = mygp.describe("c:\temp\VillageSurvey.mdb\Land")
 mygp.AddMessage(str(desc.Extent)) #that is ok
 fcs = mygp.FeatureClass # dont work ! same case for FIDSet property for a layer

Msg is <type 'exceptions.AttributeError'>: Object: Tool or environment <FeatureClass> not found

thanks for any help !


I believe you made an error in the line that reads:

fcs = mygp.FeatureClass # dont work ! same case for FIDSet property for a layer

it seems that it should read:

fcs = desc.FeatureClass # change from gp object to describe object
0 Kudos
GELIG
by
Emerging Contributor
I tell you that I became crazy. Yes I made a mistake in the the post. the real line is :
fcs = desc.FeatureClass and the error msg is : <type 'exceptions.RuntimeError'>: DescribeData: Method FeatureClass does not exist


I believe you made an error in the line that reads:

fcs = mygp.FeatureClass # dont work ! same case for FIDSet property for a layer

it seems that it should read:

fcs = desc.FeatureClass # change from gp object to describe object
0 Kudos
RichardFairhurst
MVP Alum
You cannot read FeatureClass as a property of the describe, it is just a heading for a property group in the gp programming model, but you can read any of the properties for the FeatureClass that are listed under the FeatureClass property group in the gp programming model.  For example you can read FeatureType.  I tested the code below and it works (with one of my featureclasses in the place of yours).  I do not know why the FIDSet property did not work.  Perhaps it did not work because the object you described was just a featureclass and not a layer.  I think you would have to use the mygp.CreateLayer_Management tool (or whatever it is that creates a layer from a feature class) and describe the layer to get that property.

import arcgisscripting
#Process: Create the gp object
mygp = arcgisscripting.create(9.3)
mygp.OverWriteOutput = True
desc = mygp.describe("c:\\temp\\VillageSurvey.mdb\\Land") # added slashes to read as file name
mygp.AddMessage(str(desc.Extent)) #that is ok
fcs = desc.featuretype # works !
0 Kudos
GELIG
by
Emerging Contributor
Thank you for your time.
Layer is a properties of FeatureClass. I dont understand why FIDSet dont work.
Be sure that Land is a a layer (parcel land from geodatabase)
1- Try desc.Layer.FIDSet --> dont work
2- Try mygp.MakeFeatureLayer_management(desc.CatalogPath,"out").FIDSet ---> dont work also

The question is how instantiate an object FeatureClass to access Layer properties.

Thanks a lot.


You cannot read FeatureClass as a property of the describe, it is just a heading for a property group in the gp programming model, but you can read any of the properties for the FeatureClass that are listed under the FeatureClass property group in the gp programming model.  For example you can read FeatureType.  I tested the code below and it works (with one of my featureclasses in the place of yours).  I do not know why the FIDSet property did not work.  Perhaps it did not work because the object you described was just a featureclass and not a layer.  I think you would have to use the mygp.CreateLayer_Management tool (or whatever it is that creates a layer from a feature class) and describe the layer to get that property.

import arcgisscripting
#Process: Create the gp object
mygp = arcgisscripting.create(9.3)
mygp.OverWriteOutput = True
desc = mygp.describe("c:\\temp\\VillageSurvey.mdb\\Land") # added slashes to read as file name
mygp.AddMessage(str(desc.Extent)) #that is ok
fcs = desc.featuretype # works !
0 Kudos
RichardFairhurst
MVP Alum
Thank you for your time.
Layer is a properties of FeatureClass. I dont understand why FIDSet dont work.
Be sure that Land is a a layer (parcel land from geodatabase)
1- Try desc.Layer.FIDSet --> dont work
2- Try mygp.MakeFeatureLayer_management(desc.CatalogPath,"out").FIDSet ---> dont work also

The question is how instantiate an object FeatureClass to access Layer properties.

Thanks a lot.


You are incorrect about some of your ideas. 

1. A Layer is a separate object that depends on a FeatureClass, but a FeatureClass exists independently from a Layer.  So while a FeatureClass can be accessed as a property of a described Layer, a Layer cannot be accessed directly from a described FeatureClass, it has to be created from the FeatureClass first before you can access its properties.
2.  You are bypassing the describe of the Layer object that is created by the MakeFeatureLayer_management tool.  Each new object needs its own describe to access its describe properties.  I believe the code needs to read:

Lyr = mygp.MakeFeatureLayer_management(desc.CatalogPath,"out")
descLyr = describe(Lyr)
myFIDset = descLyr.FIDSet
myFC = descLyr.FeatureClass # works because a FeatureClass is a property of a described Layer, but not the other way around


The code above preserves both the Layer object itself for use in other gp tool processes and creates a describe object to access the describe properties of the layer for python processing and programming logic.  It also provides a FeatureClass object for any tools that require that as an input.  A FeatureClass is not a property of FeatureClass.  It is the object type itself.  This is why you could not access it as a property of the first describe from the FeatureClass.

The gp Programming diagram shows that a FeatureClass inherits properties from a Table and a DataSet.  A Dataset includes an Extent property, which is why that property worked.  But a FeatureClass does not inherit properties from a Layer.

A Layer shows that it inherits properties from a FeatureClass.  It therefore should also inherit properties from Table and Dataset.  So both Lyr.FeatureType and Lyr.Extent should work.
0 Kudos