public void  Create()
        {
            IMap          pMap          = null;
            IFeatureLayer pFeatureLayer = null;
            IRasterLayer  pRasterLayer  = null;

            try
            {
                if (_SourceFile.EndsWith(".shp"))
                {
                    pMap          = new MapClass();
                    pFeatureLayer = new FeatureLayerClass();
                    pFeatureLayer.FeatureClass = EngineAPI.OpenFeatureClass(_SourceFile);
                    pMap.AddLayer(pFeatureLayer);
                    _ExportMan.ExportMapExtent(pMap as IActiveView, new Size(1024, 0), _OutFile, 300);
                }
                else
                {
                    pMap         = new MapClass();
                    pRasterLayer = new RasterLayerClass();
                    pRasterLayer.CreateFromFilePath(_SourceFile);
                    pMap.AddLayer(pRasterLayer);
                    IRasterProps pRasterProps = pRasterLayer.Raster as IRasterProps;
                    int          width        = pRasterProps.Width / 10;
                    _ExportMan.ExportMapExtent(pMap as IActiveView, new Size(width, 0), _OutFile, 300);
                }
            }
            catch (Exception ex)
            {
                Log.WriteLog(typeof(ProductQuickView), ex);
            }
            finally
            {
                if (pMap != null)
                {
                    Marshal.ReleaseComObject(pMap);
                }
                if (pFeatureLayer != null)
                {
                    Marshal.ReleaseComObject(pFeatureLayer);
                }
                if (pRasterLayer != null)
                {
                    Marshal.ReleaseComObject(pRasterLayer);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Handles the Click event of the btnOK control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            string text = this.txtFile.Text;

            if (string.IsNullOrEmpty(text))
            {
                XtraMessageBox.Show("请选择地图存储路径" + "!", "提示信息", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk);
            }
            else
            {
                double num = Convert.ToDouble(this.spinDpi.Value);
                if (num > 300.0)
                {
                    XtraMessageBox.Show("输出分辨率最高只支持300dpi!", "提示信息", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk);
                }
                else
                {
                    //Logger logger = new Logger();
                    int           width         = Convert.ToInt32(this.txtWidth.Text);
                    int           height        = Convert.ToInt32(this.txtHeight.Text);
                    ExportManager exportManager = new ExportManager();
                    string        text2         = "导出成功!";
                    if (!exportManager.ExportMapExtent(this._activeView, new Size(width, height), text, num))
                    {
                        text2 = "导出失败!";
                        //logger.Log(LogLevel.Error, EventType.UserManagement, this.Text, new Exception(text2));
                    }
                    else
                    {
                        //logger.Log(LogLevel.Info, EventType.UserManagement, this.Text, null);
                    }
                    XtraMessageBox.Show(text2, "提示信息", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk);
                    base.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
            }
        }