年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

984 lines
37 KiB

6 months ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using System.IO;
using System.Data.SQLite;
using ESRI.ArcGIS.Carto;
using System.Xml.Serialization;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.OpenData.Control;
using KGIS.Framework.OpenData.Filter;
using KGIS.Framework.OpenData.InterFace;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using Kingo.Plugin.MakeTaskPackage.Entity;
namespace Kingo.Plugin.MakeTaskPackage.View
{
public delegate void GetMapPoints();
public delegate void CutProgressReport(int sum, int current, int cutIndex);
public delegate void CutCreatDown(int cutIndex);
public partial class UCMxdMultCut : UserControl
{
public event CutCreatDown CreatDown;
public event CutProgressReport Report;
public event GetMapPoints GetMapPointsEvent = null;
private double maxDis = 0;
private MxdParameters mxdParams = null;
public bool UseOutMapControl { get; set; }
public ESRI.ArcGIS.Controls.AxMapControl OutMapControl { get; set; }
public ESRI.ArcGIS.Geometry.IGeometry GeometryNow { get; set; }
public int CutIndex { get; set; }
public bool IsEncrypt { get; set; }
public UCMxdMultCut()
{
InitializeComponent();
UseOutMapControl = false;
this.btnBrowseMxd.Click += new EventHandler(btnBrowseMxd_Click);
this.btnBrowser.Click += new EventHandler(btnBrowser_Click);
this.btnOk.Click += new EventHandler(btnOk_Click);
this.btnMapPoints.Click += new EventHandler(btnMapPoints_Click);
this.cboxTileFormat.SelectedIndex = 0;
this.rbAll.CheckedChanged += new EventHandler(rbAll_CheckedChanged);
this.rbAuto.CheckedChanged += new EventHandler(rbAll_CheckedChanged);
this.rbCustom.CheckedChanged += new EventHandler(rbAll_CheckedChanged);
this.cmbBlockCount.SelectedIndexChanged += new EventHandler(cmbBlockCount_SelectedIndexChanged);
this.cmbBlockCount.SelectedIndex = 0;
this.axMapControl1.OnMouseDown += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnMouseDownEventHandler(axMapControl1_OnMouseDown);
this.txtMaxScale.TextChanged += new EventHandler(txtMaxScale_TextChanged);
this.btnExport.Click += new EventHandler(btnExport_Click);
this.btnImport.Click += new EventHandler(btnImport_Click);
this.btnExportPoint.Click += new EventHandler(btnExportPoint_Click);
}
void btnImport_Click(object sender, EventArgs e)
{
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
System.IO.FileStream stream = null;
try
{
stream = File.OpenRead(this.openFileDialog1.FileName);
object obj = Deserialize(typeof(MxdParameters), stream);
BindParmas(obj as MxdParameters);
}
catch (Exception)
{
MessageHelper.Show("导入失败,请检查文件是否为指定格式");
}
finally
{
if (stream != null)
stream.Close();
}
}
}
void btnExport_Click(object sender, EventArgs e)
{
if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if (SetParmas())
{
try
{
if (this.rbAuto.Checked)
{
string fileName = System.IO.Path.GetDirectoryName(this.saveFileDialog1.FileName) + "\\" + System.IO.Path.GetFileNameWithoutExtension(this.saveFileDialog1.FileName);
for (int i = 0; i < mxdParams.BlockHorizontalCount; i++)
{
mxdParams.BlockIndex = i + 1;
byte[] xmlByte = Serializer(typeof(MxdParameters), mxdParams);
File.WriteAllBytes(fileName + "_" + (i + 1) + ".xml", xmlByte);
}
}
else
{
byte[] xmlByte = Serializer(typeof(MxdParameters), mxdParams);
File.WriteAllBytes(this.saveFileDialog1.FileName, xmlByte);
}
MessageHelper.Show("导出成功");
}
catch (Exception ex)
{
LogAPI.Debug("Mxd切片配置导出失败:" + ex);
MessageHelper.Show("导出失败");
}
}
else
{
MessageHelper.Show("参数设置异常,导出失败");
}
}
}
bool SetParmas()
{
if (mxdParams == null)
{
mxdParams = new MxdParameters();
}
try
{
//this.txtMaxScale.Text = mxdParams.MaxScale.ToString();
//this.txtMinScale.SelectedItem = mxdParams.MinScale.ToString();
if (!string.IsNullOrWhiteSpace(mxdParams.MinScale.ToString()))
{
this.txtMinScale.SelectedItem = mxdParams.MinScale.ToString();
}
mxdParams.MinScale = Convert.ToInt32(this.txtMinScale.SelectedItem.ToString());
mxdParams.MaxScale = Convert.ToInt32(this.txtMaxScale.Text);
mxdParams.ThreadNum = Convert.ToInt32(this.txtThreadNo.Text);
mxdParams.TileSize = Convert.ToInt32(this.txtPicSize.Text);
if (cboxTileFormat.SelectedIndex == 0)
mxdParams.ImgFormat = "png";
else
mxdParams.ImgFormat = "jpg";
if (this.rbAll.Checked)
{
mxdParams.CutType = CUTAreaType.;
}
else if (this.rbCustom.Checked)
{
mxdParams.CutType = CUTAreaType.;
}
else if (this.rbAuto.Checked)
{
mxdParams.CutType = CUTAreaType.;
}
mxdParams.BlockHorizontalCount = Convert.ToInt32(this.cmbBlockCount.SelectedItem);
mxdParams.BlockIndex = Convert.ToInt32(this.cmbBlockIndex.SelectedItem);
}
catch
{
return false;
}
return true;
}
public void BindParmas(MxdParameters mxdParams)
{
if (mxdParams == null) return;
try
{
//this.txtMaxScale.Text = mxdParams.MaxScale.ToString();
//this.txtMinScale.SelectedItem = mxdParams.MinScale.ToString();
this.txtMaxScale.Text = mxdParams.MaxScale.ToString();
this.txtMinScale.Items.Clear();
GetAllScale(mxdParams.MaxScale, maxDis);
if (!string.IsNullOrWhiteSpace(mxdParams.MinScale.ToString()))
{
this.txtMinScale.SelectedItem =mxdParams.MinScale;
}
//this.txtMinScale.SelectedItem = mxdParams.MinScale.ToString();
this.txtThreadNo.Text = mxdParams.ThreadNum.ToString();
this.txtPicSize.Text = mxdParams.TileSize.ToString();
cboxTileFormat.SelectedIndex = mxdParams.ImgFormat == "png" ? 0 : 1;
if (mxdParams.CutType == CUTAreaType.)
{
this.rbAll.Checked = true;
}
else if (mxdParams.CutType ==CUTAreaType.)
{
this.rbCustom.Checked = true;
}
else if (mxdParams.CutType == CUTAreaType.)
{
this.rbAuto.Checked = true;
}
this.cmbBlockCount.SelectedItem = mxdParams.BlockHorizontalCount;
this.cmbBlockIndex.SelectedItem = mxdParams.BlockIndex;
}
catch
{
}
}
void txtMaxScale_TextChanged(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txtMaxScale.Text)) return;
int MaxScale = 0;
int.TryParse(txtMaxScale.Text, out MaxScale);
this.txtMinScale.Items.Clear();
GetAllScale(MaxScale, maxDis);
}
catch
{
}
}
/// <summary>
/// 生成比例尺
/// </summary>
/// <param name="maxScale">最大比例尺</param>
/// <param name="maxDistance">最大距离</param>
/// <returns></returns>
private List<int> GetAllScale(int maxScale, double maxDistance)
{
List<int> lstScale = new List<int>();
double distance = 0;
int scaleNow = maxScale;
int minScale = (int)(maxDistance * 96 / (256 * 0.0254));
distance = scaleNow * 256 * 0.0254 / 96;
if (minScale <= scaleNow)
{
lstScale.Add(scaleNow);
this.txtMinScale.Items.Add(scaleNow);
return lstScale;
}
lstScale.Add(maxScale);
while (minScale > scaleNow)
{
scaleNow = scaleNow * 2;
//distance = scaleNow * 256 * 0.0254 / 96;//计算实际距离
lstScale.Add(scaleNow);
this.txtMinScale.Items.Add(scaleNow);
}
this.txtMinScale.SelectedIndex = this.txtMinScale.Items.Count - 1;
//lstScale.Add(minScale);
return lstScale;
}
IEnvelope trackE = null;
IGeometry trackPolygon = null;
bool isDraw = false;
void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
if (isDraw)
{
trackPolygon = axMapControl1.TrackPolygon();
trackE = trackPolygon.Envelope;//.TrackRectangle();
DrawPoylon(trackPolygon);
this.txtCustomPoints.Text = trackE.XMin + "," + trackE.YMax + ";" + trackE.XMax + "," + trackE.YMax + ";" + trackE.XMax + "," + trackE.YMin + ";" + trackE.XMin + "," + trackE.YMin;
}
}
RectangleElementClass polygonElement = null;
public void DrawPoylon(IGeometry geo)
{
if (polygonElement == null)
{
polygonElement = new RectangleElementClass();
polygonElement.Symbol = SelectFillSymbol();
polygonElement.Geometry = geo;
polygonElement.Name = "CF" + DateTime.Now.ToLongDateString();
(axMapControl1.ActiveView.GraphicsContainer as IGraphicsContainer).AddElement((IElement)polygonElement, 0);
}
else
{
polygonElement.Geometry = geo;
}
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
IRgbColor SelectColor = null;
ISimpleLineSymbol selectOutline = null;
ISimpleFillSymbol selectsimpleFillSymbol = null;
private ISimpleFillSymbol SelectFillSymbol()
{
if (SelectColor == null)
{
SelectColor = new RgbColor();
// 设置颜色属性
SelectColor.Red = 255;
SelectColor.Green = 0;
SelectColor.Blue = 0;
}
// 获取ILine符号接口
if (selectOutline == null)
{
selectOutline = new SimpleLineSymbol();
// 设置线符号属
selectOutline.Width = 3;
selectOutline.Color = SelectColor;
}
if (selectsimpleFillSymbol == null)
{
selectsimpleFillSymbol = new SimpleFillSymbolClass();
// 设置填充符号属性
selectsimpleFillSymbol.Outline = selectOutline;
selectsimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;
}
return selectsimpleFillSymbol;
}
/// <summary>
/// 地图取点
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void btnMapPoints_Click(object sender, EventArgs e)
{
//FrmMergeKotiles frmm = new FrmMergeKotiles();
//frmm.ShowDialog();
if (GetMapPointsEvent != null)
GetMapPointsEvent();
isDraw = true;
}
public void SetCutMapIEnvelope(IEnvelope envelope)
{
trackE = envelope;
this.txtCustomPoints.Text = trackE.XMin + "," + trackE.YMax + ";" + trackE.XMax + "," + trackE.YMax + ";" + trackE.XMax + "," + trackE.YMin + ";" + trackE.XMin + "," + trackE.YMin;
}
public List<string> selectedXzq = new List<string>();
private int currentIndex = 0;
private string keyField = "";
private string WhereStr = "";
public IFeatureClass pFC = null;
void btnExportPoint_Click(object sender, EventArgs e)
{
try
{
OpenDataDialog pDialog = new OpenDataDialog();
ISpatialDataObjectFilter pOFilter;
pOFilter = new FilterDatasetsAndLayers();
//pOFilter.DistObjectCollection.Add(
pDialog.AddFilter(pOFilter, true);
pDialog.Title = "选择矢量图层数据";
pDialog.AllowMultiSelect = false;
pDialog.RestoreLocation = true;
pDialog.StartLocation = pDialog.FinalLocation;
if (pDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count != 0)
{
foreach (ISpatialDataObject distObj in pDialog.Selection)
{
object obj = (distObj.DatasetName as IName).Open();
pFC = obj as IFeatureClass;
if (pFC != null)
{
trackE = (pFC as IGeoDataset).Extent;
FrmXZQSelected frm = new FrmXZQSelected();
frm.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
frm.Width = 800;
frm.Height = 450;
frm.ImportFeatureClass = pFC;
selectedXzq = frm.KeyFieldsList;
keyField = frm.KeyField;
WhereStr = frm.WhereStr;
currentIndex = 0;
frm.ShowInMainForm(true);
this.txtCustomPoints.Text = trackE.XMin + "," + trackE.YMax + ";" + trackE.XMax + "," + trackE.YMax + ";" + trackE.XMax + "," + trackE.YMin + ";" + trackE.XMin + "," + trackE.YMin;
}
else
{
MessageBox.Show("请选择矢量图层");
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
private ESRI.ArcGIS.Geometry.IGeometry XzqGeometry(string keyValue, string keyName)
{
if (pFC == null) return null;
IFeatureCursor featureCursor = pFC.Search(new QueryFilterClass() { WhereClause = string.Format(WhereStr, keyValue) }, false);
if (featureCursor == null) return null;
IFeature feature = featureCursor.NextFeature();
if (feature == null) return null;
return feature.ShapeCopy;
}
#region 切片区域配置
void rbAll_CheckedChanged(object sender, EventArgs e)
{
this.panelAuto.Enabled = this.rbAuto.Checked;
this.panelCustom.Enabled = this.rbCustom.Checked;
}
void cmbBlockCount_SelectedIndexChanged(object sender, EventArgs e)
{
int count = 0;
string selectText = cmbBlockCount.SelectedItem.ToString();
if (selectText == "2")
{
count = 2;
}
else if (selectText == "4")
{
count = 4;
}
else if (selectText == "8")
{
count = 8;
}
AddItems(count);
}
void AddItems(int indexCount)
{
this.cmbBlockIndex.Items.Clear();
for (int i = 1; i <= indexCount; i++)
{
this.cmbBlockIndex.Items.Add(i);
}
this.cmbBlockIndex.SelectedIndex = 0;
}
#endregion
private CutTiles cutTiles = null;
public void btnOk_Click(object sender, EventArgs e)
{
cutTiles = new CutTiles();
System.Drawing.Imaging.ImageFormat imgFormat = System.Drawing.Imaging.ImageFormat.Png;
if (string.IsNullOrEmpty(this.txtMxdPath.Text))
{
MessageHelper.Show("请选择MXD文件");
return;
}
if (this.cboxTileFormat.Text.ToLower() == "png")
{
imgFormat = System.Drawing.Imaging.ImageFormat.Png;
}
try
{
cutTiles.TilesDBPath = this.txtSaveFilePath.Text;
if (rbAuto.Checked)
{
cutTiles.BlockHorizontalCount = Convert.ToInt32(this.cmbBlockCount.SelectedItem);
cutTiles.BlockIndex = Convert.ToInt32(this.cmbBlockIndex.SelectedItem);
cutTiles.IsBlock = rbAuto.Checked;
cutTiles.CutType = CUTAreaType.;
}
else if (rbCustom.Checked)
{
cutTiles.CustomArea = trackE;
cutTiles.CutType = CUTAreaType.;
if (selectedXzq != null && selectedXzq.Count > 0)
{
ESRI.ArcGIS.Geometry.IGeometry geometry = XzqGeometry(selectedXzq[currentIndex], keyField);
if (geometry != null)
{
cutTiles.CustomArea = geometry.Envelope;
cutTiles.TilesDBPath = System.IO.Path.GetDirectoryName(this.txtSaveFilePath.Text) + "\\" + selectedXzq[currentIndex] + ".kotiles";
cutTiles.CustomGeometry = geometry;
// FrmMapVis frm = new FrmMapVis();
//frm.Show();
//frm.LoadMxd(this.txtMxdPath.Text, (geometry as ESRI.ArcGIS.esriSystem.IClone).Clone() as IGeometry);
//var pMapClip = this.axMapControl1.Map as ESRI.ArcGIS.Carto.;// IMapClipOptions;
//pMapClip.ClipGeometry = this.axMapControl1.ActiveView.Extent as IGeometry;
//pMapClip.ClipType = esriMapClipType.esriMapClipShape;
//this.axMapControl1.ActiveView.FocusMap.ClipGeometry = geometry;
//this.axMapControl1.ActiveView.Refresh();
//this.axMapControl1.Map.ClipGeometry = geometry;
//this.axMapControl1.FullExtent = geometry.Envelope;
//this.axMapControl1.Refresh();
}
}
else
{
cutTiles.CustomArea = trackPolygon.Envelope;
cutTiles.CustomGeometry = trackPolygon;
//var pMapClip = this.axMapControl1.Map as IMapClipOptions;
//pMapClip.ClipGeometry = this.axMapControl1.ActiveView.Extent as IGeometry;
//pMapClip.ClipType = esriMapClipType.esriMapClipShape;
//this.axMapControl1.Map.ClipGeometry = trackPolygon;
//this.axMapControl1.FullExtent = trackPolygon.Envelope;
//this.axMapControl1.Refresh();
//this.axMapControl1.ActiveView.FocusMap.ClipGeometry = trackPolygon;
//this.axMapControl1.ActiveView.Refresh();
}
}
else
{
cutTiles.CutType = CUTAreaType.;
}
var mapcontrol = this.axMapControl1;
//if (UseOutMapControl)
//{
// mapcontrol = OutMapControl;
//}
List<Kingo.Mobile.Shape2KOTool.SpatialRefrenceStruct> spList = Kingo.Mobile.Shape2KOTool.SpatialRefrenceStruct.GetAllData();
Kingo.Mobile.Shape2KOTool.SpatialRefrenceStruct sp = spList.Find(p => p.WKID == mapcontrol.SpatialReference.FactoryCode);
if (sp == null)
{
var spname = mapcontrol.SpatialReference.Name.Replace("_"," ").Replace("Gauss Kruger","GK");
sp = spList.Find(p => p.Description.ToUpper() == spname.ToUpper());
}
cutTiles.Projection = sp==null?"":sp.WKT;
cutTiles.TileSize = Convert.ToInt32(this.txtPicSize.Text);
cutTiles.axMap = mapcontrol;
cutTiles.LayerName = this.LayerName;
cutTiles.ImgFormat = imgFormat;
cutTiles.MaxLevel = 0;//Convert.ToInt32(this.txtMaxLevel.Text);
cutTiles.MinLevel = Convert.ToInt32(this.txtMinLevel.Text);
cutTiles.MxdPath = this.txtMxdPath.Text;
cutTiles.groupBox = this.groupBox3;
cutTiles.MaxScale = Convert.ToInt32(this.txtMaxScale.Text);
cutTiles.MinScale = Convert.ToInt32(this.txtMinScale.SelectedItem);
cutTiles.IsEncrypt = this.IsEncrypt;
}
catch (Exception)
{
MessageHelper.Show("参数设置异常");
return;
}
if (string.IsNullOrEmpty(this.txtSaveFilePath.Text))
{
MessageHelper.Show("请设置保存位置");
return;
}
DateTime dt1 = DateTime.Now;
cutTiles.CreatDown += (s, e1) =>
{
if (this.CreatDown != null)
CreatDown(CutIndex);
DateTime dt3 = DateTime.Now;
if (!this.IsDisposed && !this.Disposing)
{
this.Invoke(new MethodInvoker(() =>
{
SetState(false, dt3.Subtract(dt1).TotalSeconds.ToString("0.0"));
GC.Collect();
if (rbCustom.Checked && selectedXzq != null)
{
currentIndex++;
if (currentIndex >= selectedXzq.Count)
return;
btnOk_Click(null, null);
}
}));
}
};
cutTiles.Report += (s, c) =>
{
if (this.Report != null)
Report(s, c, CutIndex);
if (!this.IsDisposed && !this.Disposing)
{
this.Invoke(new MethodInvoker(() =>
{
this.lbTips.Text = string.Format("{0}/{1}", c, s);
}));
}
};
try
{
cutTiles.CreateMxdFileKOTilesThread(Convert.ToInt32(this.txtThreadNo.Text));
SetState(true);
}
catch (Exception ex)
{
LogAPI.Debug("mxd切片失败:" + ex);
MessageHelper.Show( "mxd切片失败:"+ ex);
}
}
public void Stop()
{
if (cutTiles != null)
{
cutTiles.Stop();
cutTiles = null;
}
}
public void CreateTiles()
{
cutTiles = new CutTiles();
System.Drawing.Imaging.ImageFormat imgFormat = System.Drawing.Imaging.ImageFormat.Png;
if (string.IsNullOrEmpty(this.txtMxdPath.Text))
{
MessageHelper.Show("请选择MXD文件");
return;
}
if (this.cboxTileFormat.Text.ToLower() == "png")
{
imgFormat = System.Drawing.Imaging.ImageFormat.Png;
}
try
{
cutTiles.TilesDBPath = this.txtSaveFilePath.Text;
if (rbAuto.Checked)
{
cutTiles.BlockHorizontalCount = Convert.ToInt32(this.cmbBlockCount.SelectedItem);
cutTiles.BlockIndex = Convert.ToInt32(this.cmbBlockIndex.SelectedItem);
cutTiles.IsBlock = rbAuto.Checked;
cutTiles.CutType =CUTAreaType.;
}
else if (rbCustom.Checked)
{
cutTiles.CustomArea = trackE;
cutTiles.CutType = CUTAreaType.;
if (selectedXzq != null && selectedXzq.Count > 0)
{
ESRI.ArcGIS.Geometry.IGeometry geometry = XzqGeometry(selectedXzq[currentIndex], keyField);
if (geometry != null)
{
cutTiles.CustomArea = geometry.Envelope;
cutTiles.TilesDBPath = System.IO.Path.GetDirectoryName(this.txtSaveFilePath.Text) + "\\" + selectedXzq[currentIndex] + ".kotiles";
cutTiles.CustomGeometry = geometry;
this.axMapControl1.Map.ClipGeometry = geometry;
this.axMapControl1.FullExtent = geometry.Envelope;
this.axMapControl1.Refresh();
}
}
//else
//{
// cutTiles.CustomArea = trackPolygon.Envelope;
// cutTiles.CustomGeometry = trackPolygon;
// this.axMapControl1.Map.ClipGeometry = trackPolygon;
// this.axMapControl1.FullExtent = trackPolygon.Envelope;
// this.axMapControl1.Refresh();
//}
}
else
{
cutTiles.CutType = CUTAreaType.;
}
List<Kingo.Mobile.Shape2KOTool.SpatialRefrenceStruct> spList = Kingo.Mobile.Shape2KOTool.SpatialRefrenceStruct.GetAllData();
Kingo.Mobile.Shape2KOTool.SpatialRefrenceStruct sp = spList.Find(p => p.WKID == this.axMapControl1.SpatialReference.FactoryCode);
cutTiles.Projection = sp.WKT;
cutTiles.TileSize = Convert.ToInt32(this.txtPicSize.Text);
cutTiles.axMap = this.axMapControl1;
cutTiles.ImgFormat = imgFormat;
cutTiles.MaxLevel = 0;//Convert.ToInt32(this.txtMaxLevel.Text);
cutTiles.MinLevel = Convert.ToInt32(this.txtMinLevel.Text);
cutTiles.MxdPath = this.txtMxdPath.Text;
cutTiles.groupBox = this.groupBox3;
cutTiles.MaxScale = Convert.ToInt32(this.txtMaxScale.Text);
cutTiles.MinScale = Convert.ToInt32(this.txtMinScale.SelectedItem);
cutTiles.IsEncrypt = this.IsEncrypt;
}
catch (Exception)
{
MessageHelper.Show("参数设置异常");
return;
}
if (string.IsNullOrEmpty(this.txtSaveFilePath.Text))
{
MessageHelper.Show("请设置保存位置");
return;
}
DateTime dt1 = DateTime.Now;
cutTiles.CreatDown += (s, e1) =>
{
if (this.CreatDown != null)
CreatDown(CutIndex);
//DateTime dt3 = DateTime.Now;
//if (!this.IsDisposed && !this.Disposing)
//{
// this.Invoke(new MethodInvoker(() =>
// {
// SetState(false, dt3.Subtract(dt1).TotalSeconds.ToString("0.0"));
// GC.Collect();
// if (rbCustom.Checked && selectedXzq != null)
// {
// currentIndex++;
// if (currentIndex >= selectedXzq.Count)
// return;
// //btnOk_Click(null, null);
// }
// }));
//}
};
cutTiles.Report += (s, c) =>
{
if (this.Report != null)
Report(s, c, CutIndex);
//if (!this.IsDisposed && !this.Disposing)
//{
// this.Invoke(new MethodInvoker(() =>
// {
// this.lbTips.Text = string.Format("{0}/{1}", c, s);
// }));
//}
};
try
{
cutTiles.CreateMxdFileKotiles(1);
SetState(true);
}
catch (Exception ex)
{
LogAPI.Debug("mxd切片失败:" + ex);
MessageHelper.Show( "mxd切片失败:"+ ex);
}
}
void btnBrowser_Click(object sender, EventArgs e)
{
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.FileName = "MXD切片";
saveDialog.Filter = "kotiles文件|*.kotiles";
if (saveDialog.ShowDialog() == DialogResult.OK)
{
this.txtSaveFilePath.Text = saveDialog.FileName;
}
}
void btnBrowseMxd_Click(object sender, EventArgs e)
{
OpenFileDialog openDialog = new OpenFileDialog();
openDialog.Filter = "mxd文件|*.mxd";
if (openDialog.ShowDialog() == DialogResult.OK)
{
this.txtMxdPath.Text = openDialog.FileName;
if (this.axMapControl1.CheckMxFile(openDialog.FileName))
{
this.axMapControl1.LoadMxFile(openDialog.FileName);
}
this.maxDis = GetMaxDistance(openDialog.FileName);
}
}
private double GetMaxDistance(string filePath)
{
ProcessMXDClass pr = new ProcessMXDClass();
IEnvelope en = pr.GetMapEnvelope(filePath);
IEnvelope extentMax = GetExtentSquare(en);
return extentMax.XMax - extentMax.XMin;
}
/// <summary>
/// 获取指定范围外正方形
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
private IEnvelope GetExtentSquare(IEnvelope e)
{
IEnvelope extent = new EnvelopeClass()
{
XMax = e.XMax,
XMin = e.XMin,
YMax = e.YMax,
YMin = e.YMin
};
double del = (extent.Width - extent.Height) / 2;
if (del > 0)
{
extent.YMax += del;
extent.YMin -= del;
}
else
{
extent.XMax -= del;
extent.XMin += del;
}
extent.XMax += extent.Width / 8;
extent.XMin -= extent.Width / 8;
extent.YMax += extent.Width / 8;
extent.YMin -= extent.Width / 8;
return extent;
}
private void SetState(bool isRunning, string msg = null)
{
this.groupBox1.Enabled = !isRunning;
this.groupBox2.Enabled = !isRunning;
this.btnOk.Enabled = !isRunning;
this.progressBar1.Visible = isRunning;
//this.lbTips.Visible = isRunning;
//this.toolStripStatusLabel3.Visible = isRunning;
//this.toolStripStatusLabel2.Visible = isRunning;
if (isRunning)
{
this.lbTips.Text = "处理中……";
}
else
{
if (msg == null)
{
this.lbTips.Text = "";
}
else
{
this.lbTips.Text = "耗时" + msg + "秒";
}
}
}
public void LoadMxd(string mxdPath)
{
this.Invoke(new MethodInvoker(() =>
{
if (this.axMapControl1.CheckMxFile(mxdPath))
{
this.axMapControl1.LoadMxFile(mxdPath);
}
}));
}
public void SetMxdPath(string mxdPath)
{
this.txtMxdPath.Text = mxdPath;
if (this.axMapControl1.CheckMxFile(mxdPath))
{
this.axMapControl1.LoadMxFile(mxdPath);
this.maxDis = GetMaxDistance(mxdPath);
}
}
public string LayerName { get; set; }
public void SetLayerVisble(string layerDescriptionName)
{
//Kingo.Mobile.Common.DataProcess.ProcessMXDClass mxdProcess = new Common.DataProcess.ProcessMXDClass();
//mxdProcess.SetMapLayerVisble(this.axMapControl1.Map, layerDescriptionName);
}
public void SetSavePath(string savePath)
{
this.txtSaveFilePath.Text = savePath;
}
public CutTiles CreateCutTiles(ESRI.ArcGIS.Geometry.IGeometry geometry)
{
cutTiles = new CutTiles();
System.Drawing.Imaging.ImageFormat imgFormat = System.Drawing.Imaging.ImageFormat.Png;
if (this.cboxTileFormat.Text.ToLower() == "png")
{
imgFormat = System.Drawing.Imaging.ImageFormat.Png;
}
else
{
imgFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
}
try
{
if (geometry != null)
{
cutTiles.CustomArea = geometry.Envelope;
cutTiles.CutType = CUTAreaType.;
cutTiles.CustomGeometry = geometry;
this.axMapControl1.Map.ClipGeometry = geometry;
this.axMapControl1.FullExtent = geometry.Envelope;
this.axMapControl1.Refresh();
}
else
{
cutTiles.CutType = CUTAreaType.;
}
List<Kingo.Mobile.Shape2KOTool.SpatialRefrenceStruct> spList = Kingo.Mobile.Shape2KOTool.SpatialRefrenceStruct.GetAllData();
Kingo.Mobile.Shape2KOTool.SpatialRefrenceStruct sp = spList.Find(p => p.WKID == this.axMapControl1.SpatialReference.FactoryCode);
cutTiles.Projection = sp.WKT;
cutTiles.TileSize = Convert.ToInt32(this.txtPicSize.Text);
cutTiles.axMap = this.axMapControl1;
cutTiles.TilesDBPath = this.txtSaveFilePath.Text;
cutTiles.ImgFormat = imgFormat;
cutTiles.MaxLevel = 0;//Convert.ToInt32(this.txtMaxLevel.Text);
cutTiles.MinLevel = Convert.ToInt32(this.txtMinLevel.Text);
cutTiles.MxdPath = this.txtMxdPath.Text;
cutTiles.groupBox = this.groupBox3;
cutTiles.MaxScale = Convert.ToInt32(this.txtMaxScale.Text);
cutTiles.MinScale = Convert.ToInt32(this.txtMinScale.SelectedItem);
cutTiles.IsEncrypt = this.IsEncrypt;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return null;
}
try
{
cutTiles.CreateMxdFileKOTilesThread(Convert.ToInt32(this.txtThreadNo.Text));
SetState(true);
}
catch (Exception ex)
{
LogAPI.Debug("mxd切片失败:" + ex);
MessageBox.Show( "mxd切片失败:" + ex);
}
return cutTiles;
}
#region 序列化
/// 序列化
/// </summary>
/// <param name="type">类型</param>
/// <param name="obj">对象</param>
/// <returns></returns>
byte[] Serializer(Type type, object obj)
{
MemoryStream stream = new MemoryStream();
XmlSerializer xml = new XmlSerializer(type);
try
{
//序列化对象
xml.Serialize(stream, obj);
}
catch (InvalidOperationException)
{
throw;
}
return stream.GetBuffer();
}
object Deserialize(Type type, Stream stream)
{
XmlSerializer xmldes = new XmlSerializer(type);
return xmldes.Deserialize(stream);
}
#endregion
}
}