zoukankan      html  css  js  c++  java
  • 生成N个点的工具,和生成N个多边形的工具

    //后来发现插入feature,可以不用
        pWorkSpaceEdit.StartEditing True
        pWorkSpaceEdit.StartEditOperation

    *********************************
        pWorkSpaceEdit.StopEditing True
        pWorkSpaceEdit.StopEditOperation

    //编辑的时候才需要
    Private Sub CommandButton1_Click()

    Dim PolyCount As Integer
    PolyCount = Val(TextBox1.Text)
    Dim i As Integer

    Dim pMxDoc As IMxDocument
    Set pMxDoc = Application.Document

    Dim pMap As IMap
    Set pMap = pMxDoc.FocusMap

    Dim pActiveView As IActiveView
    Set pActiveView = pMxDoc.FocusMap

    Dim pFeaturelayer As IFeatureLayer
    Set pFeaturelayer = pMap.Layer(0)

    Dim pFeatureClass As IFeatureClass
    Set pFeatureClass = pFeaturelayer.FeatureClass


    Dim pDataSet As IDataset
    Set pDataSet = pFeatureClass

    Dim pWorkSpace As IWorkspace
    Set pWorkSpace = pDataSet.Workspace

    Dim pWorkSpaceEdit As IWorkspaceEdit
    Set pWorkSpaceEdit = pWorkSpace


        pWorkSpaceEdit.StartEditing True
        pWorkSpaceEdit.StartEditOperation

        
        For i = 0 To PolyCount - 1
        
        Dim pFeature As IFeature
        Set pFeature = pFeatureClass.CreateFeature
        Dim pPoint As IPoint
        Set pPoint = New Point
        pPoint.PutCoords 10000000000000# * Rnd, 10000000000000# * Rnd
        Set pFeature.Shape = pPoint
        Dim pFields As IFields
        Set pFields = pFeatureClass.Fields
        Dim idx As Integer
        idx = pFields.FindField("Name")
        pFeature.Value(idx) = "武汉" & i
        pFeature.Store
        
        Next i
        
        pActiveView.Refresh
     
     
    pWorkSpaceEdit.StopEditing True

    End Sub

    ‘=======================================

    Private Sub CommandButton1_Click()

    Dim PolyCount As Integer
    PolyCount = Val(TextBox1.Text)
    Dim i As Integer

    Dim pMxDoc As IMxDocument
    Set pMxDoc = Application.Document

    Dim pMap As IMap
    Set pMap = pMxDoc.FocusMap

    Dim pActiveView As IActiveView
    Set pActiveView = pMxDoc.FocusMap

    Dim pFeaturelayer As IFeatureLayer
    Set pFeaturelayer = pMap.Layer(0)

    Dim pFeatureClass As IFeatureClass
    Set pFeatureClass = pFeaturelayer.FeatureClass


    Dim pDataSet As IDataset
    Set pDataSet = pFeatureClass

    Dim pWorkSpace As IWorkspace
    Set pWorkSpace = pDataSet.Workspace

    Dim pWorkSpaceEdit As IWorkspaceEdit
    Set pWorkSpaceEdit = pWorkSpace

        pWorkSpaceEdit.StartEditing True
        pWorkSpaceEdit.StartEditOperation

        
        For i = 0 To PolyCount - 1
        
        Dim pFeature As IFeature
        Set pFeature = pFeatureClass.CreateFeature
        Dim pPointCollection4 As IPointCollection4
        Set pPointCollection4 = New Polygon
        Dim pPolygon As IPolygon
        Set pPolygon = pPointCollection4
        
        Dim pPoint As IPoint
        Set pPoint = New Point
        pPoint.PutCoords 571 * Rnd - 450, 351 * Rnd - 90
        pPointCollection4.AddPoint pPoint
        
     
        Set pPoint = New Point
        pPoint.PutCoords 571 * Rnd - 450, 351 * Rnd - 90
         pPointCollection4.AddPoint pPoint
     
        Set pPoint = New Point
        pPoint.PutCoords 571 * Rnd - 450, 351 * Rnd - 90
        pPointCollection4.AddPoint pPoint
         
         
        Set pFeature.Shape = pPolygon
        Dim pFields As IFields
        Set pFields = pFeatureClass.Fields
        Dim idx As Integer
        idx = pFields.FindField("Name")
        pFeature.Value(idx) = "武汉" & i
        pFeature.Store
        
        Next i
        
        pActiveView.Refresh
     
     
    pWorkSpaceEdit.StopEditing True
    End Sub

     

  • 相关阅读:
    【小白成长撸】--二分查找
    【ACM小白成长撸】--贪婪法解硬币找零问题
    【小白成长撸】--Fibonacci
    【ACM小白成长撸】--计算单词个数
    【小白成长撸】--多项式求圆周率PI
    【小白成长撸】--循环顺序队列
    【小白成长撸】--链栈(C语言版)
    盘前预测-3.15
    盘前预测-3.11
    盘前预测-3.10
  • 原文地址:https://www.cnblogs.com/zhangjun1130/p/1395420.html
Copyright © 2011-2022 走看看