基于ArcGIS VBA的宗地四至生成法1

  • 格式:doc
  • 大小:47.50 KB
  • 文档页数:5

'-------------------------------------------基础配置----------------------------------------Dim pMxDoc As IMxDocument '代表本文档数据Dim pMap As IMap '代表激活的地图Dim pFeaLayer As IFeatureLayer '代表地图中的图层,这里仅有一个Dim pFeaClass As IFeatureClass '代表图层中的要素类数据'-------------------------------------------查询条件----------------------------------------Dim pQueryF1 As IQueryFilter '查询条件1Dim pQueryF2 As IQueryFilter '查询条件2Dim pFeaCursor1 As IFeatureCursor '要素游标1,提取要素数据使用Dim pFeaCursor2 As IFeatureCursor '要素游标2,提取要素数据使用Dim pFeature1 As IFeature '要素1对应变量Dim pFeature2 As IFeature '要素2对应变量'-------------------------------------------算法变量-----------------------------------------Dim iNameCount As Long '权利人数组存有的数目Dim iColumnCountStart As Long '起始输入的Excel行数Dim iColumnCountEnd As Long '结束输入的Excel行数Dim bIsNameExist As Boolean '标识当前权利人是否已写入Dim pName As String '当前权利人姓名Dim pNameArray() As String '已写入权利人姓名数组'----------------------------------------Excel数据写入准备-----------------------------------Dim xlapp As Excel.ApplicationDim xlbook As Excel.WorkbookDim xlsheet As Excel.WorksheetSet xlapp = CreateObject("excel.Application")Set xlbook = xlapp.Workbooks.Open("D:\实验表格.xls")xlapp.Visible = TrueSet xlsheet = xlbook.Worksheets(1)On Error GoTo ErrorHandler:iNameCount = 0iColumnCountStart = 5iColumnCountEnd = 5bIsNameExist = FalseSet pMxDoc = ThisDocumentSet pMap = pMxDoc.FocusMapSet pFeaLayer = yer(0)Set pFeaClass = pFeaLayer.FeatureClassSet pQueryF1 = New QueryFilterSet pQueryF2 = New QueryFilter'-------------------------------------------写Excel表头--------------------------------------With xlsheet.Cells(1, 1) = "农村土地承包经营权调查信息公示表".Cells(3, 1) = "序号".Cells(3, 2) = "承包方" & Chr(13) & Chr(10) & "(代表)".Cells(3, 3) = "地块总体情况".Cells(3, 5) = "地块具体情况".Cells(3, 13) = "公示" & Chr(13) & Chr(10) & "备注".Cells(4, 3) = "合同" & Chr(13) & Chr(10) & "面积".Cells(4, 4) = "实测" & Chr(13) & Chr(10) & "面积".Cells(4, 5) = "地块" & Chr(13) & Chr(10) & "名称".Cells(4, 6) = "地块" & Chr(13) & Chr(10) & "编码".Cells(4, 7) = "东至".Cells(4, 8) = "南至".Cells(4, 9) = "西至".Cells(4, 10) = "北至".Cells(4, 11) = "合同" & Chr(13) & Chr(10) & "面积".Cells(4, 12) = "实测" & Chr(13) & Chr(10) & "面积".Range(.Cells(3, 1), .Cells(4, 13)).Borders.LineStyle = xlContinuous.Range(.Cells(1, 1), .Cells(4, 13)).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter.Range(.Cells(1, 1), .Cells(4, 13)).VerticalAlignment = Excel.XlHAlign.xlHAlignCenter.Range(.Cells(1, 1), .Cells(1, 13)) = "黑体".Range(.Cells(1, 1), .Cells(1, 13)).Font.size = 14.Range(.Cells(3, 1), .Cells(4, 13)) = "宋体".Range(.Cells(3, 1), .Cells(4, 13)).Font.size = 9.5.Range(.Cells(1, 1), .Cells(1, 13)).Merge.Range(.Cells(3, 1), .Cells(4, 1)).Merge.Range(.Cells(3, 2), .Cells(4, 2)).Merge.Range(.Cells(3, 3), .Cells(3, 4)).Merge.Range(.Cells(3, 5), .Cells(3, 12)).Merge.Range(.Cells(3, 13), .Cells(4, 13)).MergeEnd With'------------------------------------------------------------------------------------------'pQueryF1.WhereClause = "权利人='" + "黄永和'" '重置一次循环对象集,实验Set pFeaCursor1 = pFeaClass.Search(Nothing, False)Set pFeature1 = pFeaCursor1.NextFeatureDo While Not pFeature1 Is NothingpName = pFeature1.Value(pFeature1.Fields.FindFieldByAliasName("权利人")) '获取当前权利人信息If iNameCount <> 0 Then '001--判断是否已写入过此权利人For i = 1 To iNameCount '----------------002If pName = pNameArray(i) Then '003bIsNameExist = TrueEnd If '003Next i '----------------002End If '001--判断是否已写入过此权利人If bIsNameExist = False TheniNameCount = iNameCount + 1ReDim Preserve pNameArray(1 To iNameCount)pNameArray(iNameCount) = pName'---------------------------------------------pQueryF2.WhereClause = "权利人='" + pName + "'" '重置一次循环对象集,实验Set pFeaCursor2 = pFeaClass.Search(pQueryF2, False)Set pFeature2 = pFeaCursor2.NextFeatureDim iRightNum As IntegeriRightNum = 0Dim dTotalArea As DoubledTotalArea = 0#Do While Not pFeature2 Is NothingiRightNum = iRightNum + 1dTotalArea = dTotalArea + pFeature2.Value(pFeature2.Fields.FindFieldByAliasName("Shape_Area"))'此处向excel写入数据,依据iColumnCountEndWith xlsheet.Cells(iColumnCountEnd, 5) = "" '地块名称.Cells(iColumnCountEnd, 6) = "" '地块编码.Cells(iColumnCountEnd, 7) = pFeature2.Value(pFeature2.Fields.FindFieldByAliasName("东至")) .Cells(iColumnCountEnd, 8) = pFeature2.Value(pFeature2.Fields.FindFieldByAliasName("南至")) .Cells(iColumnCountEnd, 9) = pFeature2.Value(pFeature2.Fields.FindFieldByAliasName("西至")) .Cells(iColumnCountEnd, 10) = pFeature2.Value(pFeature2.Fields.FindFieldByAliasName("北至")) .Cells(iColumnCountEnd, 11) = "" '合同面积.Cells(iColumnCountEnd, 12) = Format(pFeature2.Value(pFeature2.Fields.FindFieldByAliasName("Shape_Area")) * 0.0015, "0.00")End WithiColumnCountEnd = iColumnCountEnd + 1Set pFeature2 = pFeaCursor2.NextFeatureLoopWith xlsheet.Cells(iColumnCountStart, 2) = pName.Cells(iColumnCountStart, 3) = "".Cells(iColumnCountStart, 4) = "合计:".Cells(iColumnCountStart + 1, 4) = iRightNum & "块".Cells(iColumnCountStart + 2, 4) = Format(dTotalArea * 0.0015, "0.00") & "亩".Range(.Cells(iColumnCountStart, 1), .Cells(iColumnCountStart + iRightNum + 1, 1)).Merge.Range(.Cells(iColumnCountStart, 2), .Cells(iColumnCountStart + iRightNum + 1, 2)).Merge.Range(.Cells(iColumnCountStart, 1), .Cells(iColumnCountEnd + 2, 13)).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter.Range(.Cells(iColumnCountStart, 1), .Cells(iColumnCountEnd + 2, 13)).VerticalAlignment = Excel.XlHAlign.xlHAlignCenter.Range(.Cells(iColumnCountStart, 1), .Cells(iColumnCountEnd + 2, 13)) = "宋体".Range(.Cells(iColumnCountStart, 1), .Cells(iColumnCountEnd + 2, 13)).Font.size = 9.5End With'此处合并单元格,依据iColumnCountStart、iRightNumiColumnCountStart = iColumnCountStart + iRightNum + 1 + 1iColumnCountEnd = iColumnCountEnd + 1 + 1End IfSet pFeature1 = pFeaCursor1.NextFeaturebIsNameExist = FalseLoopxlapp.ActiveWorkbook.Savexlapp.Workbooks.Closexlapp.QuitSet xlapp = NothingMsgBox "数据处理完成!"Exit SubErrorHandler:MsgBox Err.DescriptionEnd SubPrivate Sub CommandButton3_Click()Dim xlapp As Excel.ApplicationDim xlbook As Excel.WorkbookDim xlsheet As Excel.WorksheetSet xlapp = CreateObject("excel.Application")Set xlbook = xlapp.Workbooks.Open("D:\实验表格.xls")xlapp.Visible = TrueSet xlsheet = xlbook.Worksheets(1)With xlsheet.Cells(1, 1) = "农村土地承包经营权调查信息公示表".Cells(3, 1) = "序号".Cells(3, 2) = "承包方" & Chr(13) & Chr(10) & "(代表)".Cells(3, 3) = "地块总体情况".Cells(3, 5) = "地块具体情况".Cells(3, 13) = "公示" & Chr(13) & Chr(10) & "备注".Cells(4, 3) = "合同" & Chr(13) & Chr(10) & "面积".Cells(4, 4) = "实测" & Chr(13) & Chr(10) & "面积".Cells(4, 5) = "地块" & Chr(13) & Chr(10) & "名称".Cells(4, 6) = "地块" & Chr(13) & Chr(10) & "编码".Cells(4, 7) = "东至".Cells(4, 8) = "南至".Cells(4, 9) = "西至".Cells(4, 10) = "北至".Cells(4, 11) = "合同" & Chr(13) & Chr(10) & "面积".Cells(4, 12) = "实测" & Chr(13) & Chr(10) & "面积".Range(.Cells(3, 1), .Cells(4, 13)).Borders.LineStyle = xlContinuous.Range(.Cells(1, 1), .Cells(4, 13)).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter .Range(.Cells(1, 1), .Cells(4, 13)).VerticalAlignment = Excel.XlHAlign.xlHAlignCenter.Range(.Cells(1, 1), .Cells(1, 13)) = "黑体".Range(.Cells(1, 1), .Cells(1, 13)).Font.size = 14.Range(.Cells(3, 1), .Cells(4, 13)) = "宋体".Range(.Cells(3, 1), .Cells(4, 13)).Font.size = 9.5.Range(.Cells(1, 1), .Cells(1, 13)).Merge.Range(.Cells(3, 1), .Cells(4, 1)).Merge.Range(.Cells(3, 2), .Cells(4, 2)).Merge.Range(.Cells(3, 3), .Cells(3, 4)).Merge.Range(.Cells(3, 5), .Cells(3, 12)).Merge.Range(.Cells(3, 13), .Cells(4, 13)).MergeEnd Withxlapp.ActiveWorkbook.Savexlapp.Workbooks.Closexlapp.QuitSet xlapp = NothingEnd Sub。