[ArcObjects]Spatial Grid Index 계산하기..
- ArcCatalog에서 SDE로 FeatureClass(특히 Shapefile)를 업로드 할 때 Spatial Index가 모두 빠져 있는 경우가 있다.
- GDB나 FGDB 라면 그냥 Copy & Paste로 데이터를 복사할 경우엔 Spatial Index가 모두 딸려와 정상적으로 생성이 되지만.. ArcCatalog의 Import나 Export 기능을 사용할 때 (Shapefile의 경우에는 Copy & Paste가 되지 않음) 난감한 경우가 있다.
- ArcCatalog에서 FeatrueClass 속성 창을 보면 Spatial Index를 자동 계산해주는 버튼이 있지만 하나씩 해야 한다. 100개 이상의 레이어를 올리고 하나씩 눌러가며 계산했던 적이 있다. 헐~
- ArcToolBox > Feature Class > Calculate Default Spatial Grid Index 툴을 사용하면 계산이 가능하다. Batch로 해서 하면 되지만 해본 결과 계산은 잘되지만 적용이 잘 되지 않는 듯 하다. 속성창에는 계산된 값이 보여지는데 Preview를 하면 여전히 로드되지 않는다.
- 아래 코드는 ArcObjects를 사용하여 FeatureClass의 Default Spatial Index를 계산해 주는 코드이다.
- 참조된 라이브러리는
> ESRI.ArcGIS.Geoprocessor
> ESRI.ArcGIS.Geoprocessing
- Geoprocessor 인터페이스의 Excute 메서드를 사용하여 직접 ArcToolBox를 사용한다.
- CalculateDefaultGridIndex > RemoveSpatialIndex > AddSpatialIndex 순서로 생성한다.
1: private bool CalculateDefaultSpatialIndex(IFeatureClass pDestFc)
2: {3: if (pDestFc == null) return false;
4: 5: try
6: {7: bool bSucc = false;
8: 9: //추가할 FeatureClass Parameter 생성
10: IVariantArray pArray = new VarArrayClass();
11: pArray.Add(pDestFc); 12: 13: //Geoprocessor선언
14: Geoprocessor pGP = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
15: 16: //Defualt Spatial Index 계산
17: //CalculateDefaultGridIndex_management (in_features)
18: IGeoProcessorResult pResult = (IGeoProcessorResult)pGP.Execute19: ("CalculateDefaultGridIndex", pArray, null);
20: 21: if (pResult.Status == esriJobStatus.esriJobSucceeded) //계산성공
22: {23: //결과 String은.. "Grid1;Grid2;Grid3" 형태로 반환한다.
24: string sGridIdxValue = pResult.ReturnValue.ToString();
25: 26: string[] arrGridValue = sGridIdxValue.Split(';');
27: 28: string sGrid1 = arrGridValue[0].Trim();
29: string sGrid2 = arrGridValue[1].Trim();
30: string sGrid3 = arrGridValue[2].Trim();
31: 32: //기존 SpatialIndex 삭제
33: //RemoveSpatialIndex_management (in_features)
34: pResult = (IGeoProcessorResult)pGP.Execute35: ("RemoveSpatialIndex", pArray, null);
36: 37: if (pResult.Status == esriJobStatus.esriJobSucceeded)
38: {39: //새롭게 계산된 Spatial Index 추가
40: //AddSpatialIndex_management (in_features, g1, g2, g3)
41: pArray.Add(sGrid1); 42: pArray.Add(sGrid2); 43: pArray.Add(sGrid3); 44: 45: pResult = (IGeoProcessorResult)pGP.Execute46: ("AddSpatialIndex", pArray, null);
47: 48: if (pResult.Status == esriJobStatus.esriJobSucceeded)
49: {50: bSucc = true;
51: } 52: } 53: } 54: 55: System.Runtime.InteropServices.Marshal.ReleaseComObject(pResult); 56: System.Runtime.InteropServices.Marshal.ReleaseComObject(pArray); 57: 58: pResult = null;
59: pGP = null;
60: pArray = null;
61: 62: return bSucc;
63: }64: catch (Exception Ex)
65: {66: return false;
67: } 68: }
댓글
댓글 쓰기