Select to view content in your preferred language

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

3717
27
Jump to solution
08-28-2012 12:33 PM
BretWhiteley1
New Contributor
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
27 Replies
BretWhiteley1
New Contributor
I'm glad that it works for you, and hope that you don't find my house to be in violation of irrigation codes! 🙂

BTW, here's an example on how IsPointIn() works:

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 pPt
 Set pPt = Application.CreateAppObject("Point")

 pPt.X = Map.PointerX
 pPt.Y = 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

  rsGrid.movefirst
  Do While Not rsGrid.eof
   If rsGrid.Fields.Shape.Ispointin(pPt) Then
    pControls("txtAddress").value = rsGrid.Fields("ADDR1").Value
    pControls("txtPIN").value = rsGrid.Fields("PIN").Value
    Exit Do
   End If
   rsGrid.Movenext
  Loop

 End If

 Set objLayer = Nothing
 Set objEditForm = Nothing
 Set pControls = Nothing
 Set pPt = Nothing
 Set objParcels = Nothing
 Set rsGrid = Nothing
End Sub



Thanks again! I currently have the Lat/Lon fields filled in using GPS.Latitude and GPS.Longitude. However, if they do not have a gps signal (such as in the office) and they want to add a violation based on a complaint (people call and say "soandso is watering when they are not supposed to" I would like these fields to be filled in based on where they clicked on the map.

Is it possible to grab Lat/Lon from the map and not the GPS unit?

I know about Map.PointerX/Y, but those give me state plane coordinates and I want DD. Is there a simple conversion scripts perhaps?



Thanks
0 Kudos
ThaiTruong
Occasional Contributor II
Thanks again! I currently have the Lat/Lon fields filled in using GPS.Latitude and GPS.Longitude. However, if they do not have a gps signal (such as in the office) and they want to add a violation based on a complaint (people call and say "soandso is watering when they are not supposed to" I would like these fields to be filled in based on where they clicked on the map.

Is it possible to grab Lat/Lon from the map and not the GPS unit?

I know about Map.PointerX/Y, but those give me state plane coordinates and I want DD. Is there a simple conversion scripts perhaps?

Thanks


First, you need to define a coordinate system and project your point to this projection, then you can get X & Y properties.

...
 Dim pPt
 Set pPt = Application.CreateAppObject("Point")

 pPt.X = Map.PointerX
 pPt.Y = Map.PointerY

 Dim pLLCS
 'define a coordinate system
 Set pLLCS = Application.CreateAppObject( "CoordSys" )
 pLLCS.Import("C:\Program Files (x86)\ArcGIS\ArcPad10.0\Coordinate System\Geographic Coordinate Systems\World\WGS 1984.prj")

 Dim pDstPoint
 Set pDstPoint = pLLCS.Project(pPt)

 msgbox("the DD coordinate is " & pDstPoint.X & ", " & pDstPoint.Y)
...
0 Kudos
BretWhiteley1
New Contributor
Brilliant! It works flawlessly.  Thank you so very much for your dedication to this community.


I am running into a new problem now!

When my field technician reopens a feature for editing (such as adding information concerning when he mailed a written warning, follow up inspection date, etc) The address and pin fields are changing to erroneous values.  Is there a way to make the script run ONLY WHEN NEW FEATURES ARE CREATED and not just when the edit form loads? or is there a way to LOCK the fields once they have been filled in once? or can I make the script not fill in the attributes if there is already text in the control box?

Thanks in advance!!!
0 Kudos
ThaiTruong
Occasional Contributor II
I am running into a new problem now!

When my field technician reopens a feature for editing (such as adding information concerning when he mailed a written warning, follow up inspection date, etc) The address and pin fields are changing to erroneous values.  Is there a way to make the script run ONLY WHEN NEW FEATURES ARE CREATED and not just when the edit form loads? or is there a way to LOCK the fields once they have been filled in once? or can I make the script not fill in the attributes if there is already text in the control box?

Thanks in advance!!!


I already replied your PM, here it is, again...

Sub InitializeForm
  'Do any form initialization in this sub
  If objEditForm.Mode = 3 Then
    'Things to do when create a new feature go here
  End If
  If objEditForm.Mode = 2 Then
    'Things to do when edit an existing feature go here
  End If
End Sub
0 Kudos
SuzanneRoussie
New Contributor
I've been following this thread because I was trying to do something similiar and do not have any programming experience. Thank you for assiting in making a challenge less difficult for me.  I was able to modify this code to accomplish what I needed to but found that I need to place my parcels shapefile into the same directory with the shapefile that I am modifying. Normally all my basemap data is located in other directories to keep them separate from data that is being collected or modified, especially since there is a lot of basemap data.  I tried modifying the path to the location where the parcels reside but that resulted in an error, source object not found.  My question, how do I modify the script to point to my directory where my parcels are located, or is that not possible?

Parcels reside in C:\GIS\Shapefiles\Parcels\Polygons\Parcels.shp

The line below is the one that currently works as long as the parcels reside in the same directory:

Set objParcels = Application.Map.Layers("Parcels")

Thanks.
0 Kudos
MatthewMcLamb
New Contributor
A lot of good info here. I have a quick question along the same idea. What would it take to return the address number from parcels on each side of the parcel clicked on? For example, 123 is to the left of the clicked parcel and 127 is to the right of the clicked parcel.

Thanks and God bless!
0 Kudos
ThaiTruong
Occasional Contributor II
A lot of good info here. I have a quick question along the same idea. What would it take to return the address number from parcels on each side of the parcel clicked on? For example, 123 is to the left of the clicked parcel and 127 is to the right of the clicked parcel.

Thanks and God bless!


It's tough to define left and right adjacent parcels in ArcPad due to the parcel's orientation and limited ArcPad Object Model.

I think the best way to get this works is to create a custom multiple polygon selection tool.  Have your user select the two adjacent parcels, so you can get the address numbers from the selected records.
0 Kudos
ThaiTruong
Occasional Contributor II
I've been following this thread because I was trying to do something similiar and do not have any programming experience. Thank you for assiting in making a challenge less difficult for me.  I was able to modify this code to accomplish what I needed to but found that I need to place my parcels shapefile into the same directory with the shapefile that I am modifying. Normally all my basemap data is located in other directories to keep them separate from data that is being collected or modified, especially since there is a lot of basemap data.  I tried modifying the path to the location where the parcels reside but that resulted in an error, source object not found.  My question, how do I modify the script to point to my directory where my parcels are located, or is that not possible?

Parcels reside in C:\GIS\Shapefiles\Parcels\Polygons\Parcels.shp

The line below is the one that currently works as long as the parcels reside in the same directory:

Set objParcels = Application.Map.Layers("Parcels")

Thanks.


Hi there Suzanne,

It gives you an error because the layer you specified is not on your map.  Try to add the Parcels shapefile from your basemap directory to your map document.  You can turn off the display for this layer if you want.
0 Kudos