Example: Defining a Raster Feature Source

AutoCAD Map 3D Geospatial Platform API

 
Example: Defining a Raster Feature Source
 
 
 

Defining a raster feature source is similar to defining a vector feature source. The parameters vary depending on the provider. Most raster files do not contain coordinate system information, so it must be obtained some other way. This can be done using a world file or through additional configuration for the FDO provider. The following example uses the second method, adding resource data containing the configuration information.

The resource identifier contains the location in the resource repository for the feature source definition.

MgResourceIdentifier rasterId = new MgResourceIdentifier(
  "Library://rasterFeature.FeatureSource");
string xmlString;
FeatureSourceType fsType = new FeatureSourceType();
 
fsType.Provider = "Autodesk.Raster.3.2";
 
NameValuePairType param = new NameValuePairType();
param.Name = "DefaultRasterFileLocation";
param.Value = @"C:\some\folder\rasterfile.jpg";
fsType.Parameter = new NameValuePairType[] { param };
 
fsType.ConfigurationDocument = "config://rasterfile.jpg";
fsType.LongTransaction = "";
 
// Serialize the feature source object model to an xml string
using (StringWriter writer = new StringWriter())
{
  XmlSerializer xs = new XmlSerializer(fsType.GetType());
  xs.Serialize(writer, fsType);
  xmlString = writer.ToString();
}
 
byte[] unicodeBytes = Encoding.Unicode.GetBytes(xmlString);
byte[] utf8Bytes = Encoding.Convert(Encoding.Unicode,
  Encoding.UTF8, unicodeBytes);
MgByteSource xmlSource = 
  new MgByteSource(utf8Bytes, utf8Bytes.Length);
 
MgResourceService rs;
rs = AcMapServiceFactory.GetService(MgServiceType.ResourceService)
  as MgResourceService;
rs.SetResource(rasterId, xmlSource.GetReader(), null);

The configuration information varies depending on the FDO provider. The WMS, ODBC, and Raster providers may need additional configuration information. Refer to the FDO documentation in the Map SDK and in the AutoCAD Map 3D installation folder for more details.

The following reads the configuration from a file and stores it in the resource repository. Ensure that the data name matches the <ConfigurationDocument> element in the feature source definition.

MgByteSource source;
source = new MgByteSource(@"C:\some\folder\rasterconfig.xml");
rs.SetResourceData(rasterId, "config://rasterfile.jpg",
  MgResourceDataType.Stream, source.GetReader());