Select to view content in your preferred language

Filling in atrributes for a point layer from a underlying polygon layer

4114
27
Jump to solution
08-28-2012 12:33 PM
BretWhiteley1
Deactivated User
I am using the following script to grab parcel and address information from one layer to fill the attribute table of a newly created feature.

There is no returned error, but the problem I am having is that there seems to be the wrong information stuck in the memory of recordselect function.  No matter where I place a point it gives the same parcel # and address. Or maybe it isn???t actually be performing the IF function properly. 


Sub Address

                Dim rsCurrentXY
                Set rsCurrentXY = Map.Layers("Violations").records
                rsCurrentXY.movelast
                Dim objXYShape
                Set objXYShape = rsCurrentXY.Fields.Shape
                Dim pControls
                Set pControls= Application.Map.selectionlayer.Forms("EDITFORM").Pages(???PAGE1???).Controls
                Dim rsGrid          
                ' Find corresponding map page to the valve point
                Set rsGrid = Map.Layers("ACPA_parcels").records
                rsGrid.movefirst
               
                Do While Not rsGrid.eof
                                If rsGrid.fields.shape.Ispointin(objXYShape) Then
                                                pControls("txtAddress").value = rsGrid.Fields("ADD1").Value
                               
                                                Exit Do
                                End If
                                rsGrid.Movenext
                Loop     
               

                ' Clean Up
                Set rsCurrentXY = Nothing
                Set objXYShape = Nothing
                Set rsGrid = Nothing
End Sub


(I have another subroutine called "PIN" that would do the exact same thing.)
I have them called when their respective edit boxes in the custom form are activated by the inspector.

Thanks for the help,
Robert
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
ThaiTruong
Deactivated User
Attached is a subset of parcels. Thanks so much for taking the time. 

I'll be in the office early tomorrow.


Because you have a large parcels dataset, using IsPointIn() will slow down your data capture process.  it has to loop through all the records inside your pacel layer to find one that contains the point.
So, in your case, I would use FindNearestXY() to find a parcel intersected with the collected point.  This will perform much better on a large datasets like your.

So, here is a new "InitilizeForm" sub for you.  Let me know if it works for you.

Sub InitilizeForm  Dim objLayer  'Get a reference to the first layer  Set objLayer = Application.Map.Layers("Violations")   Dim objEditForm  Set objEditForm = objLayer.forms("EDITFORM")   Dim pControls  Set pControls = ThisEvent.Object.Pages("PAGE1").Controls   Dim dblX, dblY  dblX = Map.PointerX    dblY = Map.PointerY   'Call when adding a new feature  If objEditForm.Mode = 3 Then   pControls("txtAddress").value = ""   pControls("txtPIN").value = ""    'Find Address & PIN # from Parcels Layer   Dim objParcels   Set objParcels = Application.Map.Layers("Parcels")   Dim rsGrid   Set rsGrid = objParcels.Records    Dim Rec   Rec = rsGrid.FindNearestXY(dblX,dblY,0,map.Extent)   If Rec > 0 Then    rsGrid.MoveFirst    rsGrid.move(Rec -1)    pControls("txtAddress").value = rsGrid.Fields("ADDR1").Value    pControls("txtPIN").value = rsGrid.Fields("PIN").Value   End If  End If   Set objLayer = Nothing  Set objEditForm = Nothing  Set pControls = Nothing  Set dblX = Nothing  Set dblY = Nothing  Set objParcels = Nothing  Set rsGrid = Nothing  Set Rec = Nothing End Sub

View solution in original post

0 Kudos
27 Replies
ThaiTruong
Deactivated User
I would place the subroutine under InitializeForm(), when the edit form loads.  And since this will be called each time a newly feature created, you would want it under "objEditForm.Mode = 3"

So, try to call this subroutine from Form: onload event:

'Initialization for form when adding new records:
'  When the user clicks on the map, this sets up the form.
'  Call routine to automatically population some fields.
'  Enable or disable controls base on data collection procedure.

Sub InitializeForm
 Dim pLayer, objEditForm
 Set pLayer = Map.Layers("Violations")  
   Set objEditForm = pLayer.forms("EDITFORM")

 Dim rsCurrentXY
 Set rsCurrentXY = Map.Layers("Violations").records
 rsCurrentXY.movelast

 Dim objXYShape
 Set objXYShape = rsCurrentXY.Fields.Shape

 Dim pControls
 Set pControls= ThisEvent.Object.Pages("PAGE1").Controls

 'Call when adding a new feature
 If objEditForm.Mode = 3 Then
  pControls("txtAddress").value = ""

  ' Find corresponding map page to the valve point
  Set rsGrid = Map.Layers("ACPA_parcels").records
  rsGrid.movefirst
 
  Do While Not rsGrid.eof
   If rsGrid.fields.shape.Ispointin(objXYShape) Then
    pControls("txtAddress").value = rsGrid.Fields("ADD1").Value
         Exit Do
   End If
   rsGrid.Movenext
  Loop 

  ' Clean Up
  Set rsCurrentXY = Nothing
  Set objXYShape = Nothing
  Set rsGrid = Nothing
 End If
 Set pControls = Nothing
 Set objEditForm = Nothing
 Set pLayer = Nothing
End Sub
0 Kudos
BretWhiteley1
Deactivated User
GREAT HELP, ttruong!

However, I am still at the same problem. It is auto filling in with the same attributes no matter where I click. Perhaps the Ispointin() portion is not actually working?


Any ideas?
0 Kudos
BretWhiteley1
Deactivated User
I would place the subroutine under InitializeForm(), when the edit form loads.  And since this will be called each time a newly feature created, you would want it under "objEditForm.Mode = 3"

So, try to call this subroutine from Form: onload event:

'Initialization for form when adding new records:
'  When the user clicks on the map, this sets up the form.
'  Call routine to automatically population some fields.
'  Enable or disable controls base on data collection procedure.

Sub InitializeForm
 Dim pLayer, objEditForm
 Set pLayer = Map.Layers("Violations")  
   Set objEditForm = pLayer.forms("EDITFORM")

 Dim rsCurrentXY
 Set rsCurrentXY = Map.Layers("Violations").records
 rsCurrentXY.movelast

 Dim objXYShape
 Set objXYShape = rsCurrentXY.Fields.Shape

 Dim pControls
 Set pControls= ThisEvent.Object.Pages("PAGE1").Controls

 'Call when adding a new feature
 If objEditForm.Mode = 3 Then
  pControls("txtAddress").value = ""

  ' Find corresponding map page to the valve point
  Set rsGrid = Map.Layers("ACPA_parcels").records
  rsGrid.movefirst
 
  Do While Not rsGrid.eof
   If rsGrid.fields.shape.Ispointin(objXYShape) Then
    pControls("txtAddress").value = rsGrid.Fields("ADD1").Value
         Exit Do
   End If
   rsGrid.Movenext
  Loop 

  ' Clean Up
  Set rsCurrentXY = Nothing
  Set objXYShape = Nothing
  Set rsGrid = Nothing
 End If
 Set pControls = Nothing
 Set objEditForm = Nothing
 Set pLayer = Nothing
End Sub



GREAT HELP, ttruong!

However, I am still at the same problem. It is auto filling in with the same attributes no matter where I click. Perhaps the Ispointin() portion is not actually working?


Any ideas?
0 Kudos
ThaiTruong
Deactivated User
Rob,

Double check the indentation in your VBScript! I just did a quick test and the script returns the right value every time I add a new record (see the attached images)

[ATTACH=CONFIG]17324[/ATTACH][ATTACH=CONFIG]17325[/ATTACH]
0 Kudos
BretWhiteley1
Deactivated User
Rob,

Double check the indentation in your VBScript! I just did a quick test and the script returns the right value every time I add a new record (see the attached images)

[ATTACH=CONFIG]17324[/ATTACH][ATTACH=CONFIG]17325[/ATTACH]



I just did. Everything seems right.  Still get the same address and PIN. It is very strange.

What is really strange about this is that this has worked before (the original script I posted) When I had it calling individual scripts on activating edit boxes.  All of the sudden it stopped filling properly.  Could this mean something is stuck in the memory of arcpad?


Thanks for your help. It is a much better script to have on formloadevent. But I can't get it to fill properly.


I just tried changing which field it is pulling from. It appears that no matter which field I use. The first place I click, those attributes, fill edit form for each subsequent point feature added.  So perhaps the "Clean up" functions are not doing their job.
0 Kudos
ThaiTruong
Deactivated User
That's strange!  Have you tried to create a new ArcPad document, and add the features back in to test?
Attached is my test data...
0 Kudos
BretWhiteley1
Deactivated User
That's strange!  Have you tried to create a new ArcPad document, and add the features back in to test?
Attached is my test data...


Just tried your suggestion. Created a whole new map document. Even updated the parcel layer to a more up-to-date version and it still fills in with the exact same incorrect address and pin. (the same incorrect info from the original map) This information is stuck in the memory somewhere (which is very odd). I am frustrated and I need this to be ready tomorrow at 9am.

I'm going to redo the whole thing.  Fresh check out of all the data and recreate the whole .apl and .vbs.

Unless you have any other ideas.

Thanks for your commitment to helping,
Robert
0 Kudos
BretWhiteley1
Deactivated User
Just tried your suggestion. Created a whole new map document. Even updated the parcel layer to a more up-to-date version and it still fills in with the exact same incorrect address and pin. (the same incorrect info from the original map) This information is stuck in the memory somewhere (which is very odd). I am frustrated and I need this to be ready tomorrow at 9am.

I'm going to redo the whole thing.  Fresh check out of all the data and recreate the whole .apl and .vbs.

Unless you have any other ideas.

Thanks for your commitment to helping,
Robert


This is so strange. I have re-checked out all the data and created a new map document. I even tried it on a different computer. It simply won't work properly. The same address and pin get put in the form every time it opens no matter where i place the point.

Anyone ever have experience like this?

It seems like a problem with the record select. It isn't selecting the attributes from the Ispointin() function is it stuck on some other one.

Any ideas?
0 Kudos
ThaiTruong
Deactivated User
This is so strange. I have re-checked out all the data and created a new map document. I even tried it on a different computer. It simply won't work properly. The same address and pin get put in the form every time it opens no matter where i place the point.

Anyone ever have experience like this?

It seems like a problem with the record select. It isn't selecting the attributes from the Ispointin() function is it stuck on some other one.

Any ideas?


Sorry to hear that!  Did my attached example work for you?
If it's not a big deal, post your 2 features, apl files, and vbs in here.  I'll try to look into it for you.
0 Kudos