2

I'm trying to programmatically export a symbolized raster to an RGB TIF using ArcGIS, i.e.: perform the equivalent of Export Raster Data in ArcMap with Use Renderer and Force RGB activated.

I followed the beginning of Use python to disable "Scale map elements proportionally to changes in page size" to access ArcObjects in Python.

I'm trying to re-create the code in this discussion to eventually create a RasterLayerExport object. Before that, though, I find myself incapable of creating a WorkspaceFactory.

I tried running:

import arcpy

from snippets102 import *
from comtypes.client import GetModule, CreateObject

import comtypes.gen.esriFramework as esriFramework
import comtypes.gen.esriArcMapUI as esriArcMapUI
import comtypes.gen.esriCarto as esriCarto
import comtypes.gen.esriDisplay as esriDisplay
import comtypes.gen.esriGeoDatabase as esriGeoDatabase

wkspf = CreateObject(esriGeoDatabase.WorkspaceFactory, interface = esriGeoDatabase.IWorkspaceFactory)

But this gives me the following error:

Traceback (most recent call last):
  File "C:/Users/AndyPL/.PyCharmCE2017.2/config/scratches/scratch_1.py", line 14, in <module>
    wkspf = CreateObject(esriGeoDatabase.WorkspaceFactory, interface=esriGeoDatabase.IWorkspaceFactory)
  File "C:\Python27\ArcGIS10.4\lib\site-packages\comtypes\client\__init__.py", line 238, in CreateObject
    obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
  File "C:\Python27\ArcGIS10.4\lib\site-packages\comtypes\__init__.py", line 1225, in CoCreateInstance
    _ole32.CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
  File "_ctypes/callproc.c", line 945, in GetResult
WindowsError: [Error -2147221164] Class not registered

Odd, since creating a PlugInWorkspaceFactory works fine. Does anyone else get this error?

  • 1
    This is one of the odd ones, you create an IWorkspaceFactory from the workspace type: AccessWorkspaceFactory for personal GDB, FileGDBWorkspaceFactory for file GDB etc.. see the coclasses at resources.arcgis.com/en/help/arcobjects-net/componenthelp/… and look at the example resources.arcgis.com/en/help/arcobjects-net/componenthelp/… for ShapefileWorkspaceFactory (ctrl + F to find it). Clearly on line 11 of the example the workspacefactory is being created as RasterWorkspaceFactory. – Michael Stimson Oct 12 '17 at 0:32
  • Thanks (again) for your answer Michael. So would it be something like wkspf = CreateObject(esriGeoDatabase.RasterWorkspaceFactory, interface = esriGeoDatabase.IWorkspaceFactory)? – Andrew Plowright Oct 12 '17 at 1:43
  • 1
    The RasterWorkspaceFactory is in DataSourcesRaster, see resources.arcgis.com/en/help/arcobjects-net/componenthelp/… I'm not sure what the arcpy import is for that, presumably import comtypes.gen.esriDataSourcesRaster as esriDataSourcesRaster. Were I certain of this I would have posted an answer; When you sort this out can you post your working code as an answer to your own question, I too would be interested to see it. – Michael Stimson Oct 12 '17 at 2:18
2

Thanks to Michael Stimson for figuring this one out.

In this specific example, what I needed was a RasterWorkspaceFactory, and not a WorkspaceFactory.

from snippets102 import *
from comtypes.client import GetModule, CreateObject

import comtypes.gen.esriGeoDatabase as esriGeoDatabase
import comtypes.gen.esriDataSourcesRaster as esriDataSourcesRaster

wkDir = "C:/YourWorkspace/"

wkspf = CreateObject(esriDataSourcesRaster.RasterWorkspaceFactory, interface=esriGeoDatabase.IWorkspaceFactory)
wksp = wkspf.OpenFromFile(wkDir, 0)

I'm afraid I still don't know how to access WorkspaceFactory, though.

  • 1
    There is no WorkspaceFactory (generic), this is a very odd object in that the IWorkspaceFactory interface is initialized with a CoClass only. Normaly an interface is initialized with the same class, IPoint for example is initialized to PointClass() in C# esriGeometry.Point in python. Another example of this odd instantiation is IPointCollection, there is no PointCollection class, the interface is initialized as one of the CoClasses (Ring, Path, Multipoint etc..). – Michael Stimson Oct 12 '17 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.