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()); }