|
POST
|
I think you are overly complicating this or not telling me what you are realy doing. Describe the end result better or give me a picture of what you want. You are making an excesssive number of defintion query variables that all point to the same layer, so I believe you just need one variable. You also keep creating the same whereclause, so make that a variable unless you are going to create a variant of the whereclause. Why are there 2 Subs now and how are they supposed to work together? Right now they potentially will conflict with each other if they have different input variables and restrict each other from working with all of the features, because they will either be blocked by the definition query of the other or undo the definition query. Are you trying to create a filtered layer and then create a selectionlayer and then a third selection layer from them that has a subselection? Or perhaps you do not want your Soils layer to ever have a Definition query that restricts the polygons it displays, in which case you should clear the definition query once you have finished creating a selection and zooming or creating a selection layer. (Your first sub then should maybe not create a definition query or a Selection layer and just select and zoom to features.) I still believe you need to clear the DefinitionQuery of the layer first before you select features or else your code will never create a new selection, because it will be blocked by a preexisting defintion query on the second try. I also got rid of code that seemed to do nothing. That may break it, but the code needs to be cleaned up. Your second Sub (not Function) was missing variable assignments and would have thrown errors using Option Explicit, since you did not initialize the pMxDoc or pMap variables or declare an "i" variable for your sub. I have added those assignments. Option Explicit
Public Sub ZoomToLandUnit(ByVal strLandUnit As String, ByVal strKabupaten As String, ByVal bKabupaten As Boolean)
Dim pDocument As IMxDocument
Set pDocument = ThisDocument
Dim pMap As IMap
Set pMap = pDocument.FocusMap
Dim pLayer As ILayer
Dim i As Long
For i = 0 To pMap.LayerCount - 1
If pMap.Layer(i).Name = "Soil" Then
Set pLayer = pMap.Layer(i)
End If
Next i
If pLayer Is Nothing Then Exit Sub
'set up the selection
Dim pFeatLayer As IFeatureLayer
Set pFeatLayer = pLayer
Dim pFeatDef As IFeatureLayerDefinition
Set pFeatDef = pFeatLayer
pFDef.DefinitionExpression = "" ' Clear any definition query so your feature selection query is not blocked.
Dim pFeatSelection As IFeatureSelection
Set pFeatSelection = pFeatLayer
Dim strWhereClause As String
If bKabupaten Then
strWhereClause = "Land_Unit = '" & strLandUnit & "' And KABUPATEN = '" & strKabupaten & "'"
Else
strWhereClause = "Land_Unit = " & "'" & strLandUnit & "'"
End If
Dim pQueryFilter As IQueryFilter
Set pQueryFilter = New queryFilter
pQueryFilter.WhereClause = strWhereClause
pFeatSelection.Clear
pFeatSelection.SelectFeatures pQueryFilter, esriSelectionResultNew, False
'access the feature
Dim pSelectionSet As ISelectionSet
Set pSelectionSet = pFeatSelection.selectionSet
If pSelectionSet.Count = 0 Then
MsgBox " The expression was verified successfully, but no records were returned", vbInformation
Unload frmCreateLayout
Exit Sub
End If
'zoom to all selected features
Dim pEnumGeom As IEnumGeometry
Dim pEnumGeomBind As IEnumGeometryBind
Set pEnumGeom = New EnumFeatureGeometry
Set pEnumGeomBind = pEnumGeom
pEnumGeomBind.BindGeometrySource Nothing, pSelectionSet
Dim pGeomFactory As IGeometryFactory
Set pGeomFactory = New GeometryEnvironment
Dim pGeom As IGeometry
Set pGeom = pGeomFactory.CreateGeometryFromEnumerator(pEnumGeom)
'update the extent of the map to match the extent of the selected features
Dim pActiveView As IActiveView
Set pActiveView = pMap
pActiveView.Extent = pGeom.Envelope
pActiveView.Refresh
' Do you mean to do this code or do you intend to use the other Sub to do this?
pFDef.DefinitionExpression = strWhereClause ' Do you really want this line to store the definition query on the Soils layer so that it does not display all features?
Dim SelFeatLayer As IFeatureLayer
Set SelFeatLayer = pFDef.CreateSelectionLayer(strLandUnit, True, "", "")
With pDocument
.AddLayer SelFeatLayer
.FocusMap.MoveLayer SelFeatLayer, 2
' .FocusMap.ClearSelection ' Not sure if you want to Clear the Selection. Remove the first comment quote if you do.
.activeView.Refresh
.UpdateContents
End With
End Sub
' This Is not a Function, since it does not return anything.
' THis is a Sub and it is conflicts with the prior Sub unless it is called by the prior Sub only so that it always matches the input variables.
Public Sub CreateSelLayer(ByVal strLandUnit As String, ByVal strKabupaten As String, ByVal bKabupaten As Boolean)
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Dim pLayer As ILayer
Dim i As Long
For i = 0 To pMap.LayerCount - 1
If pMap.Layer(i).Name = "Soil" Then
Set pLayer = pMap.Layer(i)
End If
Next i
If pLayer Is Nothing Then Exit Function
Dim pFLayer As IFeatureLayer
Set pFLayer = pLayer
Dim pFDef As IFeatureLayerDefinition
Set pFDef = pFLayer
pFDef.DefinitionExpression = "" ' Clear any definition query so your feature selection query is not blocked
' or else delete the above line if this Sub is always called by the other sub and always matches its inputs.
'Make a selection on the FeatureLayer
Dim pFeatSelection As IFeatureSelection
Set pFeatSelection = pFLayer
Dim pQueryFilter As IQueryFilter
Set pQueryFilter = New queryFilter
If bKabupaten Then
pQueryFilter.WhereClause = "Land_Unit = '" & strLandUnit & "' And KABUPATEN = '" & strKabupaten & "'"
Else
pQueryFilter.WhereClause = "Land_Unit = " & "'" & strLandUnit & "'"
End If
pFeatSelection.Clear
pFeatSelection.SelectFeatures pQueryFilter, esriSelectionResultNew, False
Dim SelFeatLayer As IFeatureLayer
Set SelFeatLayer = pFDef.CreateSelectionLayer(strLandUnit, True, "", "")
With pMxDoc
.AddLayer SelFeatLayer
.FocusMap.MoveLayer SelFeatLayer, 2
.FocusMap.ClearSelection
.activeView.Refresh
.UpdateContents
End With
End Sub
... View more
11-12-2010
09:21 PM
|
0
|
0
|
2065
|
|
POST
|
thank you for the information, but what i am looking for is that in the field the actual dollar sign appears. if a open the attribute table in arcmap, i can set in the field properties a number format. for example currency. do you know how i can set this number format in model builder, for the field i add? Unless the property is exposed through one of the tools in the Layers and Table Views subgroup of the Data Management tools group I don't think you can set it. You are describing a layer property, and not a feature class property, so the layers group is the logical place to look. ModelBuilder is far from a fine grade tool set that gives full access to all settings available through the ArcMap interface. It is very course grade. ArcObjects provides fine grade access all properties and setting levels, but cannot be integrated into ModelBuilder. ArcPy at ArcGIS 10 is a definite step up over ModelBuilder for accessing properties, but it also cannot access as many properties as ArcObjects at this time. Eventually ArcPy may match ArcObjects and then you could use it within ModelBuilder Scripts to manipulate settings within the ModelBuilder environment.
... View more
11-12-2010
11:13 AM
|
0
|
0
|
3368
|
|
POST
|
Hi - I have a data layer that has 5 ft contour intervals. I would like to extract only the contours that are multiples of 10, so that I can have a data layer that is 10 ft contours. What is the selection query I need to get this to work? Thanks in advance for any help; I am tired of banging my head on this one! Pam The SQl you need is for the MOD function. The syntax for its use depends on the database (PGDB, FGDB, SDE Oracle, etc.). I believe the syntax for a FGDB is something like the following (assumes your contours have a field called ELEVATION): MOD([ELEVATION], 10) = 0
... View more
11-11-2010
11:39 AM
|
3
|
0
|
4993
|
|
POST
|
Thanks Richard, No more error from the compiler now, but when I run for the second time it goes to the message box. I open the attribute table and I see only the records of the previous land unit I�??ve chosen, then I compare with the attribute table from the example. The difference is the records from the example attribute table always change every running and mine don�??t. I�??ve also change this line: Set SelFeatLayer = pFeatDef.CreateSelectionLayer(Soil, True, "", "") To: Set SelFeatLayer = pFeatDef.CreateSelectionLayer(strLandUnit, True, "", "") But still have no change. Please more suggestion. Thanks a lot Richard.. Amie Try: Set SelFeatLayer = pFeatDef.CreateSelectionLayer(strLandUnit, True, "", pFeatLayerDef.DefinitionExpression) Edit: I think the reason your code does not work a second time is that the definition query of the previous run is stored in the layer, which keeps you from selecting any records that do not match the original values. You need to clear the defintion query of the layer with each new pass. So change the beginning to read: Public Sub ZoomToLandUnit(byVal strLandUnit As String, byVal strKabupaten as String, byVal bKabupaten as Boolean)
Dim pDocument As IMxDocument
Set pDocument = ThisDocument
Dim pMap As IMap
Set pMap = pDocument.FocusMap
Dim pFeatLayer As IFeatureLayer
Dim pFeatClass As IFeatureClass
Dim pLayer As ILayer
Dim i As Long
For i = 0 To pMap.LayerCount - 1
If pMap.Layer(i).Name = "Soil" Then
Set pLayer = pMap.Layer(i)
End If
Next i
If pLayer Is Nothing Then Exit Sub
Dim pFeatLayerDef As IFeatureLayerDefinition ' Remove the duplication of this line that appears lower in the code.
Set pFeatLayerDef = pLayer
pFeatLayerDef.DefinitionExpression = ""
' Etc.
... View more
11-11-2010
08:32 AM
|
0
|
0
|
2065
|
|
POST
|
I found out that the ISelectionSet2 interface lets you create an Update cursor on a Feature Selection, so my comments about having to do special work for selection sets is not correct. While the synchronized cursors seems to work for me it has not for another user. I am not sure why that is occurring, so my code suggestion may not work.
... View more
11-11-2010
07:03 AM
|
0
|
0
|
1362
|
|
POST
|
After thinking about the second part of my post I realized that your original features are likely to be broken into many segments and that any given segment will not necessarily be oriented the same as all of the others that build a Route. Establishing orientation can be disorienting, but it can be done. I like the approach or building the routes intially from any of the directions. I would still calculate the From and To X and Y of the original lines. But after that I would do a Locate Features Along Routes for the lines (with a small tolerance). The output table can now be used to create a sequencing of the lines. You can use Chris Snyders Permananly Sort Feature tool in my post within this thread to get the features ordered in a way that will help create the sequences (sort on Route Id and the From Measure). This can help you find your origen feature for the route which will help define the origen point to use to build the routes. You can also export the events to features and calculate the new From and To X and Y of the lines to determine if they flipped. With this information you can calculate a new field to your original features that represents the origen direction that should be used. (It involves joins, various selections and field calculations to fill in the field). Then you can use that value to do the 4 selections and build your 4 sets of routes that will append together. I have done this approach to handle a similar need to control orientation of the original features relative to the routes. It worked although I would not necessarily call it an easy process. In my case I did not have a flow direction (my network is bidirectional roads), so getting connectivity correct was my sole consideration. In your case, you may have to build some routes manually, since some streams may not choose the headwater origen feature no matter what origen point you pick using the automated tools. Here is a VBA Field Calculation that is helpful for determining if your route features are simple or complex. A value of 1 indicates you have a simple route with always increasing measures. All other values indicate complex routes (branched routes or loops in most cases). Dim Output As Long Dim l As Long Dim pCurve As ICurve Dim pSegmentCollection As IMSegmentation3 Set pCurve = [Shape] Set pSegmentCollection = pCurve Output = pSegmentCollection.MMonotonicity
... View more
11-10-2010
08:30 PM
|
0
|
0
|
1152
|
|
POST
|
I have a line feature class in which I need to extract measurements based on a pre-existing point feature class. So, for each point on the line, I need to find its measurement along the line. I need to create measurements along the line using the Create Routes tool. My data is in a Lambert projection (feet), although I need for the point measurements along the line to be captured in decimal degrees. Also, I am using stream data, which flows from all directions. I used the Create Routes tool to quality assess the direction 0 to 1234, and noticed many of the streams were calculating distance from the wrong end. Is there a way to automate this process potentially through elevation, or possibly another means? Thanks in advance for your time! Linear Reference Measure values cannot be expressed as two numeric values, and I am unaware of any way to use decimal degrees that is expressed through a single numeric value. Latitide and Longitude cannot be boiled down to a single number and the distance covered by a degree of Latitude is different from the distance covered by a degree of Longitude so movement in both directions cannot be expressed in a single decimal degree value to my knowledge. Your measures can be in any linear units that are not dependent on a specific spatial plane of movement, such as feet, meters, time, etc. You can, however, convert any resulting event point you create along your line to the appropriate Decimal Degrees pair of values with the approriate projection manipulation, but that is a separate process from setting or getting events along the line with a measure value (which is what Linear referencing is all about). If I were trying to get the routes to build in the appropriate orientation and the lines are digitized to match the direction of flow I would calculate the From and To X and Y coordinates of the Routes into fields. Then I would build a model. In the model I would use SQL to do 4 selections to find routes that were dgitized from the upper left, lower left, upper right, and lower right and pass each selection to the Create Route tool with the appropriate origen setting. Then I would append the 4 Route outputs together in the model. The SQL for upper left Routes would be something like the following (this selection logic assumes that your local coordinates do not include both positive and negative values in a single plane of movement): (ABS([FromX]-[ToX]) >= ABS([FromY]-[ToY]) AND [FromX] < [ToX]) OR (ABS([FromX]-[ToX]) < ABS([FromY]-[ToY]) AND [FromY] < [ToY])
... View more
11-10-2010
07:25 PM
|
0
|
0
|
1152
|
|
POST
|
Below I have revised the code to pass arguments representing the values in the comboboxes and the visible state of the second combobox. I assume you have a form with these comboboxes that is calling the Sub in another module. Let me know if this helps. Private Sub cmdNewLayer_Click()
Call ZoomTasks.ZoomToLandUnit(cboSatuanLahan.Text, cboKabupaten.Text, cboKabupaten.Visible) �??Assumes this command Button can see the comboboxes.
End Sub
Private Sub UserForm_Initialize()
Dim strFile1 As String
strFile1 = "D:\AMIE\BELAJAR\Belajar ArcObjects\LandUnit.txt"
Dim strLandUnit As String
Open strFile1 For Input As #1
Do Until EOF(1)
Input #1, strLandUnit
cboSatuanLahan.AddItem strLandUnit
Loop
Close #1
cboSatuanLahan.Value = "-Land Unit-"
Dim strFile2 As String
strFile2 = "D:\AMIE\BELAJAR\Belajar ArcObjects\Kabupaten.txt"
Dim strKabupaten As String
Open strFile2 For Input As #2
Do Until EOF(2)
Input #2, strKabupaten
cboKabupaten.AddItem strKabupaten
Loop
Close #2
cboKabupaten.Value = "-Kabupaten-"
End Sub
Public Sub ZoomToLandUnit(byVal strLandUnit As String, byVal strKabupaten as String, byVal bKabupaten as Boolean)
Dim pDocument As IMxDocument
Set pDocument = ThisDocument
Dim pMap As IMap
Set pMap = pDocument.FocusMap
Dim pFeatLayer As IFeatureLayer
Dim pFeatClass As IFeatureClass
Dim pLayer As ILayer
Dim i As Long
For i = 0 To pMap.LayerCount - 1
If pMap.Layer(i).Name = "Soil" Then
Set pLayer = pMap.Layer(i)
End If
Next i
If pLayer Is Nothing Then Exit Sub
'set up the selection
Dim pFeatSelection As IFeatureSelection
Set pFeatSelection = pLayer
Dim pQueryFilter As IQueryFilter
Set pQueryFilter = New queryFilter
If bKabupaten Then
pQueryFilter.WhereClause = "Land_Unit = '" & strLandUnit & "' And KABUPATEN = '" & strKabupaten & "'"
Else
pQueryFilter.WhereClause = "Land_Unit = " & "'" & strLandUnit & "'"
End If
pFeatSelection.Clear
pFeatSelection.SelectFeatures pQueryFilter, esriSelectionResultNew, False
'access the feature
Dim pSelectionSet As ISelectionSet
Set pSelectionSet = pFeatSelection.selectionSet
Dim pDataset As IDataset
Set pDataset = pFeatClass
Set pFeatLayer = pLayer
Set pFeatClass = pFeatLayer.FeatureClass
If pSelectionSet.Count = 0 Then
MsgBox " The expression was verified successfully, but no records were returned", vbInformation
Unload Me
Exit Sub
End If
Dim pFeatCursor As IFeatureCursor
pSelectionSet.Search Nothing, False, pFeatCursor
Dim pFeature As IFeature
Set pFeature = pFeatCursor.NextFeature()
'zoom to all features
Dim pEnumGeom As IEnumGeometry
Dim pEnumGeomBind As IEnumGeometryBind
Set pEnumGeom = New EnumFeatureGeometry
Set pEnumGeomBind = pEnumGeom
pEnumGeomBind.BindGeometrySource Nothing, pSelectionSet
Dim pGeomFactory As IGeometryFactory
Set pGeomFactory = New GeometryEnvironment
Dim pGeom As IGeometry
Set pGeom = pGeomFactory.CreateGeometryFromEnumerator(pEnumGeom)
Dim pFeatLayerDef As IFeatureLayerDefinition
Set pFeatLayerDef = pLayer
If bKabupaten Then
pFeatLayerDef.DefinitionExpression = "Land_Unit = '" & strLandUnit & "' And KABUPATEN = '" & strKabupaten & "'"
Else
pFeatLayerDef.DefinitionExpression = "Land_Unit = " & "'" & strLandUnit & "'"
End If
'update the extent of the map to match the extent of the feature
Dim pActiveView As IActiveView
Set pActiveView = pMap
pActiveView.Extent = pGeom.Envelope
pActiveView.Refresh
Dim pFeatDef As IFeatureLayerDefinition
Set pFeatDef = pFeatLayer
Dim SelFeatLayer As IFeatureLayer
Set SelFeatLayer = pFeatDef.CreateSelectionLayer(Soil, True, "", "")
pActiveView.Refresh
pDocument.UpdateContents
End Sub
... View more
11-10-2010
06:36 PM
|
0
|
0
|
2065
|
|
POST
|
Looking at your code it appears that the performance hits are primarily due to having to to query each feature of the joined table more or less individually to create the link. Some sort of Array or List that could read and store all of the joined table records in memory once would be more efficient than hitting the on disk table through queries multiple times. 75,000 records total does not seem like it would exhaust your resources especially if the join table has much fewer records (or no more records). Choosing an approapriate Array, collection or list that gives you an efficient key to match each feature of your layers would be needed or you would need to sort the features to match the array sort so that you are not having to go backwards and forwards in the Array for a given layer. .Net has a variety of objects for storing arrays, lists or collections, so something should work (Possibly a List of Arrays or Structs would work). Anyway, that would be the basic approach I would investigate.
... View more
11-08-2010
10:32 AM
|
0
|
0
|
2613
|
|
POST
|
You are correct that either you need to include an argument of some variable that is a string in your ZoomToLandUnit Sub declaration or you need to remove it from the calling declaration. Currently the two do not match. If your ZoomToLandUnit can access the form combobox values directly from the Form without being given them as arguments, then you don't really need the arguments. If the Subroutine needs to work outside of the Form, then you need to supply the combobox values through the arguments. If you use argument variables in the Sub declaration definition, you need to use those values in the Sub code to do something, otherwise just adding unused parameters serves no purpose. Because no passed parameter variables are currently used in your Sub and the Sub seems to get the information it needs from the Form combobox states, I would just remove the attempt to pass a parameter from the calling code: Private Sub cmdNewLayer_Click()
Call ZoomTasks.ZoomToLandUnit() �??Your Sub has no argument parameters so do not pass any
End Sub
... View more
11-06-2010
10:26 AM
|
0
|
0
|
2065
|
|
POST
|
Your code looks basically fine to me provided that your field name is actually Land_Unit. Does it not get the result you want? Potentially you want to have code that validates that a choice has been made in the comboboxes prior to letting this code fire. I would test that the values are greater than " ".
... View more
11-05-2010
01:37 PM
|
0
|
0
|
2065
|
|
POST
|
Pivot Tables requires an ArcInfo license to run. ArcView won't cut it.
... View more
11-04-2010
02:52 PM
|
0
|
0
|
1693
|
|
POST
|
ArcGIS 10 does not support VBA. It supports VB Script, which cannot be used to do geometry based calculations. Your only option with the field calculator is to rewrite the calculation in Python. I am not that good with Python, so I will leave it to others to help you.
... View more
11-02-2010
06:21 PM
|
0
|
0
|
2009
|
|
POST
|
Hi, Please some one share how to write code for my requirement in ArcGIS Desktop. My requirement -To calculate lenghth of a polyline(with conditions) -My polyline is passing(Overlaping) through diffrent polygons. - I want to calculate length of polyline seperatly crossing on each polygon(overlaped lenght of polyline in each polygon) . I have three Polygon layers and one polyline. polyline is passing through each polygon layers. please share some ideas. To get the help you need, please tell us the version you are programming for (9.2, 9.3.1, 10), minimum license level that the program must support (ArcView, ArcEditor, ArcInfo) and the preferred programming language you want it writen in (VBA, VB .Net, C .Net, etc).
... View more
10-31-2010
07:25 AM
|
0
|
0
|
1087
|
|
POST
|
Thank you for your time. Layer is a properties of FeatureClass. I dont understand why FIDSet dont work. Be sure that Land is a a layer (parcel land from geodatabase) 1- Try desc.Layer.FIDSet --> dont work 2- Try mygp.MakeFeatureLayer_management(desc.CatalogPath,"out").FIDSet ---> dont work also The question is how instantiate an object FeatureClass to access Layer properties. Thanks a lot. You are incorrect about some of your ideas. 1. A Layer is a separate object that depends on a FeatureClass, but a FeatureClass exists independently from a Layer. So while a FeatureClass can be accessed as a property of a described Layer, a Layer cannot be accessed directly from a described FeatureClass, it has to be created from the FeatureClass first before you can access its properties. 2. You are bypassing the describe of the Layer object that is created by the MakeFeatureLayer_management tool. Each new object needs its own describe to access its describe properties. I believe the code needs to read: Lyr = mygp.MakeFeatureLayer_management(desc.CatalogPath,"out") descLyr = describe(Lyr) myFIDset = descLyr.FIDSet myFC = descLyr.FeatureClass # works because a FeatureClass is a property of a described Layer, but not the other way around The code above preserves both the Layer object itself for use in other gp tool processes and creates a describe object to access the describe properties of the layer for python processing and programming logic. It also provides a FeatureClass object for any tools that require that as an input. A FeatureClass is not a property of FeatureClass. It is the object type itself. This is why you could not access it as a property of the first describe from the FeatureClass. The gp Programming diagram shows that a FeatureClass inherits properties from a Table and a DataSet. A Dataset includes an Extent property, which is why that property worked. But a FeatureClass does not inherit properties from a Layer. A Layer shows that it inherits properties from a FeatureClass. It therefore should also inherit properties from Table and Dataset. So both Lyr.FeatureType and Lyr.Extent should work.
... View more
10-30-2010
09:25 AM
|
0
|
0
|
1204
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 03-24-2026 08:01 PM | |
| 6 | 02-23-2026 08:34 AM | |
| 1 | 03-31-2025 03:25 PM | |
| 1 | 03-28-2025 06:54 PM | |
| 1 | 03-16-2025 09:49 PM |
| Online Status |
Offline
|
| Date Last Visited |
03-24-2026
07:54 PM
|