public void executeRegionGroup() { createOutRaster(); if (OutRaster == null) { Console.WriteLine("not all inputs specified"); return; } IWorkspaceEdit wksE = (IWorkspaceEdit)vWks; bool weEdit = true; if (wksE.IsBeingEdited()) { weEdit = false; } else { wksE.StartEditing(false); } wksE.StartEditOperation(); Console.WriteLine("Counter = " + counter.ToString()); int readclmsStep = PixelBlockWidth + 2; int readrwsStep = PixelBlockHeight + 2; IPnt outloc = new PntClass(); IPnt inloc = new PntClass(); try { for (int rp = 0; rp < rws; rp += PixelBlockHeight) //rws { for (int cp = 0; cp < clms; cp += PixelBlockWidth) //clms { Console.WriteLine("Write Raster location = " + cp.ToString() + ":" + rp.ToString()); Console.WriteLine("Read Raster location = " + (cp - 1).ToString() + ":" + (rp - 1).ToString()); outloc.SetCoords(cp, rp); inloc.SetCoords(cp - 1, rp - 1); middleRowColumn(outloc); } } IRaster2 rs2 = (IRaster2)OutRaster; IRasterDataset rsDset = rs2.RasterDataset; IRasterDatasetEdit2 rsDsetE = (IRasterDatasetEdit2)rsDset; rsDsetE.AlterAttributeTable(vatTable); wksE.StopEditOperation(); if (weEdit) { wksE.StopEditing(true); } } catch (Exception e) { Console.WriteLine(e.ToString()); } finally { } return; }
/// <summary> /// 建立栅格图层属性表 /// </summary> /// <param name="rasterDataset">栅格数据集</param> public static void BuildRasterAttributeTable(IRasterDataset rasterDataset) { //建立默认属性表 IRasterDatasetEdit2 rasterDatasetEdit = (IRasterDatasetEdit2)rasterDataset; if (rasterDatasetEdit == null) { return; } rasterDatasetEdit.BuildAttributeTable(); }
private ITable BuildRasterAttributeTable(string rasterName) { Type factoryType = Type.GetTypeFromProgID( "esriDataSourcesGDB.AccessWorkspaceFactory"); IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance (factoryType); IRasterWorkspaceEx rasterWorkspaceEx = workspaceFactory.OpenFromFile(AppSingleton.Instance().WorkspacePath, 0) as IRasterWorkspaceEx; IRasterDataset rasterDataset = rasterWorkspaceEx.OpenRasterDataset(rasterName); IRasterDatasetEdit2 raster = (IRasterDatasetEdit2)rasterDataset; ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset = (ESRI.ArcGIS.Geodatabase.IGeoDataset)rasterDataset; raster.BuildAttributeTable(); ITable vat = (raster as IRasterBandCollection).Item(0).AttributeTable; return(vat); }
private void BuildRasterAttributeTable(IRasterDataset rasterDataset, ITable table) { //Cast to IRasterDatasetEdit2 to build a raster attribute table. IRasterDatasetEdit2 rasterDatasetEdit = (IRasterDatasetEdit2)rasterDataset; //Build a default raster attribute table with VALUE and COUNT fields. if (table == null) { rasterDatasetEdit.BuildAttributeTable(); } else { //Assign the given table as the raster attribute table. rasterDatasetEdit.AlterAttributeTable(table); } }
private void host_WizardCompleted() { AppSingleton.Instance().CreateWorkspacePath(); if (AppSingleton.Instance().SettingsControl == null) { SettingsControl control = new SettingsControl(); control.Load(); control.CheckForm(); } lastControl.SetRichTextBoxLabel("Veriler çalışma alanı sınırlarına göre kesiliyor..."); foreach (var item in AppSingleton.Instance().allLayers) { if (!ClipLayers(item.layer)) { MessageBox.Show("Hata Kodu :1103 . Lütfen yöneticiniz ile görüşünüz."); return; } } lastControl.SetRichTextBoxLabel("İşlem tamamlandı..."); foreach (var item in AppSingleton.Instance().PolygonLayerList) { FieldLayerObject fieldLayerObject = GetFieldLayerObject(item.layer.Name); if (fieldLayerObject == null) { MessageBox.Show("Hata Kodu :1110 . Lütfen yöneticiniz ile görüşünüz."); return; } lastControl.SetRichTextBoxLabel(item.layer.Name + " katmanı için raster dönüşüm yapılıyor..."); if (!PolygonToRaster(item.layer, "Clip_", fieldLayerObject.FieldName, "")) { MessageBox.Show("Hata Kodu :1111 . Lütfen yöneticiniz ile görüşünüz."); return; } lastControl.SetRichTextBoxLabel("İşlem tamamlandı..."); Dictionary <string, string> myDict = fieldLayerObject.FieldList; string reclassifyList = ""; foreach (var pair in myDict) { var key = pair.Key; if (key.Contains(" ")) { key = "'" + key + "'"; } if (reclassifyList == "") { reclassifyList = key + " " + pair.Value + ";"; } else { reclassifyList = reclassifyList + key + " " + pair.Value + ";"; } } reclassifyList = reclassifyList + "NODATA " + AppSingleton.Instance().NodataValue; lastControl.SetRichTextBoxLabel(item.layer.Name + " katmanı yeniden sınıflandırılıyor..."); IFeatureClass fclass = (AppSingleton.Instance().PersonalWorkspace as IFeatureWorkspace).OpenFeatureClass("Poly_Raster_" + item.layer.Name); Type factoryType = Type.GetTypeFromProgID( "esriDataSourcesGDB.AccessWorkspaceFactory"); IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance (factoryType); IRasterWorkspaceEx rasterWorkspaceEx = workspaceFactory.OpenFromFile(AppSingleton.Instance().WorkspacePath, 0) as IRasterWorkspaceEx; //IRasterWorkspace rasterWorkspace = AppSingleton.Instance().PersonalWorkspace as IRasterWorkspace; IRasterDataset rasterDataset = rasterWorkspaceEx.OpenRasterDataset("Poly_Raster_" + item.layer.Name); IRasterDatasetEdit2 raster = (IRasterDatasetEdit2)rasterDataset; ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset = (ESRI.ArcGIS.Geodatabase.IGeoDataset)rasterDataset; raster.BuildAttributeTable(); ITable vat = (raster as IRasterBandCollection).Item(0).AttributeTable; //Check if field Exists var check = false; for (int j = 0; j < vat.Fields.FieldCount; j++) { IField field = vat.Fields.get_Field(j); if (field.Name == fieldLayerObject.FieldName) { check = true; } } if (!check) { lastControl.SetRichTextBoxLabel("Eksik kolonlar ekleniyor..."); if (!JoinField(vat, "Value", item.layer.Name, fieldLayerObject.FieldName, fieldLayerObject.FieldName)) { MessageBox.Show("Hata Kodu :5614 . Lütfen yöneticiniz ile görüşünüz."); return; } } string returnStr = SetFieldToValue(vat, fieldLayerObject.FieldName); bool aragecis = true; if (!Reclassify(item.layer, "Value", returnStr, "Poly_Raster_", "TempReclass_")) { aragecis = false; } if (aragecis == true) { if (!Reclassify(item.layer, "Value", reclassifyList, "TempReclass_", "Reclassified_")) { MessageBox.Show("Hata Kodu :1112 . Lütfen yöneticiniz ile görüşünüz."); return; } } else { if (!Reclassify(item.layer, fieldLayerObject.FieldName, reclassifyList, "Poly_Raster_", "Reclassified_")) { MessageBox.Show("Hata Kodu :1112 . Lütfen yöneticiniz ile görüşünüz."); return; } } IRasterDataset reclassedDataset = rasterWorkspaceEx.OpenRasterDataset("Reclassified_" + item.layer.Name); IRasterDatasetEdit2 reclassed = (IRasterDatasetEdit2)reclassedDataset; ESRI.ArcGIS.Geodatabase.IGeoDataset reclassedGeoDataset = (ESRI.ArcGIS.Geodatabase.IGeoDataset)reclassedDataset; reclassed.BuildAttributeTable(); ITable vatReclass = (reclassed as IRasterBandCollection).Item(0).AttributeTable; //Check if field Exists var checkReclass = false; for (int j = 0; j < vatReclass.Fields.FieldCount; j++) { IField field = vatReclass.Fields.get_Field(j); if (field.Name == fieldLayerObject.FieldName) { checkReclass = true; } } if (!checkReclass) { if (!JoinField(vatReclass, "Value", item.layer.Name, fieldLayerObject.FieldName, fieldLayerObject.FieldName)) { MessageBox.Show("Hata Kodu :5614 . Lütfen yöneticiniz ile görüşünüz."); return; } } lastControl.SetRichTextBoxLabel("İşlem tamamlandı..."); } string rasterString = string.Empty; foreach (var item in reclassList) { if (rasterString == string.Empty) { rasterString = item; } else { rasterString = rasterString + ";" + item; } } foreach (var item in AppSingleton.Instance().RasterLayerList) { if (rasterString == string.Empty) { rasterString = item.Name; } else { rasterString = rasterString + ";" + item.Name; } } lastControl.SetRichTextBoxLabel("Tüm raster katmanlar birleştiriliyor..."); if (!Combine(rasterString)) { MessageBox.Show("Hata Kodu :2639. Lütfen yöneticiniz ile görüşünüz."); return; } //Combine işlemleri Type factoryType2 = Type.GetTypeFromProgID( "esriDataSourcesGDB.AccessWorkspaceFactory"); IWorkspaceFactory workspaceFactory2 = (IWorkspaceFactory)Activator.CreateInstance (factoryType2); IRasterWorkspaceEx rasterWorkspaceEx2 = workspaceFactory2.OpenFromFile(AppSingleton.Instance().WorkspacePath, 0) as IRasterWorkspaceEx; //IRasterWorkspace rasterWorkspace = PersonalWorkspace as IRasterWorkspace; IRasterDataset rasterDataset2 = rasterWorkspaceEx2.OpenRasterDataset("Ekolojik_Sit_Alani"); IRasterDatasetEdit2 raster2 = (IRasterDatasetEdit2)rasterDataset2; ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset2 = (ESRI.ArcGIS.Geodatabase.IGeoDataset)rasterDataset2; raster2.BuildAttributeTable(); ITable vat2 = (raster2 as IRasterBandCollection).Item(0).AttributeTable; List <string> fieldList = new List <string>(); for (int j = 0; j < vat2.Fields.FieldCount; j++) { IField field = vat2.Fields.get_Field(j); if (field.Name.ToUpper() != "OID" && field.Name.ToUpper() != "VALUE" && field.Name.ToUpper() != "COUNT") { fieldList.Add(field.Name); } } lastControl.SetRichTextBoxLabel("Final katmanında eksik kolonlar tanımlanıyor..."); for (int i = 0; i < AppSingleton.Instance().PolygonLayerList.Count; i++) { var item = AppSingleton.Instance().PolygonLayerList[i]; FieldLayerObject fieldLayerObject = GetFieldLayerObject(item.layer.Name); var reclassifiedlayername = AppSingleton.Instance().WorkspacePath + "\\Reclassified_" + item.layer.Name; if (!JoinField(vat2, fieldList[i], reclassifiedlayername, "Value", fieldLayerObject.FieldName)) { MessageBox.Show("Hata Kodu :5614 . Lütfen yöneticiniz ile görüşünüz."); return; } } //foreach (var item in reclassList) //{ // IFeatureClass fclass = (AppSingleton.Instance().PersonalWorkspace as IFeatureWorkspace).OpenFeatureClass(item); // Type factoryType = Type.GetTypeFromProgID( // "esriDataSourcesGDB.AccessWorkspaceFactory"); // string guid = Guid.NewGuid().ToString(); // IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance // (factoryType); // IRasterWorkspaceEx rasterWorkspaceEx = workspaceFactory.OpenFromFile(AppSingleton.Instance().WorkspacePath, 0) as IRasterWorkspaceEx; // //IRasterWorkspace rasterWorkspace = AppSingleton.Instance().PersonalWorkspace as IRasterWorkspace; // IRasterDataset rasterDataset = rasterWorkspaceEx.OpenRasterDataset(item); // IRasterDatasetEdit2 raster = (IRasterDatasetEdit2)rasterDataset; // ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset = (ESRI.ArcGIS.Geodatabase.IGeoDataset)rasterDataset; // raster.BuildAttributeTable(); // ITable vat = (raster as IRasterBandCollection).Item(0).AttributeTable; // //IFeatureClass fclass= (AppSingleton.Instance().PersonalWorkspace as IFeatureWorkspace).OpenFeatureClass(item); // List<double> valueList = GetUniques(vat as ITable, "Value"); // double max = FindMaxValue(valueList); // double min = FindMinValue(valueList); // IFeatureLayer fLayer = new FeatureLayerClass(); // fLayer.Name = item; // fLayer.FeatureClass = fclass; // lastControl.SetRichTextBoxLabel("Öznitelik ekleniyor..."); // AddField(fLayer, "Normal", ""); // lastControl.SetRichTextBoxLabel("İşlem tamamlandı..."); // lastControl.SetRichTextBoxLabel("Normalleştirme işlemi yapılıyor..."); // foreach (var myLayer in AppSingleton.Instance().AllLayersDict) // { // string layerName = myLayer.Key; // if ("Reclassified_" + layerName == item) // { // LayerType lType = myLayer.Value; // switch (lType.Metod) // { // case "x/Maks": // SetFirstNormal(vat, max); // break; // case "1-(x/Maks)": // SetSecondNormal(vat, max); // break; // case "(x-Min)/(Maks-Min)": // SetThirdNormal(vat, max, min); // break; // case "(Maks-x)/(Maks-Min)": // SetFourthNormal(vat, max, min); // break; // default: // Console.WriteLine("Invalid selection. Please select 1, 2, or 3."); // break; // } // } // } // lastControl.SetRichTextBoxLabel("İşlem tamamlandı..."); //} lastControl.SetRichTextBoxLabel("İşlem tamamlandı..."); //this.Dispose(); //MessageBox.Show("Done!"); //obviously you'd do something else in a real app... }
private void btnOk_Click(object sender, EventArgs e) { if (cmbUygulamaKatmani.SelectedIndex < 0) { MessageBox.Show("Uygulama katmanı belirlenmeden işlem yapılamaz."); return; } if (cmbProjectArea.SelectedIndex < 0) { MessageBox.Show("Proje sınırı belirlenmeden işlem yapılamaz."); return; } if (cmbNn.SelectedIndex < 0) { MessageBox.Show("Nn değeri belirlenmeden işlem yapılamaz."); return; } if (cmbGs.SelectedIndex < 0) { MessageBox.Show("Gs değeri belirlenmeden işlem yapılamaz."); return; } if (cmbY.SelectedIndex < 0) { MessageBox.Show("Y değeri belirlenmeden işlem yapılamaz."); return; } if (cmbS.SelectedIndex < 0) { MessageBox.Show("S değeri belirlenmeden işlem yapılamaz."); return; } AppSingleton.Instance().CreateWorkspacePath(); if (AppSingleton.Instance().SettingsControl == null) { SettingsControl control = new SettingsControl(); control.Load(); control.CheckForm(); } tpSonuc.Visible = true; tpSonuc.VisualMode = ProgressBarDisplayMode.TextAndPercentage; tpSonuc.CustomText = "Uygulama Katmanı kesiliyor..."; tpSonuc.Maximum = 13; tpSonuc.Step = 1; tpSonuc.PerformStep(); var clipLayer = AppSingleton.Instance().ClipLayers((cmbProjectArea.SelectedItem as LayerObject).layer, (cmbUygulamaKatmani.SelectedItem as LayerObject).layer); if (rbYillik.Checked) { var clipLayerName = Path.GetFileNameWithoutExtension(clipLayer); CalculateNpYillik(clipLayerName); } string nN = string.Empty; string nP = string.Empty; string Y = string.Empty; string S = string.Empty; string gS = string.Empty; //if (AppSingleton.Instance().UygulamaYontemi == "IDW") //{ tpSonuc.CustomText = "nN Katmanı oluşturuluyor..."; tpSonuc.PerformStep(); nN = AppSingleton.Instance().IDW(clipLayer, cmbNn.SelectedItem.ToString(), "nN"); tpSonuc.CustomText = "nP Katmanı oluşturuluyor..."; tpSonuc.PerformStep(); if (rbYillik.Checked) { nP = AppSingleton.Instance().IDW(clipLayer, "npYillik", "npYillik"); } tpSonuc.CustomText = "Y Katmanı oluşturuluyor..."; tpSonuc.PerformStep(); Y = AppSingleton.Instance().IDW(clipLayer, cmbY.SelectedItem.ToString(), "Y"); tpSonuc.CustomText = "S Katmanı oluşturuluyor..."; tpSonuc.PerformStep(); S = AppSingleton.Instance().IDW(clipLayer, cmbS.SelectedItem.ToString(), "S"); tpSonuc.CustomText = "gS Katmanı oluşturuluyor..."; tpSonuc.PerformStep(); gS = AppSingleton.Instance().IDW(clipLayer, cmbGs.SelectedItem.ToString(), "gS"); //} //else if (AppSingleton.Instance().UygulamaYontemi == "KRIGING") //{ // nN = AppSingleton.Instance().Kriging((cmbUygulamaKatmani.SelectedItem as LayerObject).layer, cmbNn.SelectedItem.ToString()); // nP = AppSingleton.Instance().Kriging((cmbUygulamaKatmani.SelectedItem as LayerObject).layer, cmbNp.SelectedItem.ToString()); // Y = AppSingleton.Instance().Kriging((cmbUygulamaKatmani.SelectedItem as LayerObject).layer, cmbY.SelectedItem.ToString()); // S = AppSingleton.Instance().Kriging((cmbUygulamaKatmani.SelectedItem as LayerObject).layer, cmbS.SelectedItem.ToString()); // gS = AppSingleton.Instance().Kriging((cmbUygulamaKatmani.SelectedItem as LayerObject).layer, cmbGs.SelectedItem.ToString()); //} tpSonuc.CustomText = "nKS Katmanı oluşturuluyor..."; tpSonuc.PerformStep(); if (rbAylik.Checked) { nP = "12"; } string nKS = RasterCalculatorNKS(nN, nP, Y, S, gS); tpSonuc.CustomText = "kKS Katmanı oluşturuluyor..."; tpSonuc.PerformStep(); string kKS = RasterCalculatorKKS(nKS); var nksStr = "0 0.400000 1;0.400000 0.670000 2;0.670000 1 3;1 1.330000 4;1.330000 2 5;2 4 6;4 100000 7;NODATA 0"; var kksStr = "0 0.250000 7;0.250000 0.500000 6;0.500000 0.750000 5;0.750000 1 4;1 1.500000 3;1.500000 2.500000 2;2.500000 100000 1;NODATA 0"; tpSonuc.CustomText = "nKS Katmanı sınıflandırılıyor..."; tpSonuc.PerformStep(); var rNKS = Reclassify(Path.GetFileNameWithoutExtension(nKS), "Value", nksStr, "R_"); tpSonuc.CustomText = "kKS Katmanı sınıflandırılıyor..."; tpSonuc.PerformStep(); var rKKS = Reclassify(Path.GetFileNameWithoutExtension(kKS), "Value", kksStr, "R_"); tpSonuc.CustomText = "Katmanlar birleştiriliyor..."; tpSonuc.PerformStep(); string combine = Combine(rNKS + ";" + rKKS); tpSonuc.CustomText = "Veriler ekleniyor..."; tpSonuc.PerformStep(); Type factoryType = Type.GetTypeFromProgID( "esriDataSourcesGDB.AccessWorkspaceFactory"); IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance (factoryType); IRasterWorkspaceEx rasterWorkspaceEx = workspaceFactory.OpenFromFile(AppSingleton.Instance().WorkspacePath, 0) as IRasterWorkspaceEx; IRasterDataset rasterDataset = rasterWorkspaceEx.OpenRasterDataset("Siniflandirma_Aydeniz"); IRasterDatasetEdit2 raster = (IRasterDatasetEdit2)rasterDataset; ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset = (ESRI.ArcGIS.Geodatabase.IGeoDataset)rasterDataset; raster.BuildAttributeTable(); ITable vat = (raster as IRasterBandCollection).Item(0).AttributeTable; AddField(vat, "SONUC", "TEXT"); IQueryFilter queryFilter = new QueryFilterClass(); ICursor updateCursor = vat.Search(queryFilter, false); IRow feature = null; while ((feature = updateCursor.NextRow()) != null) { int kksField = feature.Fields.FindField("R_kks"); int nksField = feature.Fields.FindField("R_nks"); int sonucField = feature.Fields.FindField("SONUC"); string sonucValue = string.Empty; int nksValue = Convert.ToInt32(feature.get_Value(nksField)); int kksValue = Convert.ToInt32(feature.get_Value(nksField)); if (nksValue != kksValue) { sonucValue = "Diğer"; } else if (nksValue == 1) { sonucValue = "Çöl"; } else if (nksValue == 2) { sonucValue = "Çok Kurak"; } else if (nksValue == 3) { sonucValue = "Kurak"; } else if (nksValue == 4) { sonucValue = "Yarı Kurak"; } else if (nksValue == 5) { sonucValue = "Yarı Nemli"; } else if (nksValue == 6) { sonucValue = "Nemli"; } else if (nksValue == 7) { sonucValue = "Çok Nemli (Islak)"; } else if (nksValue == 0) { sonucValue = "Diğer"; } feature.set_Value(sonucField, sonucValue); feature.Store(); } tpSonuc.CustomText = "İşlem tamamlandı..."; tpSonuc.PerformStep(); (this.Parent as Form).Close(); }