Esempio n. 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.listBox1.SelectedItems == null)
            {
                MessageBox.Show("请选择图幅名!");
                return;
            }

            string sqlText = "";

            for (int i = 0; i < this.listBox1.SelectedItems.Count; i++)
            {
                sqlText = "select name,DATASTRUCTURE from sheetmetadata where NAME='" + listBox1.SelectedItems[i] + "'";
                m_oraCmd.CommandText = sqlText;
                OracleDataReader dr = m_oraCmd.ExecuteReader();
                if (!dr.HasRows)
                {
                    MessageBox.Show("图幅不存在!");
                    return;
                }
                while (dr.Read())
                {
                    // this.listBox1.Items.Add(dr.GetValue(0).ToString());
                    if (dr.GetValue(1).ToString() == "矢量")
                    {
                        IFeatureLayer feaLyr;
                        feaLyr = m_gdata.AddFeatureClassToMap(dr.GetValue(0).ToString());
                        this.m_mapControl.Map.AddLayer(feaLyr);
                    }
                    if (dr.GetValue(1).ToString() == "影像")
                    {
                        IRasterWorkspaceEx rasterWS      = m_workSpace as IRasterWorkspaceEx;
                        IRasterCatalog     rasterCatalog = rasterWS.OpenRasterCatalog("COASTALGIS." + dr.GetValue(1).ToString());
                        ITable             table         = rasterCatalog as ITable;
                        ICursor            cursor        = table.Search(null, false);
                        IRow           row      = cursor.NextRow();
                        IRasterDataset rasterDS = null;
                        while (row != null)
                        {
                            IRasterCatalogItem rasterCatalogItem = row as IRasterCatalogItem;

                            if (dr.GetValue(0).ToString() == row.get_Value(cursor.FindField("NAME")).ToString())
                            {
                                rasterDS = rasterCatalogItem.RasterDataset;
                                break;
                            }
                            row = cursor.NextRow();
                        }
                        IRasterLayer rasterLayer = new RasterLayerClass();
                        rasterLayer.CreateFromDataset(rasterDS);
                        this.m_mapControl.Map.AddLayer(rasterLayer);
                    }
                }
            }
        }
Esempio n. 2
0
        public IRasterDataset GetRasterDatasetInCatalog(IFeatureClass pCatalog, string RasterDSName)
        {
            //1.根据名称在featureClass 中找到feature
            IQueryFilter pQueryFilter = new QueryFilterClass();

            pQueryFilter.WhereClause = "NAME ='" + RasterDSName + "'";

            IFeatureCursor pFeatCur = pCatalog.Search(pQueryFilter, false);

            int i = pFeatCur.FindField("Name");

            IFeature pFeat = pFeatCur.NextFeature();

            //2.找到Raster字段,并把其中的值返回IRasterDataset
            IRasterCatalogItem pRasCatItem = pFeat as IRasterCatalogItem;

            return(pRasCatItem.RasterDataset);
        }
        private byte[] GetRasterStatisticsOperHandler(NameValueCollection boundVariables,
                                                      JsonObject operationInput,
                                                      string outputFormat,
                                                      string requestProperties,
                                                      out string responseProperties)
        {
            _logger.LogMessage(ServerLogger.msgType.infoDetailed, _soename + ".GetRasterStatistics", 8000, "request received");
            if (!_supportRasterItemAccess)
            {
                throw new ArgumentException("The image service does not have a catalog and does not support this operation");
            }
            responseProperties = null;

            long?objectID;
            //case insensitive
            bool found = operationInput.TryGetAsLong("objectid", out objectID);

            if (!found || (objectID == null))
            {
                throw new ArgumentNullException("ObjectID");
            }
            IRasterCatalogItem    rasterCatlogItem = null;
            IRasterBandCollection rasterBandsCol   = null;
            IRasterStatistics     statistics       = null;

            try
            {
                rasterCatlogItem = _mosaicCatalog.GetFeature((int)objectID) as IRasterCatalogItem;
                if (rasterCatlogItem == null)
                {
                    _logger.LogMessage(ServerLogger.msgType.infoDetailed, _soename + ".GetRasterStatistics", 8000, "request finished with exception");
                    throw new ArgumentException("The input ObjectID does not exist");
                }
            }
            catch
            {
                _logger.LogMessage(ServerLogger.msgType.infoDetailed, _soename + ".GetRasterStatistics", 8000, "request finished with exception");
                throw new ArgumentException("The input ObjectID does not exist");
            }
            JsonObject result = new JsonObject();

            try
            {
                rasterBandsCol = (IRasterBandCollection)rasterCatlogItem.RasterDataset;
                List <object> maxvalues = new List <object>();
                List <object> minvalues = new List <object>();
                List <object> standarddeviationvalues = new List <object>();
                List <object> meanvalues = new List <object>();
                for (int i = 0; i < rasterBandsCol.Count; i++)
                {
                    statistics = rasterBandsCol.Item(i).Statistics;
                    maxvalues.Add(statistics.Maximum);
                    minvalues.Add(statistics.Minimum);
                    standarddeviationvalues.Add(statistics.StandardDeviation);
                    meanvalues.Add(statistics.Mean);
                    Marshal.ReleaseComObject(statistics);
                }

                result.AddArray("maxValues", maxvalues.ToArray());
                result.AddArray("minValues", minvalues.ToArray());
                result.AddArray("meanValues", meanvalues.ToArray());
                result.AddArray("stdvValues", standarddeviationvalues.ToArray());
            }
            catch
            {
                _logger.LogMessage(ServerLogger.msgType.infoDetailed, "GetRasterStatistics", 8000, "request completed. statistics does not exist");
            }
            finally
            {
                if (rasterBandsCol != null)
                {
                    Marshal.ReleaseComObject(rasterBandsCol);
                }
                if (rasterCatlogItem != null)
                {
                    Marshal.ReleaseComObject(rasterCatlogItem);
                }
            }
            _logger.LogMessage(ServerLogger.msgType.infoDetailed, _soename + ".GetRasterStatistics", 8000, "request completed successfully");
            return(Encoding.UTF8.GetBytes(result.ToJson()));
        }
Esempio n. 4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            Exception eError = null;

            //界面控制判断和检查


            if (txtSavePath.Text == "")
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "请选择保存路径!");
                return;
            }
            //栅格数据文件名称
            string pFileName = txtSavePath.Text.Trim();

            pFileName = pFileName.Substring(pFileName.LastIndexOf('\\') + 1);
            //目标栅格数据存储类型
            string pFormat = cmbDataFormat.Text.Trim().ToUpper();

            #region 创建目标工作空间
            IWorkspace pDesWS = null;//定义工作空间

            //如果存在同名库体则删除


            if (File.Exists(txtSavePath.Text.Trim()))
            {
                File.Delete(txtSavePath.Text.Trim());
            }
            if (cmbDataFormat.Text.Trim().ToUpper() == "PDB")
            {
                pDesWS = CreateWorkspace(txtSavePath.Text.Trim(), "PDB", out eError);
            }
            else if (cmbDataFormat.Text.Trim().ToUpper() == "GDB")
            {
                pDesWS = CreateWorkspace(txtSavePath.Text.Trim(), "GDB", out eError);
            }
            else if (cmbDataFormat.Text.Trim().ToUpper() == "TIF")
            {
                pDesWS = CreateWorkspace(txtSavePath.Text.Trim(), "tif", out eError);
            }
            else if (cmbDataFormat.Text.Trim().ToUpper() == "IMG")
            {
                pDesWS = CreateWorkspace(txtSavePath.Text.Trim(), "img", out eError);
            }
            if (eError != null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "创建工作空间失败!");
                return;
            }
            if (pDesWS == null)
            {
                return;
            }

            #endregion


            //IExtractionOp extraction = new RasterExtractionOpClass();
            IGeometry clipExtent = null;       //几何限制条件
            #region 获得几何限制条件
            IGeometry pGeo1 = null;
            IGeometry pGeo2 = null;
            IGeometry pGeo3 = null;

            pGeo1 = GetUnionGeo(dgMap);

            pGeo2 = GetUnionGeo(dgCounty);
            pGeo3 = GetUnionGeo(dgRange);
            ITopologicalOperator pTop = clipExtent as ITopologicalOperator;
            if (pGeo1 != null)
            {
                if (clipExtent == null)
                {
                    clipExtent = pGeo1;
                }
                else
                {
                    clipExtent = pTop.Union(pGeo1);
                }
            }
            pTop = clipExtent as ITopologicalOperator;
            if (pGeo2 != null)
            {
                if (clipExtent == null)
                {
                    clipExtent = pGeo2;
                }
                else
                {
                    clipExtent = pTop.Union(pGeo2);
                }
            }
            pTop = clipExtent as ITopologicalOperator;
            if (pGeo3 != null)
            {
                if (clipExtent == null)
                {
                    clipExtent = pGeo3;
                }
                else
                {
                    clipExtent = pTop.Union(pGeo3);
                }
            }
            if (clipExtent != null)
            {
                pTop = clipExtent as ITopologicalOperator;
                pTop.Simplify();
                clipExtent = pTop as IGeometry;
            }
            #endregion
            try
            {
                #region 提取数据
                IRaster pOrgRaster = null;           //源栅格数据



                if (m_dbType == "栅格数据集")
                {
                    //源栅格数据图层

                    IRasterLayer mOrgRasterlyer = m_Layer as IRasterLayer;
                    if (mOrgRasterlyer == null)
                    {
                        return;
                    }

                    //源栅格数据集
                    pOrgRaster = mOrgRasterlyer.Raster;
                    if (pOrgRaster == null)
                    {
                        return;
                    }
                    //栅格数据集提取

                    StractData(pFileName, clipExtent, pDesWS, pFormat, pOrgRaster, checkBoxClip.Checked, out eError);
                    if (eError != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", eError.Message);
                        return;
                    }
                }
                else
                {
                    //源数据为栅格数据编目,步骤入下:
                    //(1) 创建临时的工作空间;
                    //(2) 将符合属性条件的栅格数据拼接成栅格数据集后,存储在临时的工作空间里面
                    //(3) 将临时的工作空间里面的栅格数据集案范围提取出来

                    //=======================================================================================

                    #region 栅格编目数据提取

                    //(1)创建临时工作空间

                    IWorkspace tempWS = CreateWorkspace(ModData.temporaryDBPath, "GDB", out eError);
                    if (eError != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "创建临时的工作空间出错!");
                        return;
                    }
                    if (tempWS == null)
                    {
                        return;
                    }

                    //(2)遍历源栅格数据,将数据入库到临时工作空间里面

                    //源栅格数据图层

                    IFeatureLayer mOrgFeaLyer = m_Layer as IFeatureLayer;
                    if (mOrgFeaLyer == null)
                    {
                        return;
                    }
                    IRasterDataset pResRDataset = null;     //最后生成的栅格数据集


                    IFeatureClass pOrgFeaCls = mOrgFeaLyer.FeatureClass;
                    IQueryFilter  pFilter    = new QueryFilterClass();
                    pFilter.WhereClause = txtWhereStr.Text.Trim();
                    IFeatureCursor pFeaCursor = pOrgFeaCls.Search(pFilter, false);
                    if (pFeaCursor == null)
                    {
                        return;
                    }
                    IFeature pORgFea = pFeaCursor.NextFeature();
                    #region 遍历源栅格数据,进行源栅格数据入库(过滤和拼接)
                    while (pORgFea != null)
                    {
                        IRasterCatalogItem pOrgRCItem   = pORgFea as IRasterCatalogItem;
                        IRasterDataset     pOrgRasterDt = pOrgRCItem.RasterDataset;
                        if (pResRDataset == null)
                        {
                            //第一个数据入库直接将源数据拷贝过去

                            if (pOrgRasterDt.CanCopy())
                            {
                                pResRDataset = pOrgRasterDt.Copy(m_DesRasterCollName, tempWS) as IRasterDataset;
                                pORgFea      = pFeaCursor.NextFeature();
                                continue;
                            }
                        }
                        //从第二个栅格数据开始,进行入库和拼接

                        IRaster       pOrgRast    = pOrgRasterDt.CreateDefaultRaster();
                        IRasterLoader pRasterLoad = new RasterLoaderClass();
                        if (pOrgRast != null)
                        {
                            pRasterLoad.Background = 0;                                          //background value be ignored when loading
                            pRasterLoad.PixelAlignmentTolerance = 0;                             //重采样的容差
                            pRasterLoad.MosaicColormapMode      = rstMosaicColormapMode.MM_LAST; //拼接的颜色采用 last map color

                            pRasterLoad.Load(pResRDataset, pOrgRast);
                        }
                        Marshal.ReleaseComObject(pRasterLoad);

                        pORgFea = pFeaCursor.NextFeature();
                    }

                    //释放cursor
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor);
                    #endregion

                    //(3) 将临时工作空间里面的栅格数据集提取出来

                    if (pResRDataset == null)
                    {
                        return;
                    }
                    pOrgRaster = pResRDataset.CreateDefaultRaster();
                    StractData(pFileName, clipExtent, pDesWS, pFormat, pOrgRaster, checkBoxClip.Checked, out eError);
                    if (eError != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", eError.Message);
                        return;
                    }
                    #endregion
                }
                #endregion
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "操作完成!");
            }
            catch (Exception er)
            {
                //*******************************************************************
                //guozheng added
                if (ModData.SysLog != null)
                {
                    ModData.SysLog.Write(er, null, DateTime.Now);
                }
                else
                {
                    ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    ModData.SysLog.Write(er, null, DateTime.Now);
                }
                //********************************************************************
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "提取栅格数据失败!\n" + er.Message);
                return;
            }
            this.Close();
        }
Esempio n. 5
0
        /// <summary>
        /// Sets band information on items in a mosaic dataset
        /// </summary>
        /// <param name="md">The mosaic dataset with the items</param>
        private static void SetMosaicDatasetItemInformation(IMosaicDataset md)
        {
            // Get the Attribute table from the Mosaic Dataset.
            IFeatureClass   featureClass = md.Catalog;
            ISchemaLock     schemaLock   = (ISchemaLock)featureClass;
            IRasterDataset3 rasDs        = null;

            try
            {
                // A try block is necessary, as an exclusive lock might not be available.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Get an update cursor going through all the rows in the Moasic Dataset.
                IFeatureCursor fcCursor = featureClass.Update(null, false);
                // Alternatively, a read cursor can be used if the item does not need to be changed.
                // featureClass.Search(null, false);

                // For each row,
                IRasterCatalogItem rasCatItem = (IRasterCatalogItem)fcCursor.NextFeature();
                while (rasCatItem != null)
                {
                    // get the functionrasterdataset from the Raster field.
                    IFunctionRasterDataset funcDs = (IFunctionRasterDataset)rasCatItem.RasterDataset;
                    if (funcDs != null)
                    {
                        // Check if the 'BandName' property exists in the dataset.
                        bool propertyExists = false;
                        for (int bandID = 0; bandID < funcDs.RasterInfo.BandCount; ++bandID)
                        {
                            object bandNameProperty = null;
                            bandNameProperty = GetBandProperty((IDataset)funcDs, "BandName", bandID);
                            if (bandNameProperty != null)
                            {
                                propertyExists = true;
                            }
                        }
                        if (propertyExists == false && funcDs.RasterInfo.BandCount > 2)
                        {
                            // If the property does not exist and the dataset has atleast 3 bands,
                            // set Band Definition Properties for first 3 bands of the dataset.
                            SetBandProperties((IDataset)funcDs);
                            funcDs.AlterDefinition();
                            rasDs = (IRasterDataset3)funcDs;
                            // Refresh the dataset.
                            rasDs.Refresh();
                        }
                    }
                    fcCursor.UpdateFeature((IFeature)rasCatItem);
                    rasDs      = null;
                    rasCatItem = (IRasterCatalogItem)fcCursor.NextFeature();
                }
                rasCatItem   = null;
                fcCursor     = null;
                featureClass = null;
            }
            catch (Exception exc) { Console.WriteLine("Exception Caught in SetMosaicDatasetItemInformation: " + exc.Message); }
            finally
            {
                // Set the lock to shared, whether or not an error occurred.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }