Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            IGeoDataset   inGeoDataSet;
            IGeoDataset   outGeoDataSet;
            IConversionOp conversionOp = new RasterConversionOpClass();

            // 构造inGeoDataSet
            ILayer       layer       = GetLayerByName(comboBox1.SelectedItem.ToString());
            IRasterLayer rasterLayer = layer as IRasterLayer;
            IRaster      raster      = rasterLayer.Raster;

            inGeoDataSet = raster as IGeoDataset;

            IWorkspaceFactory2 pWorkspaceFactoryShp = new ShapefileWorkspaceFactoryClass();
            IWorkspace         pWorkspace           = pWorkspaceFactoryShp.OpenFromFile(textBox1.Text, 0);
            ISpatialReference  pSpatialReference    = inGeoDataSet.SpatialReference;

            outGeoDataSet = conversionOp.RasterDataToPolygonFeatureData(
                inGeoDataSet,
                pWorkspace,
                textBox2.Text,
                true
                );

            IDataset      pDataset1     = outGeoDataSet as IDataset;
            IFeatureClass pFeatureClass = pDataset1 as IFeatureClass;

            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.FeatureClass = pFeatureClass;
            pFeatureLayer.Name         = textBox2.Text;

            mainForm.axMapControl1.AddLayer(pFeatureLayer);
            mainForm.axMapControl1.Refresh();
        }
Exemplo n.º 2
0
        internal IFeatureClass RasterToPolygon(IRaster inputRaster, string outputName, string outputDir, bool smoothShapes)
        {
            IWorkspace    workspace    = SetupOp.OpenShapeFileWorkspace(outputDir);
            IConversionOp conversionOp = new RasterConversionOpClass();

            try
            {
                IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;

                //Delete any existing
                IEnumDatasetName datasets = workspace.get_DatasetNames(esriDatasetType.esriDTFeatureClass);
                datasets.Reset();
                IDataset     existing    = null;
                IDatasetName datasetName = datasets.Next();
                while (datasetName != null)
                {
                    if (string.Compare(outputName, datasetName.Name, true) == 0)
                    {
                        existing = (IDataset)((IName)datasetName).Open();
                        break;
                    }
                    datasetName = datasets.Next();
                }
                if (existing != null)
                {
                    try
                    {
                        existing.Delete();
                    }
                    finally
                    {
                        UrbanDelineationExtension.ReleaseComObject(existing);
                    }
                }

                //Convert to polygon feature
                SetAnalysisEnvironment((IRasterAnalysisEnvironment)conversionOp);
                IGeoDataset polygons = conversionOp.RasterDataToPolygonFeatureData((IGeoDataset)inputRaster, workspace, outputName, smoothShapes);
                return((IFeatureClass)polygons);
            }
            finally
            {
                UrbanDelineationExtension.ReleaseComObject(workspace);
                UrbanDelineationExtension.ReleaseComObject(conversionOp);
            }
        }
Exemplo n.º 3
0
        // Konverterar raster till vektor.
        public IFeatureLayer convertRasterToVector(string outPath, string fileName)
        {
            IGeoDataset pLayerDataset = (IGeoDataset)dest;

            IConversionOp conversionOp     = new RasterConversionOpClass();
            IRasterAnalysisEnvironment env = (IRasterAnalysisEnvironment)conversionOp;

            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
            IWorkspace        workspace        = workspaceFactory.OpenFromFile(outPath, 0);

            env.OutWorkspace = workspace;

            IWorkspaceFactory wsFactory = new ShapefileWorkspaceFactoryClass();
            IWorkspace        shapeWS   = wsFactory.OpenFromFile(outPath, 0);

            IFeatureWorkspace fWorkspace = (IFeatureWorkspace)wsFactory.OpenFromFile(outPath, 0);
            IWorkspace2       workTemp   = (IWorkspace2)fWorkspace;

            if (workTemp.NameExists[esriDatasetType.esriDTFeatureClass, fileName])
            {
                IDataset dataset = (IDataset)fWorkspace.OpenFeatureClass(fileName);
                dataset.Delete();
            }

            IGeoDataset   featPolClassOut = conversionOp.RasterDataToPolygonFeatureData(pLayerDataset, shapeWS, fileName + ".shp", true);
            IFeatureClass fClass          = fWorkspace.OpenFeatureClass(fileName);
            IFeatureLayer fLayer          = new FeatureLayerClass();

            fLayer.FeatureClass = fClass;
            fLayer.Name         = fClass.AliasName;
            fLayer.Visible      = true;

            map.AddLayer(fLayer);

            return(fLayer);
        }
Exemplo n.º 4
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            string fileName;
            string shpFile;
            int startX, endX;
            string shpDir;
            object Missing = Type.Missing;
            //if (bFeatDataPath == true)
            //{
            //    fileName = comboBoxInData.Text;
            //    shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
            //    startX = fileName.LastIndexOf("\\");
            //    endX = fileName.Length;
            //    shpFile = fileName.Substring(startX + 1, endX - startX - 1);
            //    pFClass = Utility.OpenFeatureClassFromShapefile(shpDir, shpFile);
            //}
            //else
            //{
            //    pFClass = GetFeatureFromMapLyr(comboBoxInData.Text);
            //}
            if (bRasterDataPath == true)
            {
                fileName = txtOutPath.Text;
                shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX = fileName.LastIndexOf("\\");
                endX = fileName.Length;
                shpFile = fileName.Substring(startX + 1, endX - startX - 1);
            }
            else
            {
                shpDir = txtOutPath.Text;
                shpFile = "դ��ת����";
            }
            try
            {
                //ɾ����ʱ�����ļ�
                DelFeatFile(shpDir, shpFile);
                //���դ�����ݼ�
                IRasterDescriptor pRsDescriptor = new RasterDescriptorClass();
                pRsDescriptor.Create(m_pInRaster, new QueryFilterClass(), comboBoxField.Text);
                //�����������ռ�
                IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
                IWorkspace pWS = pWSF.OpenFromFile(shpDir, 0);
                //ת��դ��Ϊ������
                IConversionOp pConversionOp = new RasterConversionOpClass();
                IFeatureClass pOutFeatCls = null;
                switch (comboBoxGeomeryType.Text)
                {
                    case "��":
                        pOutFeatCls = pConversionOp.RasterDataToPointFeatureData(pRsDescriptor as IGeoDataset, pWS, shpFile) as IFeatureClass;
                        break;
                    case "��":
                        pOutFeatCls = pConversionOp.RasterDataToLineFeatureData(pRsDescriptor as IGeoDataset, pWS, shpFile, false, false, ref Missing) as IFeatureClass;
                        break;
                    case "��":
                        pOutFeatCls = pConversionOp.RasterDataToPolygonFeatureData(pRsDescriptor as IGeoDataset, pWS, shpFile, false) as IFeatureClass;
                        break;
                }
                IFeatureLayer pFeatLyr = new FeatureLayerClass();
                pFeatLyr.FeatureClass = pOutFeatCls;
                pMap.AddLayer(pFeatLyr);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
        }
        /// <summary>
        /// return operation watershed handler
        /// </summary>
        /// <param name="boundVariables">>bound Variables</param>
        /// <param name="operationInput">operation Input</param>
        /// <param name="outputFormat">output Format</param>
        /// <param name="requestProperties">request Properties</param>
        /// <param name="responseProperties">response Properties</param>
        /// <returns>operation watershed handler</returns>
        private byte[] OperationWatershedHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = null;

            long?idWatershed;

            if (operationInput.Exists("idWatershed"))
            {
                if (!operationInput.TryGetAsLong("idWatershed", out idWatershed))
                {
                    throw new ArgumentNullException("idWatershed");
                }
            }
            else
            {
                idWatershed = 0;
            }

            JsonObject jsonObjectPoint;

            if (!operationInput.TryGetJsonObject("location", out jsonObjectPoint))
            {
                throw new ArgumentNullException("location");
            }

            IPoint location = Conversion.ToGeometry(jsonObjectPoint, esriGeometryType.esriGeometryPoint) as IPoint;

            if (location == null)
            {
                throw new ArgumentException("Invalid location", "location");
            }

            double?snapDistance;

            if (!operationInput.TryGetAsDouble("snapDistance", out snapDistance))
            {
                throw new ArgumentNullException("snapDistance");
            }

            snapDistance = snapDistance ?? 0.0;

            long?idAccumulation;

            if (!operationInput.TryGetAsLong("idAccumulation", out idAccumulation) || !idAccumulation.HasValue)
            {
                throw new ArgumentNullException("idAccumulation");
            }

            long?idDirection;

            if (!operationInput.TryGetAsLong("idDirection", out idDirection) || !idDirection.HasValue)
            {
                throw new ArgumentNullException("idDirection");
            }

            string methodName = MethodBase.GetCurrentMethod().Name;

            try
            {
                IFeatureWorkspace featureWorkspace = Helper.CreateInMemoryWorkspace() as IFeatureWorkspace;
                IFeatureClass     featureClass     = this.CreateFeatureClass(location, featureWorkspace);

                IFeature feature = featureClass.CreateFeature();
                feature.Shape = location;
                feature.set_Value(featureClass.FindField(SAUtility.FieldNameIdWatershed), (int)idWatershed.Value);
                feature.Store();

                IHydrologyOp hydrologyOp = new RasterHydrologyOp() as IHydrologyOp;

                IGeoDataset accumulation = this.GetGeodataset((int)idAccumulation.Value);
                IGeoDataset direction    = this.GetGeodataset((int)idDirection.Value);

                IFeatureClassDescriptor featureClassDescriptor = new FeatureClassDescriptorClass();
                featureClassDescriptor.Create(featureClass, null, SAUtility.FieldNameIdWatershed);
                IGeoDataset pourPoint = featureClassDescriptor as IGeoDataset;

                IRasterAnalysisEnvironment rasterAnalysisEnvironment = new RasterAnalysisClass();
                object extentProvider = Type.Missing;
                object snapRasterData = Type.Missing;
                rasterAnalysisEnvironment.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvMaxOf, ref extentProvider, ref snapRasterData);

                IGeoDataset snapRaster = hydrologyOp.SnapPourPoint(pourPoint, accumulation, snapDistance.Value);

                IGeoDataset watershed = hydrologyOp.Watershed(direction, snapRaster);

                IConversionOp conversionOp          = new RasterConversionOpClass() as IConversionOp;
                IGeoDataset   featureClassWatershed = conversionOp.RasterDataToPolygonFeatureData(watershed, featureWorkspace as IWorkspace, "WatershedPolygon", true);

                IRecordSetInit recordset = new RecordSetClass();
                recordset.SetSourceTable(featureClassWatershed as ITable, null);

                byte[] recorset = Conversion.ToJson(recordset as IRecordSet);
                this.logger.LogMessage(ServerLogger.msgType.infoDetailed, methodName, SAUtility.MessageCodeSOE, string.Format("Watershed created with succcess. IdWatershed {0}", (int)idWatershed.Value));
                return(recorset);
            }
            catch (Exception ex)
            {
                this.logger.LogMessage(ServerLogger.msgType.error, methodName, SAUtility.MessageCodeSOE, ex.Message);
                return(new ObjectError("error create watershed").ToJsonObject().JsonByte());
            }
        }
Exemplo n.º 6
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            string fileName;
            string shpFile;
            int    startX, endX;
            string shpDir;
            object Missing = Type.Missing;

            //if (bFeatDataPath == true)
            //{
            //    fileName = comboBoxInData.Text;
            //    shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
            //    startX = fileName.LastIndexOf("\\");
            //    endX = fileName.Length;
            //    shpFile = fileName.Substring(startX + 1, endX - startX - 1);
            //    pFClass = Utility.OpenFeatureClassFromShapefile(shpDir, shpFile);
            //}
            //else
            //{
            //    pFClass = GetFeatureFromMapLyr(comboBoxInData.Text);
            //}
            if (bRasterDataPath == true)
            {
                fileName = txtOutPath.Text;
                shpDir   = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX   = fileName.LastIndexOf("\\");
                endX     = fileName.Length;
                shpFile  = fileName.Substring(startX + 1, endX - startX - 1);
            }
            else
            {
                shpDir  = txtOutPath.Text;
                shpFile = "栅格转特征";
            }
            try
            {
                //删除临时特征文件
                DelFeatFile(shpDir, shpFile);
                //获得栅格数据集
                IRasterDescriptor pRsDescriptor = new RasterDescriptorClass();
                pRsDescriptor.Create(m_pInRaster, new QueryFilterClass(), comboBoxField.Text);
                //获得输出工作空间
                IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
                IWorkspace        pWS  = pWSF.OpenFromFile(shpDir, 0);
                //转换栅格为特征类
                IConversionOp pConversionOp = new RasterConversionOpClass();
                IFeatureClass pOutFeatCls   = null;
                switch (comboBoxGeomeryType.Text)
                {
                case "点":
                    pOutFeatCls = pConversionOp.RasterDataToPointFeatureData(pRsDescriptor as IGeoDataset, pWS, shpFile) as IFeatureClass;
                    break;

                case "线":
                    pOutFeatCls = pConversionOp.RasterDataToLineFeatureData(pRsDescriptor as IGeoDataset, pWS, shpFile, false, false, ref Missing) as IFeatureClass;
                    break;

                case "面":
                    pOutFeatCls = pConversionOp.RasterDataToPolygonFeatureData(pRsDescriptor as IGeoDataset, pWS, shpFile, false) as IFeatureClass;
                    break;
                }
                IFeatureLayer pFeatLyr = new FeatureLayerClass();
                pFeatLyr.FeatureClass = pOutFeatCls;
                pMainFrm.getMapControl().AddLayer(pFeatLyr, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }