예제 #1
2
 public static void LoadGeoData(AxMapControl axMapControl1, AxMapControl axMapControl2, string strFileN)
 {
     string strFExtenN = System.IO.Path.GetExtension(strFileN);
     switch (strFExtenN)
     {
         case ".shp":
             {
                 string strPath = System.IO.Path.GetDirectoryName(strFileN);
                 string strFile = System.IO.Path.GetFileNameWithoutExtension(strFileN);
                 axMapControl1.AddShapeFile(strPath, strFile);
                 axMapControl2.ClearLayers();
                 axMapControl2.AddShapeFile(strPath, strFile);
                 axMapControl2.Extent = axMapControl2.FullExtent;
                 break;
             }
         case ".bmp":
         case ".tif":
         case ".jpg":
         case ".img":
             {
                 IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
                 string pathName = System.IO.Path.GetDirectoryName(strFileN);
                 string fileName = System.IO.Path.GetFileName(strFileN);
                 IWorkspace pWS = pWSF.OpenFromFile(pathName, 0);
                 IRasterWorkspace pRWS = pWS as IRasterWorkspace;
                 IRasterDataset pRasterDataSet = pRWS.OpenRasterDataset(fileName);
                 IRasterPyramid pRasPyramid = pRasterDataSet as IRasterPyramid;
                 if (pRasPyramid != null)
                 {
                     if (!(pRasPyramid.Present))
                     {
                         pRasPyramid.Create();
                     }
                 }
                 IRaster pRaster = pRasterDataSet.CreateDefaultRaster();
                 IRasterLayer pRasterLayer = new RasterLayerClass();
                 pRasterLayer.CreateFromRaster(pRaster);
                 ILayer pLayer = pRasterLayer as ILayer;
                 axMapControl1.AddLayer(pLayer, 0);
                 axMapControl2.ClearLayers();
                 axMapControl2.AddLayer(pLayer, 0);
                 axMapControl2.Extent = axMapControl2.FullExtent;
                 break;
             }
         case ".mxd":
             {
                 if (axMapControl1.CheckMxFile(strFExtenN))
                 {
                     axMapControl1.LoadMxFile(strFExtenN);
                 }
                 else
                     MessageBox.Show("所选择的文件不是Mxd文件!", "提示信息");
                 break;
             }
         default:
             break;
     }
 }
예제 #2
0
        private IGeoProcessorResult CreateBuffer(Geoprocessor gp)
        {
            strBufferLayer = cboBufferLayer.Text;
            //Buffer_analysis (in_features, out_feature_class, buffer_distance_or_field, line_side, line_end_type, dissolve_option, dissolve_field)
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer();
            IFeatureLayer bufferLayer = GetFeatureLayer(strBufferLayer);

            buffer.in_features = bufferLayer;


            string outputFullPath = System.IO.Path.Combine(strOutputPath, textBox1.Text);

            buffer.out_feature_class        = outputFullPath;
            buffer.buffer_distance_or_field = bufferDistanceField + " " + (string)comboBox1.SelectedItem;

            buffer.line_side       = strSideType;
            buffer.line_end_type   = strEndType;
            buffer.dissolve_option = strDissolveType;
            buffer.dissolve_field  = strDissolveFields;

            IGeoProcessorResult results          = (IGeoProcessorResult)gp.Execute(buffer, null);
            IFeatureLayer       pOutputFeatLayer = new FeatureLayerClass();

            outputFeatureName = textBox1.Text;


            FileInfo info = new FileInfo(outputFeatureName);
            string   path = outputFeatureName.Substring(0, outputFeatureName.Length - info.Name.Length);

            axMapControl1.AddShapeFile(path, info.Name);
            axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null);

            return(results);
        }
예제 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            gp.AddOutputsToMap = true;
            //DisplayEnvironmentPameters(gp);
            IGeoProcessorResult results = null;

            results = UnionOverlay1(gp);

            try
            {
                //将结果添加到当前地图中
                FileInfo info = new FileInfo(outputFullPath);
                string   path = outputFullPath.Substring(0, outputFullPath.Length - info.Name.Length);
                axMapControl1.AddShapeFile(path, info.Name);
                axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
                this.Close();
            }
            catch (Exception ee)
            {
                MessageBox.Show("出错:" + ee.Message);
            }
        }
예제 #4
0
        public void ExcelToShp(string path)
        {
            if (Utils.CheckFileExists(path))
            {
                string zjdShpTemplte = System.AppDomain.CurrentDomain.BaseDirectory + "ArcGisTemplete\\宅基地模板shp";
                string saveDir       = path.Substring(0, path.LastIndexOf(".")) + "SHP";
                FileUtils.CopyDir(zjdShpTemplte, saveDir, true);
                while (axMapControl.LayerCount > 0)
                {
                    axMapControl.DeleteLayer(0);
                }
                axMapControl.AddShapeFile(saveDir, "ZJD.shp");

                IFeatureLayer  featureLayer  = ArcGisUtils.GetFeatureLayer2("ZJD");
                IFeatureClass  featureClass  = featureLayer.FeatureClass;
                IWorkspaceEdit workspaceEdit = ArcGisUtils.StratEdit(featureClass);

                IFeatureCursor featureCursor = featureClass.Insert(false);
                IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
                ISheet         sheet         = ExcelManager.ExcelRead.ReadExcelSheet(path, 0);

                foreach (NPOI.SS.UserModel.IRow row in sheet)
                {
                    IPointCollection pc         = new Polygon();
                    string[]         pcStrArray = row.GetCell(2).StringCellValue.Split(',');
                    foreach (string ptStr in pcStrArray)
                    {
                        string[] ptArray = ptStr.Split(':');
                        IPoint   point   = new PointClass();
                        point.PutCoords(double.Parse(ptArray[0]), double.Parse(ptArray[1]));
                        pc.AddPoint(point);
                    }
                    IPolygon polygon = ArcGisUtils.CreatePolygon(pc);
                    featureBuffer.Shape    = polygon;
                    featureBuffer.Value[3] = row.GetCell(0).StringCellValue;
                    featureBuffer.Value[4] = row.GetCell(1).StringCellValue;
                    featureCursor.InsertFeature(featureBuffer);
                }

                //IList<IFeature> list = ArcGisUtils.GetEntitysList("", "ZJD");
                ArcGisDao.EndEdit(workspaceEdit);
            }
        }
예제 #5
0
    public static void LoadGeoData(AxMapControl axMapControl1, AxMapControl axMapControl2, string strFileN)
    {
        string strFExtenN = System.IO.Path.GetExtension(strFileN);

        switch (strFExtenN)
        {
        case ".shp":
        {
            string strPath = System.IO.Path.GetDirectoryName(strFileN);
            string strFile = System.IO.Path.GetFileNameWithoutExtension(strFileN);
            axMapControl1.AddShapeFile(strPath, strFile);
            axMapControl2.ClearLayers();
            axMapControl2.AddShapeFile(strPath, strFile);
            axMapControl2.Extent = axMapControl2.FullExtent;
            break;
        }

        case ".bmp":
        case ".tif":
        case ".jpg":
        case ".img":
        {
            IWorkspaceFactory pWSF           = new RasterWorkspaceFactoryClass();
            string            pathName       = System.IO.Path.GetDirectoryName(strFileN);
            string            fileName       = System.IO.Path.GetFileName(strFileN);
            IWorkspace        pWS            = pWSF.OpenFromFile(pathName, 0);
            IRasterWorkspace  pRWS           = pWS as IRasterWorkspace;
            IRasterDataset    pRasterDataSet = pRWS.OpenRasterDataset(fileName);
            IRasterPyramid    pRasPyramid    = pRasterDataSet as IRasterPyramid;
            if (pRasPyramid != null)
            {
                if (!(pRasPyramid.Present))
                {
                    pRasPyramid.Create();
                }
            }
            IRaster      pRaster      = pRasterDataSet.CreateDefaultRaster();
            IRasterLayer pRasterLayer = new RasterLayerClass();
            pRasterLayer.CreateFromRaster(pRaster);
            ILayer pLayer = pRasterLayer as ILayer;
            axMapControl1.AddLayer(pLayer, 0);
            axMapControl2.ClearLayers();
            axMapControl2.AddLayer(pLayer, 0);
            axMapControl2.Extent = axMapControl2.FullExtent;
            break;
        }

        case ".mxd":
        {
            if (axMapControl1.CheckMxFile(strFExtenN))
            {
                axMapControl1.LoadMxFile(strFExtenN);
            }
            else
            {
                MessageBox.Show("所选择的文件不是Mxd文件!", "提示信息");
            }
            break;
        }

        default:
            break;
        }
    }
예제 #6
0
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddFeatrueClass_OKbutton_Click(object sender, EventArgs e)
        {
            if (AddFeatrueClass_radioGroup.SelectedIndex == 0)
            {
                //临时图层
                //检查文件名是否已存在
                int changefilename = 0;
                while (System.IO.File.Exists(Application.StartupPath + "\\temp\\TempLayer" + changefilename + ".shp"))
                {
                    changefilename++;
                }

                //创建点
                IFields     pFields     = new FieldsClass();
                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                IField      pField      = new FieldClass();
                IFieldEdit  pFieldEdit  = pField as IFieldEdit;
                pFieldEdit.Name_2 = "Shape";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

                //设置geometry definition
                IGeometryDef     pGeometryDef     = new GeometryDefClass();
                IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
                if (AddFeatrueClass_geometrytype.Text == "POINT")
                {
                    pGeometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint;//点
                }
                else
                {
                    if (AddFeatrueClass_geometrytype.Text == "POLYLINE")
                    {
                        pGeometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline;//线
                    }
                    else
                    {
                        pGeometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon;//面
                    }
                }
                pGeometryDefEdit.SpatialReference_2 = null;
                pFieldEdit.GeometryDef_2            = pGeometryDefEdit;
                pFieldsEdit.AddField(pField);

                IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
                IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(Application.StartupPath + "\\temp", 0) as IFeatureWorkspace;
                pFeatureWorkspace.CreateFeatureClass("TempLayer" + changefilename + ".shp", pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

                m_mapControl.AddShapeFile(Application.StartupPath + "\\temp", "TempLayer" + changefilename + ".shp");
            }
            else
            {
                //检查输入是否为空
                if (AddFeatrueClass_geometrytype.Text == "" || AddFeatrueClass_locationbutton.Text == "" || AddFeatrueClass_filename.Text == "")
                {
                    MessageBox.Show("输入不能为空");
                    return;
                }
                else
                {
                    //检查文件名是否已存在
                    if (System.IO.File.Exists(AddFeatrueClass_locationbutton.Text + "\\" + AddFeatrueClass_filename.Text) ||
                        System.IO.File.Exists(AddFeatrueClass_locationbutton.Text + "\\" + AddFeatrueClass_filename.Text + ".shp")) //检查文件是否存在
                    {
                        MessageBox.Show("该文件夹下已经有同名文件,请更改文件名称。");
                        return;
                    }
                }
                //自定义图层
                IFields     pFields     = new FieldsClass();
                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                IField      pField      = new FieldClass();
                IFieldEdit  pFieldEdit  = pField as IFieldEdit;
                pFieldEdit.Name_2 = "Shape";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

                //设置geometry definition
                IGeometryDef     pGeometryDef     = new GeometryDefClass();
                IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
                if (AddFeatrueClass_geometrytype.Text == "POINT")
                {
                    pGeometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint;
                }
                else
                {
                    if (AddFeatrueClass_geometrytype.Text == "POLYLINE")
                    {
                        pGeometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline;
                    }
                    else
                    {
                        pGeometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon;
                    }
                }
                pGeometryDefEdit.SpatialReference_2 = null;
                pFieldEdit.GeometryDef_2            = pGeometryDef;
                pFieldsEdit.AddField(pField);

                IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
                IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(AddFeatrueClass_locationbutton.Text, 0) as IFeatureWorkspace;

                int i = AddFeatrueClass_filename.Text.IndexOf(".shp");
                if (i == -1)
                {
                    pFeatureWorkspace.CreateFeatureClass(AddFeatrueClass_filename.Text + ".shp", pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
                }
                else
                {
                    pFeatureWorkspace.CreateFeatureClass(AddFeatrueClass_filename.Text, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
                }

                m_mapControl.AddShapeFile(AddFeatrueClass_locationbutton.Text, AddFeatrueClass_filename.Text);
            }
            this.Close();
            this.Dispose();
        }
예제 #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            IFeature pFeature;
            IFeatureClass pFeatureClass;
            IFeatureCursor pFeatureCursor = null;
            pFeatureClass = (GetLayerByName(this.cboField.Text) as IFeatureLayer).FeatureClass;
            pFeatureCursor = pFeatureClass.Search(null, true);
            pFeature = pFeatureCursor.NextFeature();

            IFeature sFeature;
            IFeatureClass sFeatureClass;
            IFeatureCursor sFeatureCursor = null;
            sFeatureClass = (GetLayerByName(this.cboSch.Text) as IFeatureLayer).FeatureClass;
            sFeatureCursor = sFeatureClass.Search(null, true);
            sFeature = sFeatureCursor.NextFeature();

            IGeometry pTemPt;

            //空间包含查询
            IRelationalOperator pRelOpt = pFeature.Shape as IRelationalOperator;

            while (sFeature != null)
            {
                pTemPt = sFeature.ShapeCopy;
                if (pRelOpt.Contains(pTemPt))
                {
                    axMap.Map.SelectFeature((GetLayerByName(this.cboSch.Text) as IFeatureLayer), sFeature);
                    axMap.ActiveView.Refresh();
                }
                sFeature = sFeatureCursor.NextFeature();
            }

            IFeatureLayer pFeatureLayer = GetLayerByName(this.cboSch.Text);
            //缓冲距离
            double bufferDistance;
            //输入的缓冲距离转换为double
            double.TryParse("5000", out bufferDistance);

            string outputpath = "schdata\\中学_buffer.shp";
            //判断输出路径是否合法
            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(outputpath)) ||
              ".shp" != System.IO.Path.GetExtension(outputpath))
            {
                MessageBox.Show("输出路径错误!");
                return;
            }




            //获取一个geoprocessor的实例
            Geoprocessor gp = new Geoprocessor();
            //OverwriteOutput为真时,输出图层会覆盖当前文件夹下的同名图层
            gp.OverwriteOutput = true;
            string distance = "5000";
            //创建一个Buffer工具的实例
            //ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(pFeatureLayer, strOutputPath, bufferDistance.ToString());
            string para = distance + " Meters";
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer();
            //IFeatureLayer pFeatureLayer = (IFeatureLayer)pEnumFeatureSetup;
            //IFeatureLayer pFeatureLayer = mMapControl.Map.FeatureSelection as IFeatureLayer;
            buffer.in_features = /*pEnumFeatureSetup*/pFeatureLayer;
            buffer.out_feature_class = outputpath;
            buffer.buffer_distance_or_field = para;
            buffer.dissolve_option = "ALL";


            //执行缓冲区分析
            IGeoProcessorResult results = null;
            //results = (IGeoProcessorResult)gp.Execute(buffer, null);

            results = (IGeoProcessorResult)gp.Execute(buffer, null);



            //判断缓冲区是否成功生成
            if (results.Status != esriJobStatus.esriJobSucceeded)
                MessageBox.Show("图层" + "缓冲区生成失败!");
            else
            {
                this.DialogResult = DialogResult.OK;
                //MessageBox.Show("缓冲区生成成功!");
                axMap.AddShapeFile("schdata", "中学_buffer.shp");

            }


            //进行叠置分析裁剪图层
            Clip(cboField.Text);

            
            
        }