Thursday, July 2, 2015

point shapefile add lat long field

http://justinberke.blogspot.com/2009/10/calculate-latlong-values-in-arcmap.html


Calculating Lat/Long Coordinates:
  • Add a point coverage to a project
  • Change the data frame to a geographic coordinate system
    • Right click on the data frame heading in the table of contents pane and choose Properties
    • Navigate to the Coordinate System tab
    • Expand the Predefined branch
    • Expand the Geographic Coordinate Systems branch
    • Expand the North America branch
    • Choose North American 1983 HARN and click OK
    • Choose Yes if prompted with a coordinate system warning
  • Open the layer's Attribute Table and add the following fields /types (LONG_DD is indeed string 3, not a typo)
Field Name 
LATITUDE
LONGITUDE
LAT_DD
LAT_MM
LAT_SS
LONG_DD
LONG_MM
LONG_SS
DATUM
Type/Length
Text (string), 20
Text, 20
Text, 2
Text, 2
Text, 9
Text, 3
Text, 2
Text, 9
Text, 25
  • Go ahead and calculate "North American 1983 HARN" (or whatever coordinate system you used) in the DATUM field.  Whomever uses this data in the future will need to the method used to calculate the units
  • Now begin to calculate the units.  Right click the LATITUDE field and select Calculate Geometry
    • Set the Property to "Select Y Coordinate of Point" (Latitude = y, and Longitude = x)
! Note that Latitude = y and Longitude = x. Usually you'll ask for "x/y coordinates" in geometry class, however surveyors ask for "a northing and an easting" - which flips the order of the x and y values around.
    • Select "Use coordinate system of the data frame" to use the geographic coordinate system. After this, the Units will change from various length units of measure (meters, feet, etc.) to a number of DMS choices
    • Select "Packed DMS Format (+/- DDD.MMSSssssss")" and hit OK
  • Repeat this for LONGITUDE with "Select X Coordinate of Point"
  • Use the Field Calculator to populate the remaining fields using the following formulas
    • LAT_DD: left([LATITUDE], 2)
    • LAT_MM: mid([LATITUDE], 4, 2)
    • LAT_SS: right([LATITUDE], 8)/1000000
    • LONG_DD: left([LONGITUDE], 3)
    • LONG_MM: mid([LONGITUDE], 5, 2)
    • LONG_SS: right([LONGITUDE], 8)/1000000
  • Finally, be sure to Calculate Geometry again on the LATITUDE and LONGITUDE fields (Using the coordinate system of the data frame) but set the units to Decimal Degrees.  Until this is finished, the values look like decimal degrees, but if these coordinates are projected, they will be incorrect - perhaps by a long way.  A good trick is to see if any values after the decimal are greater than x.599999.  If there are any values between x.6 and x.9, those are indeed decimal degrees.
  • There are a few other formats that may be more appropriate for individual projects. Some custom utilities will require lat/long processing fields to match, so be careful with the LAT_DD/LONG_DD fields; thus DMS fields may need to be converted to another data type.  Further, field types of Double and Short Integer may be more appropriate for your database.

    Using VBA Script Code in the Field Calculator, a field of type double can be populated with latitude or longitude values.

    1. Add a field of type double to the attribute table to store either latitude or longitude values.
    2. Start an edit session.
    3. Open the attribute table.
    4. Right-click the field and select Calculate Values.
    5. Check the 'Advanced' check box.
    6. Paste the following code into the 'Pre-Logic VBA Code' box:

      Dim Output As Double 
      Dim pPoint As IPoint 
      Set pPoint = [Shape] 
      Output = pPoint.X


        The above code is for calculating Longitude. X should be changed to Y to calculate Latitude values.
    7. Type 'Output' into the lower text box. 
    8. Click OK.

No comments: