public static bool CreateSignaturefile(IRasterDataset pRasterDataset, int classCount, string gsgPath)
 {
     IGeoDataset pGeo = pRasterDataset as IGeoDataset;
     IMultivariateOp pMultivarateOp = new RasterMultivariateOpClass();
     // string gsgPath = "e:\\222.gsg";
     pMultivarateOp.IsoCluster(pGeo, gsgPath, classCount);
     return true;
 }
Exemple #2
0
        /// <summary>
        /// 生成signature文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SC_CreateSampleFiles_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (SC_dataGridView.Rows.Count == 0)
            {
                return;
            }
            SaveFileDialog SaveSignatureFile = new SaveFileDialog();

            SaveSignatureFile.Title  = "生成Signature文件";
            SaveSignatureFile.Filter = "样本文件|*.gsg";
            if (SaveSignatureFile.ShowDialog() == DialogResult.OK)
            {
                IGeoDataset inputraster = SampleLayerCombox.Tag as IGeoDataset;

                //在临时文件夹生成featureclass,根据featureclass生成signature文件
                //判断临时文件夹下是否有重名
                int changefilename = 0;
                while (System.IO.File.Exists(Application.StartupPath + "\\temp\\TempSample" + changefilename + ".shp"))
                {
                    changefilename++;
                }
                //新建featureclass字段
                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;
                pGeometryDefEdit.GeometryType_2     = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon;
                pGeometryDefEdit.SpatialReference_2 = inputraster.SpatialReference;
                pFieldEdit.GeometryDef_2            = pGeometryDef;
                pFieldsEdit.AddField(pField);

                IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
                IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(Application.StartupPath + "\\temp", 0) as IFeatureWorkspace;
                IFeatureClass     featureclass      = pFeatureWorkspace.CreateFeatureClass("TempSample" + changefilename + ".shp", pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
                //根据单元格tag中存储的多边形生成对应要素
                for (int i = 0; i < SC_dataGridView.Rows.Count; i++)
                {
                    IFeature feature = featureclass.CreateFeature();
                    feature.Shape = SC_dataGridView.Rows[i].Cells["color"].Tag as IPolygon;
                    feature.Store();
                }
                //生成signature文件
                IGeoDataset     Sampledataset  = featureclass as IGeoDataset;
                IMultivariateOp Multivariateop = new RasterMultivariateOpClass();
                Multivariateop.CreateSignatures(inputraster, Sampledataset, SaveSignatureFile.FileName + ".gsg", true);
            }
        }
        public static IRaster ClassifyMethod(IRasterDataset pRasterDataset, int classCount, string gsgPath)
        {
            IGeoDataset pGeoDatasetResult=null;

            if (CreateSignaturefile(pRasterDataset, classCount, gsgPath))
            {
                IGeoDataset pGeo = pRasterDataset as IGeoDataset;
                IMultivariateOp pMultivarateOp = new RasterMultivariateOpClass();
                 pGeoDatasetResult = pMultivarateOp.MLClassify(pGeo, gsgPath, false, esriGeoAnalysisAPrioriEnum.esriGeoAnalysisAPrioriEqual, Type.Missing, Type.Missing);
            }
            return (IRaster)pGeoDatasetResult;
        }
        /*
         *该方法通过纯粹的Arcobject的方式实现最大似然分类        *
         *
         * *
         */
        private byte[] DoClassifyHandler(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;
            long? classCount;
            //case insensitive
            bool found = operationInput.TryGetAsLong("objectID", out objectID);
            if (!found || (objectID == null))
                throw new ArgumentNullException("ObjectID");

            found = operationInput.TryGetAsLong("classnumber", out classCount);
            if (!found || (objectID == null))
                throw new ArgumentNullException("classnumber");
            IRasterCatalogItem rasterCatlogItem = 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();
            string outputurl = "";
            try
            {

                IRasterDataset pRasterDataSet = rasterCatlogItem.RasterDataset;

                IGeoDataset pGeo = pRasterDataSet as IGeoDataset;

                string inPath = @"D:\arcgisserver\directories\arcgisoutput\imageserver\test2_ImageServer";
                string gsgname = System.DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "") + ".gsg";
                string gsgPath = System.IO.Path.Combine(inPath, gsgname);

                bool bcreatesignaturefile = Classify.CreateSignaturefile(pRasterDataSet, Convert.ToInt32(classCount), gsgPath);
                if (bcreatesignaturefile)
                {
                    IMultivariateOp pMultivarateOp = new RasterMultivariateOpClass();
                    IGeoDataset pGeoDatasetResult = pMultivarateOp.MLClassify(pGeo, gsgPath, false, esriGeoAnalysisAPrioriEnum.esriGeoAnalysisAPrioriEqual, Type.Missing, Type.Missing);

                    IEnvelope pEnvelp = new EnvelopeClass();

                    string outurl = "http://localhost:6080/arcgis/rest/directories/arcgisoutput/imageserver/test2_ImageServer/";
                    pEnvelp.PutCoords(116.56075474, 40.29407147, 116.63105347, 40.34514666);
                    // string dd = ExportImage.ExportLayerImage((IRaster)pGeoDatasetResult, bbox, new string[] { "400", "400" }, outurl, fileDir);
                    outputurl = ExportImage.CreateJPEGFromActiveView((IRaster)pGeoDatasetResult, pEnvelp, outurl, inPath);
                }
            }

            catch
            {

            }
            result.AddString("url", outputurl);
            return Encoding.UTF8.GetBytes(result.ToJson());
        }