www.pudn.com > createPolygon.zip > Form1.cs, change:2015-10-16,size:9290b


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using ESRI.ArcGIS.ADF.BaseClasses; 
using ESRI.ArcGIS.Controls; 
using ESRI.ArcGIS.Carto; 
using ESRI.ArcGIS.Display; 
using ESRI.ArcGIS.esriSystem; 
using ESRI.ArcGIS.Geometry; 
using ESRI.ArcGIS.SystemUI; 
using ESRI.ArcGIS.Geodatabase; 
using ESRI.ArcGIS.Geoprocessor; 
using ESRI.ArcGIS.Geoprocessing; 
using ESRI.ArcGIS.AnalysisTools; 
using System.Runtime.InteropServices; 
using ESRI.ArcGIS.DataSourcesFile; 
using ESRI.ArcGIS.DataSourcesRaster; 
using ESRI.ArcGIS.Analyst3D; 
using ESRI.ArcGIS.GeoAnalyst; 
 
 
namespace createPolygon 
{ 
    public partial class Form1 : Form 
    { 
        public Form1() 
        { 
            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop); 
            ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.EngineOrDesktop, ESRI.ArcGIS.LicenseLevel.GeodatabaseUpdate); 
            InitializeComponent(); 
 
        } 
 
        private void 生成shp文件ToolStripMenuItem_Click(object sender, EventArgs e) 
        { 
              /*  ILayer pLayer = axMapControl1.get_Layer(0); 
                  IRasterLayer rasterLayer = (IRasterLayer)pLayer; 
                  IRaster pRaster = rasterLayer.Raster; 
                  IRasterProps pRasterProps = (IRasterProps)pRaster; 
                  double mapPntX, mapPntY; 
                  mapPntX = pRasterProps.Extent.XMin; 
                  mapPntY = pRasterProps.Extent.YMax; 
                  double cellSizeX, cellSizeY; 
                  cellSizeX = pRasterProps.MeanCellSize().X; 
                  cellSizeY = pRasterProps.MeanCellSize().Y; 
                  IPnt pnt = new PntClass(); 
                  pnt.SetCoords((e.mapX - mapPntX) / cellSizeX, (mapPntY - e.mapY) / cellSizeY); 
                  IPnt pntSize =new PntClass(); 
                  pntSize.SetCoords(1,1); 
                  IPixelBlock pixelBlock = pRaster.CreatePixelBlock(pntSize); 
                  pRaster.Read(pnt, pixelBlock); 
                  object obj = pixelBlock.GetVal(0,0,0); 
                  MessageBox.Show(Convert.ToUInt32(obj).ToString());*/ 
                IFeatureLayer pFLayer = axMapControl1.get_Layer(0) as IFeatureLayer; 
                IFeatureClass pFC = pFLayer.FeatureClass; 
 
                //类型不对停止编辑 
                if (pFC.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint) { return; } 
                //建立编辑空间 
                IDataset pDataset = pFC as IDataset; 
                IWorkspace pWorkspace = pDataset.Workspace; 
                IWorkspaceEdit pWorkspaceEdit = pWorkspace as IWorkspaceEdit; 
 
                //开始编辑 
                pWorkspaceEdit.StartEditing(false); 
                pWorkspaceEdit.StartEditOperation(); 
 
                //创建点pFromPoint.Z = formZ;   
                
                //IZ iFromZ = (IZ)pFromPoint;   
                IPoint pToPoint = new PointClass(); 
              //  pToPoint.PutCoords(toX,toY); 
              //  pToPoint.Z = toZ; 
                IZAware toZAware = pToPoint as IZAware; 
                toZAware.ZAware = true;   
            ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass(); 
 
                for (int i = 0; i <= 50; i++) 
                { 
                    pToPoint.X = -65111.0 + i * 1; 
                    pToPoint.Y = 3578528.0 + i * 1; 
                    pToPoint.Z = 3000 + i * 100; 
                     
                    IFeature pFeature = pFC.CreateFeature(); 
 
                    pFeature.Shape = pToPoint;//设置新建的元素为点元素 
 
                    //对元素设置属性值:  
                    // pFeature.set_Value(pFeature.Fields.FindField("Name"), name); 
                 //   pFeature.set_Value(pFeature.Fields.FindField("GDP"), 10000+i*1000); 
 
                    pFeature.Store(); 
                } 
                    /*  point.X = e.mapX; 
                      point.Y = e.mapY; 
 
                      IFeature pFeature = pFC.CreateFeature(); 
 
                      pFeature.Shape = point;//设置新建的元素为点元素 
 
                      //对元素设置属性值:  
                         // pFeature.set_Value(pFeature.Fields.FindField("Name"), name); 
                      pFeature.set_Value(pFeature.Fields.FindField("GDP"),456); 
                
                      pFeature.Store();*/ 
 
                    //停止编辑 
                pWorkspaceEdit.StopEditOperation(); 
                pWorkspaceEdit.StopEditing(true); 
               axMapControl1.ActiveView.Refresh();//更新视窗*/ 
 
        } 
 
        private void 生成点ToolStripMenuItem_Click(object sender, System.EventArgs e) 
        { 
 
        } 
 
        private void 生成面ToolStripMenuItem_Click(object sender, System.EventArgs e) 
        { 
            IFeatureLayer pFLayer = axMapControl1.get_Layer(0) as IFeatureLayer; 
            IFeatureClass pFC = pFLayer.FeatureClass; 
 
 
        } 
 
        private void 栅格转矢量ToolStripMenuItem_Click(object sender, System.EventArgs e) 
        { 
            openFileDialog1.Filter = "tif文件(*.tif)|*.tif"; 
            openFileDialog1.Multiselect = false; 
            openFileDialog1.InitialDirectory = @"G:\data\景观古迹名胜分布_面状"; 
            DialogResult pdialogResult = openFileDialog1.ShowDialog(); 
            if (pdialogResult != DialogResult.OK) 
            { 
                return; 
            } 
            else 
            { 
 
                string pPath = openFileDialog1.FileName; 
                string pFolder = System.IO.Path.GetDirectoryName(pPath); 
                string pFileName = System.IO.Path.GetFileName(pPath); 
                //IFeatureLayer pFLayer = axMapControl1.get_Layer(0) as IFeatureLayer; 
                //IRasterLayer pRLayer = axMapControl1.get_Layer(0) as IRasterLayer; 
                IWorkspaceFactory2 pWorkspaceFactory2 = new RasterWorkspaceFactoryClass(); 
               // string filepath = @"F:\data"; 
                //IConversionNotation conversionNote = new RasterConvolutionFilterClass(); 
                IConversionOp conversionOP = new RasterConversionOpClass(); 
                IRasterWorkspace2 pRasterWorkspace; 
                ESRI.ArcGIS.Geodatabase.IRasterDataset pRasterDataset; 
                // RasterDataset pRasterDataset; 
                pRasterWorkspace = pWorkspaceFactory2.OpenFromFile(pFolder, 0) as IRasterWorkspace2; 
                pRasterDataset = pRasterWorkspace.OpenRasterDataset(pFileName); 
                IRasterLayer pRasterLayer = new RasterLayerClass(); 
                pRasterLayer.CreateFromDataset(pRasterDataset); 
                IRaster raster = pRasterLayer.Raster; 
                IGeoDataset pRasterGeoDataset = pRasterDataset as IGeoDataset; 
 
 
                IGeoDataset geoDataset; 
                IWorkspaceFactory workspacefactory = new ShapefileWorkspaceFactoryClass(); 
                IWorkspace workspace; 
                workspace = workspacefactory.OpenFromFile(@"G:\temp", 0); 
                string OutputName =pFileName+ "newShapFile.shp"; 
                // geoDataset = conversionOP.RasterDataToPolygonFeatureData(raster, workspace, OutputName); 
                geoDataset = conversionOP.RasterDataToPointFeatureData(pRasterGeoDataset, workspace, OutputName); 
            } 
        } 
 
        private void 矢量转栅格ToolStripMenuItem_Click(object sender, System.EventArgs e) 
        { 
            ILayer layer = this.axMapControl1.get_Layer(0); 
            IFeatureLayer pFeatureLayer = layer as IFeatureLayer; 
            IFeatureClass featureClass = pFeatureLayer.FeatureClass; 
            IFeatureClassDescriptor featureClassDescriptor = new FeatureClassDescriptorClass(); 
            featureClassDescriptor.Create(featureClass,null,"code"); 
 
            IGeoDataset geoDataset = featureClassDescriptor as IGeoDataset; 
            //输出空间设置 
            string outputpath =@"G:\temp"; 
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory(); 
            IWorkspace workspace = workspaceFactory.OpenFromFile(outputpath,0); 
            IConversionOp conversionOP = new RasterConversionOpClass(); 
            IRasterAnalysisEnvironment rasterEnvironment = conversionOP as IRasterAnalysisEnvironment; 
            //输出参数设置 
            double dcellsize = 0.024668; 
            object ocellsize = dcellsize as object; 
 
            rasterEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue,ref ocellsize); 
           // rasterEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue); 
            IRasterDataset rasterDatset = conversionOP.ToRasterDataset(geoDataset, "GRID", workspace,"NEWRaster"); 
        } 
    } 
}