CreateLayer(Uri,ILayerContainerEdit,Int32,String) Method
In This Topic
Creates a new Layer instance with the specified path to a dataset and adds it to a container such as a map or a group layer. Optionally you can provide a name to override the default display name.
This method must be called on the MCT. Use QueuedTask.Run.
Syntax
Parameters
- dataUri
- An URI represents the path or url to a dataset or .lyrx or .lpkx file.
- container
- A map or group layer instance where the Layer will be added
- index
- The position of the layer in the map or group layer. 0 represents the top most position.
- layerName
- (optional) When it is not provided, the default display name gets used e.g. the dataset name or alias. (default value = "")
Exceptions
Example
Create and add a layer to the active map
{
//* string url = @"c:\data\project.gdb\DEM"; //Raster dataset from a FileGeodatabase
//* string url = @"c:\connections\mySDEConnection.sde\roads"; //FeatureClass of a SDE
//* string url = @"c:\connections\mySDEConnection.sde\States\roads"; //FeatureClass within a FeatureDataset from a SDE
//* string url = @"c:\data\roads.shp"; //Shapefile
//* string url = @"c:\data\imagery.tif"; //Image from a folder
//* string url = @"c:\data\mySDEConnection.sde\roads"; //.lyrx or .lpkx file
//* string url = @"c:\data\CAD\Charlottesville\N1W1.dwg\Polyline"; //FeatureClass in a CAD dwg file
//* string url = @"C:\data\CAD\UrbanHouse.rvt\Architectural\Windows"; //Features in a Revit file
//* string url = @"http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"; //map service
//* string url = @"http://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/FeatureServer/0"; //FeatureLayer off a map service or feature service
string urlRoads = @"c:\data\project.gdb\roads"; //FeatureClass of a FileGeodatabase
Uri uri = new Uri(urlRoads);
var newLayer = await QueuedTask.Run(() => LayerFactory.Instance.CreateLayer(uri, map));
}
Create a raster layer
{
string urlRatser = @"C:\Images\Italy.tif";
await QueuedTask.Run(() =>
{
// Create a raster layer using a path to an image.
// Note: You can create a raster layer from a url, project item, or data connection.
var rasterLayerToCreate = LayerFactory.Instance.CreateLayer(new Uri(urlRatser), map) as RasterLayer;
});
}
Create a mosaic layer
{
//Path to mosaic dataset
string urlItaly = @"C:\Images\countries.gdb\Italy";
// Create a mosaic layer using a path to a mosaic dataset.
// Note: You can create a mosaic layer from a url, project item, or data connection.
mosaicLayer = await QueuedTask.Run(() =>
LayerFactory.Instance.CreateLayer(new Uri(urlItaly), map) as MosaicLayer);
}
Create an image service layer
{
string urlToUse =
@"http://imagery.arcgisonline.com/arcgis/services/LandsatGLS/GLS2010_Enhanced/ImageServer";
// Create an image service layer using the url for an image service.
var isLayer = await QueuedTask.Run(() =>
LayerFactory.Instance.CreateLayer(new Uri(urlToUse), map) as ImageServiceLayer);
}
Create Stream Layer with URI
{
await QueuedTask.Run(() =>
{
var url = "https://geoeventsample1.esri.com:6443/arcgis/rest/services/AirportTraffics/StreamServer";
var createParam = new FeatureLayerCreationParams(new Uri(url))
{
IsVisible = false //turned off by default
};
streamLayer = LayerFactory.Instance.CreateLayer<StreamLayer>(createParam, map);
//or use "original" create layer (will be visible by default)
Uri uri = new Uri(url);
streamLayer = LayerFactory.Instance.CreateLayer(uri, map) as StreamLayer;
streamLayer.SetVisibility(false);//turn off
});
}
Requirements
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)
ArcGIS Pro version: 3.0 or higher.
See Also