Tool for generating N points and for generating N Polygon

Source: Internet
Author: User
// It is later found that feature is inserted. You can skip this step.
PWorkSpaceEdit. StartEditing True
PWorkSpaceEdit. StartEditOperation

*********************************
PWorkSpaceEdit. StopEditing True
PWorkSpaceEdit. StopEditOperation

// Required only when editing
Private Sub commandbutton#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) = "Wuhan" & I
PFeature. Store

Next I

PActiveView. Refresh


PWorkSpaceEdit. StopEditing True

End Sub

'================================================

 

Private Sub commandbutton#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 ipolympus gon
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) = "Wuhan" & I
PFeature. Store

Next I

PActiveView. Refresh


PWorkSpaceEdit. StopEditing True
End Sub

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.