Non-deprecated way to access IRaster in Java SOE?

764
9
04-09-2013 05:41 PM
EricRussell
New Contributor
As far as I can tell, the only way to get an IRaster from an IMapServerDataAccess in a Java Server Object Extension is to create a new com.esri.arcgis.datasourcesraster.Raster, like this:

[indent]
IMapServerDataAccess dataAccess = (IMapServerDataAccess)mapServer;
return new Raster(dataAccess.getDataSource(mapServer.getDefaultMapName(), 0));
[/indent]

This works, but the one-argument constructor for Raster is deprecated. Is there a non-deprecated way to get the data source as an IRaster?
0 Kudos
9 Replies
LeoDonahue
Occasional Contributor III
Hey Eric,

The IMapServerDataAccess Interface docs indicate that getDataSource(String mapName,              int layerID) returns one of the following:


Get Data Source
This function allows fine-grained object access to a FeatureLayer, a RasterLayer or a StandaloneTable by returning IFeatureClass, IRaster or ITable respectively. If the layer or standalone table has any joins, the returned object will not contain the joined portion. In addition any field visibility or field alias set to the layer in the source map document will be ignored as it returns the underlying data source.


And, the Raster class docs indicate that even though the method you used is deprecated, that you can simply cast the object to Raster.
0 Kudos
EricRussell
New Contributor
Hi Leo,

The documentation certainly seems to indicate that the result of getDataSource can be cast directly to an IRaster or IFeatureClass, but that's actually not the case. The getDataSource method returns a com.esri.arcgis.interop.RemoteObjRef, which can't be cast to an IRaster or IFeatureClass. You have to wrap in in a call to new FeatureClass(Object) or new Raster(Object). This isn't in the documentation, but it is in the sample code.

Eric
0 Kudos
LeoDonahue
Occasional Contributor III
Just so I can compare apples to apples, what is your layer 0?  A mosaic?  A raster catalog?  Something else?
0 Kudos
EricRussell
New Contributor
It's just a regular raster layer, displaying an 8-bit unsigned file geodatabase raster dataset of flow direction data.
0 Kudos
LeoDonahue
Occasional Contributor III
Ok, if regular Raster layer, then can't you do this:

RasterLayer rl = (RasterLayer) mapServer.getLayer("Layers", 0);
System.out.println(rl.getSpatialReference().getName());
System.out.println(rl.getFilePath());
0 Kudos
EricRussell
New Contributor
That may work. I'll give it a try when I'm back in the office tomorrow. But I was under the impression that you can't use the getLayer method from an SOE at all as of 10.1, because it's not supported on optimized map services (see, for example, http://blogs.esri.com/esri/arcgis/2010/11/12/accessing-optimized-map-services-with-server-object-ext... and http://blogs.esri.com/esri/arcgis/2011/11/15/whats-new-for-java-server-object-extension-builders/).
0 Kudos
LeoDonahue
Occasional Contributor III
But I was under the impression that you can't use the getLayer method from an SOE at all as of 10.1, because it's not supported on optimized map services

Did you tell anyone in the original post you were using 10.1 with optimized map services?  No.

I was going to remind you where to go from IRasterLayer, but it doesn't matter now.


A Raster can be created in three ways:
1. Get from a RasterLayer using IRasterLayer::Raster
2. Create from a raster dataset using either :IRasterDataset::CreateDefaultRaster or IRasterDataset2::CreateFullRaster
3. Cocreate a Raster and append raster bands using IRasterBandCollection interface.


0 Kudos
EricRussell
New Contributor
Sorry, I thought it was implied by the fact that I was using IMapServerDataAccess. As of 10.1, all map services are optimized map services, so you have to use IMapServerDataAccess to access map data from an SOE.

Just to be sure, I tried using getLayer(String,int) and it fails with an AutomationException (no such interface supported).

Thanks,
Eric
0 Kudos
LeoDonahue
Occasional Contributor III
Well, I'm out of options.  Not being on 10.1 doesn't help me help you either.

Since the 10.1 samples show this:

  FeatureClass fc = new FeatureClass(this.mapServerDataAccess.getDataSource(mapName, layerId)); 


It stands to reason that one could do this... I guess not though.

 IRaster raster = this.mapServerDataAccess.getDataSource(mapName, layerId); 


If getDataSource on IMapServerDataAccess doesn't do this,
This function allows fine-grained object access to a FeatureLayer, a RasterLayer  or a StandaloneTable by returning IFeatureClass, IRaster or ITable respectively.

then maybe we need to report it?
0 Kudos