Hi AI,
Because GeoTiffRasterLayer has some performance issue, we should use GdiPlusRasterLayer to implement your scenario. Here I provide a solution which may meet your requirement, the steps are below:
1. Generate boundingbox index file for your GeoTiff files
// You need to generate the index file in another application
string[] files = Directory.GetFiles(@"C:/Data/", "*.tif", SearchOption.TopDirectoryOnly);
Dictionary<string, RectangleShape> boundingBoxEntities = new Dictionary<string, RectangleShape>();
foreach (string file in files)
{
GeoTiffRasterLayer layer = new GeoTiffRasterLayer(file);
layer.LibraryType = GeoTiffLibraryType.ManagedLibTiff;
layer.UpperThreshold = double.MaxValue;
layer.LowerThreshold = 0;
layer.Open();
RectangleShape rectangle = layer.GetBoundingBox();
layer.Close();
boundingBoxEntities.Add(layer.Name, rectangle);
}
// Serialize the boundingBoxEntities to a index file named "index.dat"
2. Use a customized layer to load files, please check the following sample code for your reference
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Map1.MapUnit = GeographyUnit.Meter;
LayerOverlay geoTiffOverlay = new LayerOverlay("GeoTiff");
IndexDdiPlusRasterLayer indexLayer = new IndexDdiPlusRasterLayer(Server.MapPath(@"~/Datas/"), Server.MapPath(@"~/Datas/index.dat"));
geoTiffOverlay.Layers.Add(indexLayer);
Map1.CustomOverlays.Add(geoTiffOverlay);
Map1.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);
}
}
}
public class IndexDdiPlusRasterLayer : Layer
{
private Dictionary<string, RectangleShape> boundingBoxEntities;
private Collection<GdiPlusRasterLayer> staticLayers;
public IndexDdiPlusRasterLayer(string dataFolder, string indexFilePath)
{
// Deserialize the index file to generate boundingBoxEntities
boundingBoxEntities = new Dictionary<string, RectangleShape>();
staticLayers = new Collection<GdiPlusRasterLayer>();
string[] files = Directory.GetFiles(dataFolder, "*.tif", SearchOption.TopDirectoryOnly);
foreach (string file in files)
{
// Get the fileName by examine "file"
string fileName = "";
GdiPlusRasterLayer gdiPlusLayer = new GdiPlusRasterLayer(file, boundingBoxEntities[fileName]);
gdiPlusLayer.UpperThreshold = double.MaxValue;
gdiPlusLayer.LowerThreshold = 0;
staticLayers.Add(gdiPlusLayer);
}
}
protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)
{
RectangleShape extent = canvas.CurrentWorldExtent;
object image = canvas.NativeImage;
GeographyUnit unit = canvas.MapUnit;
bool isInDrawing = canvas.IsDrawing;
if (isInDrawing)
{
canvas.EndDrawing();
}
foreach (GdiPlusRasterLayer layer in staticLayers)
{
if (boundingBoxEntities[layer.Name].Intersects(extent))
{
canvas.BeginDrawing(image, extent, unit);
layer.Open();
layer.Draw(canvas, labelsInAllLayers);
canvas.EndDrawing();
}
}
if (isInDrawing)
{
canvas.BeginDrawing(image, extent, unit);
}
}
}
By the way, the following link provides another solution (using customized WMS Services) which may helpful to you.
gis.thinkgeo.com/Support/Dis...fault.aspx
Please let us know if you have further questions.
Regards,
Ivan