ceicher

Unable to read data from Query Layer

Discussion created by ceicher on Mar 19, 2012
Latest reply on Sep 25, 2012 by jpenney
Hi,

I'm unable to use Python/Geoprocessing to read data from an ESRI Query Layer. How can I make this work?

I've tried two things:
1) Use Make Feature Layer to read from .lyr

Reference: http://forums.arcgis.com/threads/584-beta-10-system-tool-for-extracting-query-layer-data-to-file-gdb

Code explained: Works for .lyr based on layer (data source is sde spatial view which arcgis sees as a feature class). Does not work for .lyr based on query layer (data source is sde view which arcgis sees as a table).

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

arcpy.AddMessage("start script....")

#lyr = "C:\Projects\BranchMapping\dev\src\GP_Tasks\ppOwner.lyr"
lyr = "C:\Projects\BranchMapping\dev\src\GP_Tasks\BRANCHES.lyr"

#qry = "KeyInstn = 4001616" # D
qry = "KeyInstn = 4019974" # VABK

arcpy.AddMessage("Making feature layer....")
arcpy.MakeFeatureLayer_management(lyr, "lyr", qry)

arcpy.AddMessage("Getting count....")
result = arcpy.GetCount_management("lyr")

count = int(result.getOutput(0))
arcpy.AddMessage(str(count))


2) MakeQueryTable

Reference: http://forums.arcgis.com/threads/25496-Query-Layer?highlight=query+layer+geoprocessing+python

Opening the tool I browse to the sde view. Afterwards I get this error: ERROR 000793
Invalid data element type ERROR 000840: The value is not a Raster Layer.

I read the doc, but I don't understand. Can I use this tool to create a layer from a "query layer" table data source (i.e. same data source that I can use to create a Query Layer in ArcMap).

Does ESRI have a way to use PY to read data from a Query Layer data source?

Thanks,

-Cory

Outcomes