User Tools

Site Tools


source_code_desktopeditionsample_indexedrasterlayer_cs_151105.zip

App.xaml.cs

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
 
namespace IndexRasterLayerSample
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
    }
}

MainWindow.xaml.cs

using System.IO;
using System.Windows;
using System.Windows.Forms;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WpfDesktopEdition;
 
namespace IndexRasterLayerSample
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
 
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            map.MapUnit = GeographyUnit.Meter;
        }
 
        private void LoadButtonClick(object sender, RoutedEventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
            if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                tbFolder.Text = folderBrowserDialog.SelectedPath;
            }
 
            if (!string.IsNullOrEmpty(tbFolder.Text))
            {
                IndexRasterLayer indexRasterLayer = new IndexRasterLayer(@"..\..\index.idx");
                string[] files = Directory.GetFiles(tbFolder.Text);
 
                foreach (var file in files)
                {
                    indexRasterLayer.RasterLayers.Add(new MrSidRasterLayer(file));
                }
 
                LayerOverlay layerOverlay = new LayerOverlay();
                layerOverlay.Layers.Add(indexRasterLayer);
                map.Overlays.Add(layerOverlay);
 
                indexRasterLayer.Open();
                map.CurrentExtent = indexRasterLayer.GetBoundingBox();
 
                map.Refresh();
            }
        }
    }
}

IndexRasterLayer.cs

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
 
namespace ThinkGeo.MapSuite.Core
{
    public class IndexRasterLayer : RasterLayer
    {
        private bool isOpen;
        private string idxPathFileName;
        private RtreeSpatialIndex rTreeIndex;
        private Collection<MrSidRasterLayer> rasterLayers;
 
        public IndexRasterLayer()
            : this(new Collection<MrSidRasterLayer>(), string.Empty)
        { }
 
        public IndexRasterLayer(string idxPathFileNam)
     : this(new Collection<MrSidRasterLayer>(), idxPathFileNam)
        { }
 
        public IndexRasterLayer(IEnumerable<MrSidRasterLayer> rasterLayers)
            : this(rasterLayers, string.Empty)
        { }
 
        public IndexRasterLayer(IEnumerable<MrSidRasterLayer> rasterLayers, string idxPathFileName)
            : base()
        {
            this.idxPathFileName = idxPathFileName;
 
            this.rasterLayers = new Collection<MrSidRasterLayer>();
            foreach (var layer in rasterLayers)
            {
                this.rasterLayers.Add(layer);
            }
        }
 
        public string IndexFilePath
        {
            set { this.idxPathFileName = value; }
            get { return this.idxPathFileName; }
        }
 
        public Collection<MrSidRasterLayer> RasterLayers
        {
            set { this.rasterLayers = value; }
            get { return this.rasterLayers; }
        }
 
 
        public override bool HasBoundingBox
        {
            get { return true; }
        }
 
        protected override bool IsOpenCore
        {
            get { return isOpen; }
        }
 
        protected override void OpenCore()
        {
            if (!IsOpenCore)
            {
                isOpen = true;
 
                if (!File.Exists(idxPathFileName))
                {
                    RtreeSpatialIndex.CreateRectangleSpatialIndex(idxPathFileName, RtreeSpatialIndexPageSize.EightKilobytes, RtreeSpatialIndexDataFormat.Float);
 
                    rTreeIndex = new RtreeSpatialIndex(idxPathFileName, RtreeSpatialIndexReadWriteMode.ReadWrite);
                    rTreeIndex.Open();
 
                    foreach (var rasterLayer in rasterLayers)
                    {
                        rasterLayer.Open();
                        RectangleShape boudingBox = rasterLayer.GetBoundingBox();
 
                        Feature feature = new Feature(boudingBox);
                        feature.Id = rasterLayer.PathFilename;
                        rTreeIndex.Add(feature);
                    }
                }
                else
                {
                    rTreeIndex = new RtreeSpatialIndex(idxPathFileName, RtreeSpatialIndexReadWriteMode.ReadOnly);
                    rTreeIndex.Open();
                }
            }
        }
 
        protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)
        {
            Collection<string> ids = rTreeIndex.GetFeatureIdsIntersectingBoundingBox(canvas.CurrentWorldExtent);
 
            var layers = rasterLayers.Where(a => ids.Contains(a.PathFilename));
 
            foreach (var layer in layers)
            {
                layer.Open();
                layer.Draw(canvas, labelsInAllLayers);
            }
        }
 
        protected override RectangleShape GetBoundingBoxCore()
        {
            Collection<RectangleShape> boundingBoxs = new Collection<RectangleShape>();
 
            foreach (var rasterLayer in rasterLayers)
            {
                rasterLayer.Open();
                boundingBoxs.Add(rasterLayer.GetBoundingBox());
            }
 
            return ExtentHelper.GetBoundingBoxOfItems(boundingBoxs);
        }
    }
}

AssemblyInfo.cs

using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
 
// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("IndexRasterLayerSample")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("IndexRasterLayerSample")]
[assembly: AssemblyCopyright("Copyright ©  2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
 
// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
 
//In order to begin building localizable applications, set 
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>.  For example, if you are using US english
//in your source files, set the <UICulture> to en-US.  Then uncomment
//the NeutralResourceLanguage attribute below.  Update the "en-US" in
//the line below to match the UICulture setting in the project file.
 
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
 
 
[assembly: ThemeInfo(
    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
                                     //(used if a resource is not found in the page, 
                                     // or application resource dictionaries)
    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
                                              //(used if a resource is not found in the page, 
                                              // app, or any theme specific resource dictionaries)
)]
 
 
// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Resources.Designer.cs

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
 
namespace IndexRasterLayerSample.Properties {
    using System;
 
 
    /// <summary>
    ///   A strongly-typed resource class, for looking up localized strings, etc.
    /// </summary>
    // This class was auto-generated by the StronglyTypedResourceBuilder
    // class via a tool like ResGen or Visual Studio.
    // To add or remove a member, edit your .ResX file then rerun ResGen
    // with the /str option, or rebuild your VS project.
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    internal class Resources {
 
        private static global::System.Resources.ResourceManager resourceMan;
 
        private static global::System.Globalization.CultureInfo resourceCulture;
 
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal Resources() {
        }
 
        /// <summary>
        ///   Returns the cached ResourceManager instance used by this class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("IndexRasterLayerSample.Properties.Resources", typeof(Resources).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }
 
        /// <summary>
        ///   Overrides the current thread's CurrentUICulture property for all
        ///   resource lookups using this strongly typed resource class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }
    }
}

Settings.Designer.cs

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
 
namespace IndexRasterLayerSample.Properties {
 
 
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
 
        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
 
        public static Settings Default {
            get {
                return defaultInstance;
            }
        }
    }
}
source_code_desktopeditionsample_indexedrasterlayer_cs_151105.zip.txt · Last modified: 2015/11/05 08:15 by tgwikiupdate