Exemplo n.º 1
0
        /// <summary>
        /// 获取属性表中的列名
        /// </summary>
        /// <param name="fPath">模拟抽样文件</param>
        /// <param name="cmb">下拉框</param>
        public static void BindFields(string fPath, ComboBoxEdit cmb)
        {
            cmb.Properties.Items.Clear();
            try
            {
                DataTable        table      = new DataTable();
                IFeatureClass    allVillage = EngineAPI.OpenFeatureClass(fPath);
                ITableConversion conver     = new TableConversion();
                table = conver.AETableToDataTable(allVillage);

                if (table == null)
                {
                    return;
                }
                for (int i = 0; i < table.Columns.Count; ++i)
                {
                    //Type type = table.Columns[i].DataType;
                    //if (type != typeof(string))
                    //{
                    string f_name = table.Columns[i].ColumnName;
                    cmb.Properties.Items.Add(f_name);
                    //}
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void cmbSecondUnit_TextChanged(object sender, EventArgs e)
        {
            _sampleFile   = cmbSecondUnit.Text;
            _pSampleLayer = null;
            for (int i = 0; i < _pMapControl.LayerCount; i++)
            {
                ILayer pLayer = _pMapControl.get_Layer(i);
                if (pLayer is IFeatureLayer)
                {
                    IFeatureClass pFClass  = (pLayer as IFeatureLayer).FeatureClass;
                    string        dtSource = Path.Combine((pFClass as IDataset).Workspace.PathName, (pFClass as IDataset).Name + ".shp");
                    if (dtSource == _sampleFile)
                    {
                        _pSampleLayer = pLayer as IFeatureLayer;
                    }
                }
            }
            if (_pSampleLayer == null)
            {
                IFeatureClass pFClass = EngineAPI.OpenFeatureClass(_sampleFile);
                _pSampleLayer = new FeatureLayerClass();
                _pSampleLayer.FeatureClass = pFClass;
                _pSampleLayer.Name         = (pFClass as IDataset).Name;

                _pMapControl.AddLayer(_pSampleLayer);
            }
        }
Exemplo n.º 3
0
        public static Dictionary <string, IFeatureClass> ReadE00Folder(string sPath)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(sPath);

            FileInfo[] files = directoryInfo.GetFiles("*.e00");
            Dictionary <string, IFeatureClass> result;

            if (files == null || files.Length == 0)
            {
                result = null;
            }
            else
            {
                string     coverageDir = ControlAPI.GetCoverageDir();
                FileInfo[] array       = files;
                for (int i = 0; i < array.Length; i++)
                {
                    FileInfo fileInfo = array[i];
                    EngineAPI.E00ToCoverage(fileInfo.FullName, coverageDir);
                }
                IWorkspace workspace = EngineAPI.OpenWorkspace(coverageDir, DataType.coverage);
                if (workspace == null)
                {
                    result = null;
                }
                else
                {
                    result = ControlAPI.ReadCoverage(workspace);
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        public IGeoDataset SetNull(string inRaster, int excludeValue)
        {
            IMapAlgebraOp pRSalgebra  = null;
            IGeoDataset   pGeoDataset = null;

            try
            {
                pGeoDataset = EngineAPI.OpenRasterFile(inRaster) as IGeoDataset;
                string expression = "SetNull([InRaster] != " + excludeValue + ",[InRaster])";
                pRSalgebra = new RasterMapAlgebraOpClass();
                pRSalgebra.BindRaster(pGeoDataset, "InRaster");
                IGeoDataset resDataset = pRSalgebra.Execute(expression);
                return(resDataset);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (pRSalgebra != null)
                {
                    Marshal.ReleaseComObject(pRSalgebra);
                }
                if (pGeoDataset != null)
                {
                    Marshal.ReleaseComObject(pGeoDataset);
                }
            }
        }
        //地图刷新
        private void MapEvent_LayerChanged(IActiveView View, esriViewDrawPhase phase, object Data, IEnvelope envelope)
        {
            List <string> featureLayerNameList = new List <string>();

            if (layerCount != GlobalVars.instance.MapControl.LayerCount)
            {
                layerCount = GlobalVars.instance.MapControl.LayerCount;
                cbxEditorFeature.Properties.Items.Clear();
                pMapControl      = GlobalVars.instance.MapControl;
                pMap             = GlobalVars.instance.MapControl.Map;
                featureLayerList = EngineAPI.GetMapControlFeatureLayer(pMap);
                foreach (IFeatureLayer pFeatureLayer in featureLayerList)
                {
                    cbxEditorFeature.Properties.Items.Add(pFeatureLayer.FeatureClass.AliasName);
                    featureLayerNameList.Add(pFeatureLayer.Name);
                }
                if (!featureLayerNameList.Contains(cbxEditorFeature.Text))
                {
                    cbxEditorFeature.Text = "";
                }
            }
            if (layerCount == 0)
            {
                cbxEditorFeature.Text = "";
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Get all layers.
 /// </summary>
 /// <param name="cmbRaster">The CMB raster.</param>
 /// <param name="cmbFeature">The CMB feature.</param>
 public static void GetAllLayers(ComboBoxEdit cmbRaster, ComboBoxEdit cmbFeature)
 {
     try
     {
         List <ILayer> layers = EngineAPI.GetLayers(EnviVars.instance.MapControl.ActiveView.FocusMap, "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}", null);
         int           i      = 0;
         while (i < layers.Count)
         {
             ILayer lyr = layers[i];
             if (lyr is IRasterLayer)
             {
                 if (cmbRaster != null)
                 {
                     IRasterLayer rasterLyr = lyr as IRasterLayer;
                     cmbRaster.Properties.Items.Add(rasterLyr.FilePath);
                 }
             }
             if (lyr is IFeatureLayer)
             {
                 if (cmbFeature != null)
                 {
                     IFeatureClass featureClass = (lyr as IFeatureLayer).FeatureClass;
                     if (featureClass != null)
                     {
                         string shpFile = System.IO.Path.Combine((featureClass as IDataset).Workspace.PathName, (featureClass as IDataset).Name + ".shp");
                         cmbFeature.Properties.Items.Add(shpFile);
                     }
                 }
             }
             i++;
         }
     }
     catch (Exception)
     { }
 }
Exemplo n.º 7
0
        private void cmbFUnit_TextChanged(object sender, EventArgs e)
        {
            _file    = cmbFUnit.Text;
            _pFLayer = null;
            for (int i = 0; i < _pMapControl.LayerCount; i++)
            {
                ILayer pLayer = _pMapControl.get_Layer(i);
                if (pLayer is IFeatureLayer)
                {
                    IFeatureClass pFClass  = (pLayer as IFeatureLayer).FeatureClass;
                    string        dtSource = Path.Combine((pFClass as IDataset).Workspace.PathName, (pFClass as IDataset).Name + ".shp");
                    if (dtSource == _file)
                    {
                        _pFLayer = pLayer as IFeatureLayer;
                    }
                }
            }
            if (_pFLayer == null)
            {
                IFeatureClass pFClass = EngineAPI.OpenFeatureClass(_file);
                _pFLayer = new FeatureLayerClass();
                _pFLayer.FeatureClass = pFClass;
                FileInfo fInfo = new FileInfo(_file);
                _pFLayer.Name = fInfo.Name.Substring(0, fInfo.Name.Length - 4);

                _pMapControl.AddLayer(_pFLayer);
            }

            BindField(_pFLayer.FeatureClass, cmbLyrField, true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 删除要素
        /// </summary>
        /// <param name="shpFile"></param>
        /// <param name="Rowsname"></param>
        /// <returns></returns>
        public bool DeleFeature(string shpFile, string Rowsname)
        {
            bool          result;
            IFeatureClass allVillage = null;

            try
            {
                string fieldName = Rowsname.Substring(0, Rowsname.IndexOf("="));
                allVillage = EngineAPI.OpenFeatureClass(shpFile);
                //属性查询
                IQueryFilter queryFilter = new QueryFilterClass();
                queryFilter.WhereClause = Rowsname;
                //
                IFeatureCursor updateCursor = allVillage.Update(queryFilter, false);
                IFeature       feature      = updateCursor.NextFeature();
                int            m            = 0;
                while (feature != null)
                {
                    m++;
                    updateCursor.DeleteFeature();
                    feature = updateCursor.NextFeature();
                }
                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示信息");
                result = false;
            }
            return(result);
        }
Exemplo n.º 9
0
        private bool CompareLayers(IMap map, out List <ILayer> dataLayers)
        {
            dataLayers = EngineAPI.GetLayers(map, "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}", null);
            bool result;

            if (dataLayers.Count != this.m_layers.Count)
            {
                result = false;
            }
            else
            {
                for (int i = 0; i < dataLayers.Count; i++)
                {
                    ILayer      layer       = dataLayers[i];
                    MyDataLayer myDataLayer = this.m_layers[i];
                    if (layer != myDataLayer.Layer || myDataLayer.Visible != layer.Visible)
                    {
                        result = false;
                        return(result);
                    }
                }
                result = true;
            }
            return(result);
        }
Exemplo n.º 10
0
        private void frmSampleOverview_Load(object sender, EventArgs e)
        {
            pTable.Clear();
            pTable.Columns.Clear();
            IFeatureClass    allVillage = EngineAPI.OpenFeatureClass(files);
            ITableConversion conver     = new TableConversion();

            this.CurrentTable = conver.AETableToDataTable(allVillage);
            for (int i = 2; i < CurrentTable.Columns.Count; i++)
            {
                if (CurrentTable.Columns[i].DataType == typeof(double))
                {
                    cBEHorizontal.Properties.Items.Add(CurrentTable.Columns[i]);
                    cBEvertical.Properties.Items.Add(CurrentTable.Columns[i]);
                    pTable.Columns.Add(new DataColumn(CurrentTable.Columns[i].ColumnName, CurrentTable.Columns[i].DataType));
                }
            }
            DataRow drr = null;

            for (int i = 0; i < CurrentTable.Rows.Count; i++)
            {
                drr = pTable.NewRow();
                for (int j = 0; j < pTable.Columns.Count; j++)
                {
                    //转换成亩
                    drr[j] = double.Parse(CurrentTable.Rows[i][pTable.Columns[j].ColumnName].ToString()) / 666.67;
                }
                pTable.Rows.Add(drr);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 计算信息熵阈值
        /// </summary>
        public bool CalEntropyMean(out string msg)
        {
            IRasterDataset pRasterDataset = null;

            try
            {
                pRasterDataset = EngineAPI.OpenRasterFile(_Hyper_Entropy);
                IRasterBandCollection pRasterBandCollection = pRasterDataset as IRasterBandCollection;
                IRasterBand           pRasterBand           = pRasterBandCollection.Item(0);
                bool hasSta = false;
                pRasterBand.HasStatistics(out hasSta);
                if (!hasSta)
                {
                    pRasterBand.ComputeStatsAndHist();
                }
                IRasterStatistics pRasterStatistics = pRasterBand.Statistics;
                _Hyper_Entropy_T = pRasterStatistics.Mean;
                msg = "";
                return(true);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return(false);
            }
            finally
            {
                if (pRasterDataset != null)
                {
                    Marshal.ReleaseComObject(pRasterDataset);
                }
            }
        }
Exemplo n.º 12
0
        private bool CompareLyrList(IMap pMap, out List <ILayer> ptr)
        {
            ptr = EngineAPI.GetLayers(pMap, "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}", null);
            bool result;

            if (ptr.Count != this._lyrList.Count)
            {
                result = false;
            }
            else
            {
                for (int i = 0; i < ptr.Count; i++)
                {
                    ILayer layer  = ptr[i];
                    ILayer layer2 = this._lyrList[i];
                    if (layer != layer2)
                    {
                        result = false;
                        return(result);
                    }
                }
                result = true;
            }
            return(result);
        }
Exemplo n.º 13
0
        public bool PurePixel2Shp(out string msg)
        {
            IFeatureClass pFeatureClass = null;

            try
            {
                string outEnd = System.IO.Path.Combine(BLL.ConstDef.PATH_TEMP, "PurePixel_" + DateTime.Now.ToFileTime().ToString() + ".shp");
                if (!BLL.EnviVars.instance.GpExecutor.Raster2Polygon(_Hyper_PurePixel, outEnd, false, out msg))
                {
                    return(false);
                }
                //字段整理
                pFeatureClass = EngineAPI.OpenFeatureClass(outEnd);
                pFeatureClass.DeleteField(pFeatureClass.Fields.get_Field(0));
                IField     field      = new FieldClass();
                IFieldEdit fieldEdit2 = field as IFieldEdit;
                fieldEdit2.Name_2 = "CLASS_ID";
                fieldEdit2.Type_2 = esriFieldType.esriFieldTypeInteger;
                pFeatureClass.AddField(field);

                return(true);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return(false);
            }
        }
Exemplo n.º 14
0
        public static IRasterLayer GetTopVisableRaster()
        {
            IRasterLayer rasterLyr = null;

            try
            {
                List <ILayer> layers = EngineAPI.GetLayers(EnviVars.instance.MapControl.ActiveView.FocusMap, "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}", null);
                int           i      = layers.Count;
                while (i > 0)
                {
                    ILayer lyr = layers[i - 1];
                    if (lyr is IRasterLayer)
                    {
                        if (lyr.Visible)
                        {
                            rasterLyr = lyr as IRasterLayer;
                        }
                    }
                    i--;
                }
                return(rasterLyr);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 15
0
        ///<summary>
        /// 获取shp字段列表
        /// </summary>
        /// <param name="inFile">输入shp文件名</param>
        /// <param name="fields">字段列表</param>
        public void GetFields(string inFile, List <string> fields)
        {
            IFeatureClass featureClass = null;

            try
            {
                featureClass = EngineAPI.OpenFeatureClass(inFile);
                int nFields = featureClass.Fields.FieldCount;
                for (int i = 0; i < nFields; i++)
                {
                    string name = featureClass.Fields.get_Field(i).Name;
                    fields.Add(name);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (featureClass != null)
                {
                    Marshal.ReleaseComObject(featureClass);
                }
            }
        }
Exemplo n.º 16
0
        ///<summary>
        /// 区域像元值统计ZonalStatisticsAsTable
        /// 统计某范围内像元值
        /// 返回datatable
        /// </summary>
        /// <param name="inFile">输入shp文件名</param>
        /// <param name="inValueFile">要统计的栅格文件名</param>
        /// <param name="zoneField">区域字段,区分要统计的区域</param>
        /// <param name="statistisType">统计类型(保留字段)</param>
        public DataTable ZonalStatisticsAsTable(string inFile, string inValueFile, string zoneField, string statistisType = null)
        {
            IFeatureClass  pFeatureClass = null;
            IRasterDataset pRasterDst    = null;
            IZonalOp       pZonalOp      = null;
            ITable         pResTable     = null;

            try
            {
                pFeatureClass = EngineAPI.OpenFeatureClass(inFile);
                pRasterDst    = EngineAPI.OpenRasterFile(inValueFile);
                pZonalOp      = new RasterZonalOpClass();
                pResTable     = pZonalOp.ZonalStatisticsAsTable((IGeoDataset)pFeatureClass, (IGeoDataset)pRasterDst, true);
                ITable          pZoneTable = (ITable)pFeatureClass;
                TableConversion conver     = new TableConversion();
                DataTable       result     = conver.AETableToDataTable(pResTable);
                DataTable       zone       = conver.AETableToDataTable(pZoneTable);
                result.Columns.Remove("Rowid");
                result.Columns.Remove("VALUE");
                //result.Columns.Remove("AREA");
                //result.Columns.RemoveAt(0);
                //result.Columns.RemoveAt(0);
                //result.Columns.RemoveAt(1);
                result.Columns.Add(zoneField);
                for (int i = 0; i < zone.Rows.Count; i++)
                {
                    if (i < result.Rows.Count)
                    {
                        result.Rows[i][zoneField] = zone.Rows[i][zoneField];
                    }
                }
                result.Columns[zoneField].SetOrdinal(0);
                return(result);
            }
            catch (Exception ex)
            {
                Log.WriteLog(typeof(GPExecutor), ex);
                return(null);
            }
            finally
            {
                if (pFeatureClass != null)
                {
                    Marshal.ReleaseComObject(pFeatureClass);
                }
                if (pRasterDst != null)
                {
                    Marshal.ReleaseComObject(pRasterDst);
                }
                if (pZonalOp != null)
                {
                    Marshal.ReleaseComObject(pZonalOp);
                }
                if (pResTable != null)
                {
                    Marshal.ReleaseComObject(pResTable);
                }
            }
        }
Exemplo n.º 17
0
        private void BindField(IFeatureClass featureClass, ComboBoxEdit cmb, bool isNum)
        {
            List <string> fields = new List <string>();

            EngineAPI.GetFields(_pFLayer.FeatureClass, 0, fields);
            cmb.Properties.Items.Clear();
            cmb.Properties.Items.AddRange(fields);
        }
Exemplo n.º 18
0
        protected override HandleRef BuildWindowCore(HandleRef hwndParent)
        {
            SurfaceId = EngineAPI.CreateRenderSurface(hwndParent.Handle, _width, _height);
            Debug.Assert(ID.IsValid(SurfaceId));
            _renderWindowHandle = EngineAPI.GetWindowHandle(SurfaceId);
            Debug.Assert(_renderWindowHandle != IntPtr.Zero);

            return(new HandleRef(this, _renderWindowHandle));
        }
Exemplo n.º 19
0
        //public void Resize()
        //{
        //    _resizeTimer.Trigger();
        //}

        private void Resize(object sender, DelayEventTimerArgs e)
        {
            e.RepeatEvent = GetAsyncKeyState(VK_LBUTTON) < 0;
            if (!e.RepeatEvent)
            {
                EngineAPI.ResizeRenderSurface(SurfaceId);
                Logger.Log(MessageType.Info, "Resized");
            }
        }
Exemplo n.º 20
0
        public bool CreateShpFile(IGeometry geometry, out string sShpFilePath)
        {
            string str = DateTime.Now.ToString().Replace(':', '-').Replace('/', '-').Replace(' ', '-');

            sShpFilePath = System.IO.Path.Combine(ConstDef.PATH_TEMP, str + ".shp");
            if (!Directory.Exists(ConstDef.PATH_TEMP))
            {
                Directory.CreateDirectory(ConstDef.PATH_TEMP);
            }
            return(EngineAPI.CreateShpFile(sShpFilePath, geometry));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Gets the workspace.
        /// </summary>
        /// <param name="sFilePath">The s file path.</param>
        /// <param name="type">The type.</param>
        /// <param name="pWorkspaceList">The p workspace list.</param>
        /// <returns>IWorkspace.</returns>
        public static IWorkspace GetWorkspace(string sFilePath, DataType type, List <WorkspaceInfo> pWorkspaceList)
        {
            IWorkspace workspace = ControlAPI.GetOpenedWorkspace(sFilePath, type, pWorkspaceList);

            if (workspace == null)
            {
                workspace = EngineAPI.OpenWorkspace(sFilePath, type);
                ControlAPI.AddWorkspaceInfo(sFilePath, type, workspace, pWorkspaceList);
            }
            return(workspace);
        }
Exemplo n.º 22
0
        public bool CreateFishNet(string inExtent, int width, int height, string outFishnet, out string msg)
        {
            msg = string.Empty;
            bool result = true;

            ESRI.ArcGIS.DataManagementTools.CreateFishnet fishNet = null;
            IFeatureClass       pfeatureClass      = null;
            IGeoProcessorResult geoProcessorResult = null;

            try
            {
                pfeatureClass = EngineAPI.OpenFeatureClass(inExtent);
                IEnvelope extent = (pfeatureClass as IGeoDataset).Extent;
                fishNet                   = new CreateFishnet();
                fishNet.template          = extent;
                fishNet.cell_width        = width;
                fishNet.cell_height       = height;
                fishNet.number_columns    = 0;
                fishNet.number_rows       = 0;
                fishNet.origin_coord      = extent.XMin + " " + extent.YMin;
                fishNet.y_axis_coord      = extent.XMin + " " + extent.YMax;
                fishNet.out_feature_class = outFishnet;
                fishNet.geometry_type     = "POLYGON";
                fishNet.labels            = "NO_LABELS";
                //geoProcessorResult = this.m_gp.Execute(fishNet, null) as IGeoProcessorResult;
                //msg += GetGPMessages(this.m_gp);
                //Geoprocessor m_gp = new Geoprocessor() { OverwriteOutput = true };
                geoProcessorResult = m_gp.Execute(fishNet, null) as IGeoProcessorResult;
                msg += GetGPMessages(m_gp);
                if (geoProcessorResult.Status == esriJobStatus.esriJobSucceeded)
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (pfeatureClass != null)
                {
                    Marshal.ReleaseComObject(pfeatureClass);
                }
                //if (geoProcessorResult != null)
                //    Marshal.ReleaseComObject(geoProcessorResult);
            }
        }
Exemplo n.º 23
0
 public void DeleteShpFile(string shpfilePath)
 {
     if (!string.IsNullOrEmpty(shpfilePath))
     {
         string        directoryName = System.IO.Path.GetDirectoryName(shpfilePath);
         string        fileName      = System.IO.Path.GetFileName(shpfilePath);
         IWorkspace    workspace     = EngineAPI.OpenWorkspace(directoryName, DataType.shp);
         IFeatureClass featureClass  = (workspace as IFeatureWorkspace).OpenFeatureClass(fileName);
         if ((featureClass as IDataset).CanDelete())
         {
             (featureClass as IDataset).Delete();
         }
     }
 }
        //窗体加载
        private void Form_Editor_Load(object sender, EventArgs e)
        {
            this.Location = new System.Drawing.Point(400, 190);
            setEditToolEnable(false);

            //遍历所有的图层,将矢量图层加入到下拉框
            cbxEditorFeature.Properties.Items.Clear();
            pMapControl      = GlobalVars.instance.MapControl;
            pMap             = GlobalVars.instance.MapControl.Map;
            featureLayerList = EngineAPI.GetMapControlFeatureLayer(pMap);
            foreach (IFeatureLayer pFeatureLayer in featureLayerList)
            {
                cbxEditorFeature.Properties.Items.Add(pFeatureLayer.FeatureClass.AliasName);
            }
        }
Exemplo n.º 25
0
        private void frmSampleOverview_Load(object sender, EventArgs e)
        {
            IFeatureClass    allVillage = EngineAPI.OpenFeatureClass(files);
            ITableConversion conver     = new TableConversion();

            this.CurrentTable = conver.AETableToDataTable(allVillage);
            if (allVillage != null)
            {
                Marshal.ReleaseComObject(allVillage);
            }

            for (int i = 0; i < CurrentTable.Columns.Count; i++)
            {
                if (CurrentTable.Columns[i].ColumnName.Contains("调查"))
                {
                    cBEHorizontal.Properties.Items.Add(CurrentTable.Columns[i]);
                    pTable.Columns.Add(new DataColumn(CurrentTable.Columns[i].ColumnName, CurrentTable.Columns[i].DataType));
                }
                if (CurrentTable.Columns[i].ColumnName.Contains("分类"))
                {
                    cBEvertical.Properties.Items.Add(CurrentTable.Columns[i]);
                    pTable.Columns.Add(new DataColumn(CurrentTable.Columns[i].ColumnName, CurrentTable.Columns[i].DataType));
                }
            }
            DataRow dr = null;

            foreach (DataRow row in CurrentTable.Rows)
            {
                dr = pTable.NewRow();
                for (int j = 0; j < pTable.Columns.Count; j++)
                {
                    dr[j] = row[pTable.Columns[j].ColumnName];
                }
                pTable.Rows.Add(dr);
            }
            DataRow drr = null;

            for (int i = 0; i < CurrentTable.Rows.Count; i++)
            {
                drr = pTable.NewRow();
                for (int j = 0; j < pTable.Columns.Count; j++)
                {
                    //转换成亩
                    drr[j] = double.Parse(CurrentTable.Rows[i][pTable.Columns[j].ColumnName].ToString()) / 666.67;
                }
                pTable.Rows.Add(drr);
            }
        }
Exemplo n.º 26
0
        private void barBtnOpenShp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_pFtLayer != null)
            {
                EnviVars.instance.MapControl.Map.DeleteLayer(_pFtLayer);
            }

            OpenFileDialog fileDialog = new OpenFileDialog();

            //fileDialog.Multiselect = true;
            fileDialog.Title  = "请选择文件";
            fileDialog.Filter = "shapefile(*.shp)|*.shp|All files(*.*)|*.*";

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                filepath = fileDialog.FileName.ToString();
                //sampleSumTable.Clear();//清空表
                //sampleSumTable.Columns.Clear();
                IFeatureClass    allVillage = EngineAPI.OpenFeatureClass(filepath);
                ITableConversion conver     = new TableConversion();
                this.sampleSumTable = conver.AETableToDataTable(allVillage);
                qualified           = sampleSum = sampleSumTable.Rows.Count;//样本量
                if (sampleSumTable.Columns.Contains("shape"))
                {
                    sampleSumTable.Columns.Remove("shape");
                }
                selectRows = sampleSumTable.Clone();
                gridView1.Columns.Clear();
                sampleSumTable.DefaultView.Sort = "FID ASC";
                gridControlTable.DataSource     = sampleSumTable;
                gridControlTable.Refresh();
                _pFtLayer = new FeatureLayerClass();
                _pFtLayer.FeatureClass = allVillage;
                FileInfo info = new FileInfo(filepath);
                //string filename = System.IO.Path .GetFileNameWithoutExtension(filepath);
                _pFtLayer.Name = info.Name;
                //将数据加载到主地图上
                EnviVars.instance.MapControl.AddLayer(_pFtLayer);
                //MAP.AddShpFileToMap(filepath);
                deleted           = sampleSum - qualified;
                barStatic.Caption = string.Format("样本总数:{0}  已删样本数 {1} 合格样本数 {2}", sampleSum, deleted, qualified);
                if (!(Overview == null || Overview.IsDisposed))
                {
                    Overview.Activate();
                    Overview.updatetable(sampleSumTable, _pFtLayer);
                }
            }
        }
Exemplo n.º 27
0
        internal static void ThrowLastException(int err)
        {
            int    category;
            string message;
            string procedureName;
            string lineText;
            int    lineNumber;
            HTuple userData;
            int    lastException = EngineAPI.GetLastException(out category, out message, out procedureName, out lineText, out lineNumber, out userData);

            if (err != -1 && lastException == 2)
            {
                throw new HOperatorException(err);
            }
            throw new HDevEngineException(lastException, (HDevEngineException.ExceptionCategory)category, message, procedureName, lineText, lineNumber, userData);
        }
Exemplo n.º 28
0
        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(512, 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);
                }
            }
        }
Exemplo n.º 29
0
        public PythonEngine(ClientHandler client)
        {
            this.client    = client;
            _engine        = Python.CreateEngine();
            _scope         = _engine.CreateScope();
            _cachedObjects = new CachedObjects(client);

            _gameAPI   = new GameAPI(client, _scope);
            _engineAPI = new EngineAPI(client);

            PrepareStaticLocals();

            var outputStream       = new MemoryStream();
            var outputStreamWriter = new TcpStreamWriter(outputStream, client);

            _engine.Runtime.IO.SetOutput(outputStream, outputStreamWriter);
        }
Exemplo n.º 30
0
 //选中表格某一行事件
 private void gridView1_MouseDown(object sender, MouseEventArgs e)
 {
     DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hi = this.gridView1.CalcHitInfo(new Point(e.X, e.Y));
     if (e.Button == MouseButtons.Left && e.Clicks == 2)
     {
         //判断光标是否在行范围内
         if (hi.InRow)
         {
             int vsRowNum = hi.RowHandle;//鼠标选中行号
             //每次抽样得到的样本
             sampleTable = SampleZones[vsRowNum];
             string outfile = Path.Combine(ConstDef.PATH_TEMP, DateTime.Now.ToFileTime().ToString() + ".shp");
             try
             {
                 SampleSimulation Sim = new SampleSimulation();
                 if (Sim.CreateShpFile(cBFile.Text, sampleTable, outfile))
                 {
                     //添加第i次得到的样本结果到主地图视图
                     //MapAPI.AddShpFileToMap(outfile);
                     string layerName = string.Format("第{0}次抽样结果", vsRowNum + 1);
                     for (int i = 0; i < _pMapControl.LayerCount; i++)
                     {
                         ILayer pLayer = _pMapControl.get_Layer(i);
                         if (pLayer is IFeatureLayer)
                         {
                             if (pLayer.Name == layerName)
                             {
                                 _pMapControl.Map.DeleteLayer(pLayer);
                             }
                         }
                     }
                     IFeatureClass pFC = EngineAPI.OpenFeatureClass(outfile);
                     IFeatureLayer pFL = new FeatureLayerClass();
                     pFL.Name         = layerName;
                     pFL.FeatureClass = pFC;
                     _pMapControl.AddLayer(pFL);
                 }
             }
             catch (Exception ex)
             {
                 XtraMessageBox.Show(ex.Message);
             }
         }
     }
 }