Key functions used by self-developed identify (VB. NET source code)

Source: Internet
Author: User
Tags ipoint
Develop the identify function by yourself. The most important thing is to query the mouse click position and the layer information of the corresponding object. Use the following function, you can identify all types of layer information (all layers I know now). The applicability and usage of the function have been clearly written. Enjoy it! ^ _ ^

Private const const_fieldname as string = "field"
Private const const_valuename as string = "value"
''' <Summary>
''' To obtain the attributes of the selected feature
''' </Summary>
''' <Param name = "pfeat"> selected feature </param>
''' <Param name = "Player"> operate the feature layer </param>
''' <Returns> returns the datatable for binding to the grid. </returns>
''' <Remarks> used for any featurelayer </remarks>
Private function setfeatureproperty (byval pfeat as ifeature, byval player as ifeaturelayer) as datatable
If pfeat is nothing then return nothing: Exit Function
Dim ptable as new datatable
Ptable. Columns. Add (const_fieldname)
Ptable. Columns. Add (const_valuename)
Dim pfeatureclass as ifeatureclass = player. featureclass
Dim pfields as ifields = pfeatureclass. Fields
Dim playerfields as ilayerfields = new featurelayer
Playerfields = player
Dim pgomtrytype as esrigeometrytype = pfeatureclass. shapetype
Dim strtype as string = nothing
''Here, we use a dot, line, plane, or multiple slices as an example to expand it.
Select case pgomtrytype
Case esrigeometrytype. esrigeometrypoint
Strtype = "point"
Case esrigeometrytype. esrigeometrypolyline
Strtype = "polyline"
Case esrigeometrytype. esrigeometrypolygon
Strtype = "polygon"
Case esrigeometrytype. esrigeometrymultipatch
Strtype = "multipatch"
End select
For J as integer = 0 to pfields. fieldcount-1
Dim pfieldinfo as ifieldinfo = new fieldinfo
Pfieldinfo = playerfields. fieldinfo (j)
If pfieldinfo. Visible then
Dim prow as datarow = ptable. newrow
Prow. Item (0) = pfields. Field (j). Name
If j <> 1 then
Prow. Item (1) = pfeat. Value (j). tostring ()
Else
Prow. Item (1) = strtype
End if
Ptable. Rows. Add (prow)
End if
Next
Gridcontrolproperty. datasource = ptable
Return ptable
End Function
''' <Summary>
''' To obtain the properties of the tin corresponding to the cursor position
''' </Summary>
''' <Param name = "Ppoint"> click a map point </param>
''' <Param name = "ptinlayer"> operation TiN layer </param>
''' <Returns> returns the datatable for binding to the grid. </returns>
''' <Remarks> used for TiN layer </remarks>

Private function settinproperty (byval Ppoint as ipoint, byval ptinlayer as itinlayer) as datatable
Dim ptinsurface as itinsurface = new Tin
Ptinsurface = ptinlayer. Dataset
Dim ptinsurelement as itinsurfaceelement = ptinsurface. getsurfaceelement (Ppoint)
If ptinsurelement is nothing then return nothing: Exit Function
Dim ptable as new datatable
Ptable. Columns. Add (const_fieldname)
Ptable. Columns. Add (const_valuename)
Dim pfields as ifields = ptinlayer. dataset. Fields
Dim ppropertylist as List (of double) = new list (of double)
Ppropertylist. Add (ptinsurelement. elevation)
Ppropertylist. Add (ptinsurelement. slopedegrees)
Ppropertylist. Add (ptinsurelement. aspectdegrees)
Ppropertylist. Add (ptinsurelement. facetagvalue)
Ppropertylist. Add (ptinsurelement. nodetagvalue)
Dim playerfields as ilayerfields = new tinlayer
Playerfields = ptinlayer
For J as integer = 0 to pfields. fieldcount-1
Dim pfieldinfo as ifieldinfo = new fieldinfo
Pfieldinfo = playerfields. fieldinfo (j)
If pfieldinfo. Visible then
Dim prow as datarow = ptable. newrow
Prow. Item (0) = pfields. Field (j). Name
Prow. Item (1) = ppropertylist (j)
Ptable. Rows. Add (prow)
End if
Next
Gridcontrolproperty. datasource = ptable
Return ptable
End Function
''' <Summary>
''' To obtain the property information of the raster corresponding to the cursor position.
''' </Summary>
''' <Param name = "Ppoint"> map point clicked by the mouse </param>
''' <Param name = "prasterlayer"> operation layer </param>
''' <Returns> returns the datatable for binding to the grid. </returns>
''' <Remarks> used for raster layers, images, and other queries </remarks>
Private function setrasterproperty (byval Ppoint as ipoint, byval prasterlayer as irasterlayer) as datatable
Dim pidentify as iidentify = new rasterlayer
Pidentify = prasterlayer
Dim parray as iarray = pidentify. Identify (Ppoint)
If parray is nothing then return nothing: Exit Function
Dim prasteridentify2 as irasteridentifyobj2 = parray. element (0)
Dim prasteridentify as irasteridentifyobj = parray. element (0)
Dim pfield as string = nothing
Dim pvalue as string = nothing
Pfield = prasteridentify. Name
If pfield = "nodata" then return nothing: Exit Function
Dim ptable as new datatable
Ptable. Columns. Add (const_fieldname)
Ptable. Columns. Add (const_valuename)
Dim pidentifyindex as integer = 0
While 1
Try
Prasteridentify2.getpropandvalues (pidentifyindex, pfield, pvalue)
Catch ex as exception
Exit while
End try
Dim prow as datarow = ptable. newrow
Prow. Item (0) = pfield
Prow. Item (1) = pvalue
Ptable. Rows. Add (prow)
Pidentifyindex = pidentifyindex + 1
End while
Gridcontrolproperty. datasource = ptable
Return ptable
End Function

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.