ScottSugden

Find by attribute tool to return original ObjectID and in correct spatial reference

Discussion created by ScottSugden on Mar 10, 2012
Latest reply on Mar 13, 2012 by ScottSugden
Hi,

Using a GP tool (via SOAP API) I am trying create a 'Find by attribute tool' to that returns the original/searched layer ObjectID and geometry in the correct spatial reference/coordinate system. I have no problems passing the find attribute values, selecting the correct layer (from a mxd) to search and returning some results. My issue is that I can only either:
'1' Return the rows in the correct mxd spatial reference but with autogenerated ObjectIDs (not the original objectids that I require) or
'2' Return the rows with the correct searched layer ObjectIDs but in the searched layer coordinate system rather than the mxd coordinate system

I have tried various approaches to get result '1' including using:
arcpy.SearchCursor eg

mxd = arcpy.mapping.MapDocument(MXD_PATH)
df = arcpy.mapping.ListDataFrames(mxd)[0]
sr = df.spatialReference
arcpy.env.outputCoordinateSystem = sr
layer = arcpy.mapping.ListLayers(mxd, CADASTRE_LAYER_NAME)[0]
rowsSearch = arcpy.SearchCursor(layer, whereSql)
fc = arcpy.CreateFeatureclass_management("in_memory", "tempFindLotDpFc", "POLYGON", layer)
rowsNew = arcpy.InsertCursor(fc)
for rowSearch in rowsSearch:
   rowsNew.insertRow(rowSearch)
fs = arcpy.FeatureSet()
fs.load(fc)


arcpy.Select_analysis eg

mxd = arcpy.mapping.MapDocument(MXD_PATH)
df = arcpy.mapping.ListDataFrames(mxd)[0]
sr = df.spatialReference
arcpy.env.outputCoordinateSystem = sr
layer = arcpy.mapping.ListLayers(mxd, CADASTRE_LAYER_NAME)[0]
fc = arcpy.CreateFeatureclass_management("in_memory", "tempFindLotDpFc", "POLYGON", "", "", "", sr)
arcpy.Select_analysis(layer, fc, whereSql)
fs = arcpy.FeatureSet()
fs.load(fc)


I have tried updating the field OBJECTID in the fc but it is always read only. I have also tried using tables instead of feature classes with no success as OBJECTID is still read only.

Method 2 uses something like:

mxd = arcpy.mapping.MapDocument(MXD_PATH)
df = arcpy.mapping.ListDataFrames(mxd)[0]
sr = df.spatialReference
arcpy.env.outputCoordinateSystem = sr
layer = arcpy.mapping.ListLayers(mxd, CADASTRE_LAYER_NAME)[0]
arcpy.MakeTableView_management(layer, "tv", whereSql)
fs = arcpy.FeatureSet()
fs.load("tv")


Any suggestions would be greatly appreciated. Thanks

Outcomes