Thursday, October 1, 2009

Calculate Lat/Long Values in ArcMap

Yet again, I had a difficult time finding sufficient information on calculating latitude and longitude values for a point shapefile. I've only encountered one or two situations in the past few years where I worked with a coverage that was missing these data, though it's still a basic and important technique that should be addressed a bit better.

It turns out that (at least) ArcMap 9.2 provides a pretty simple method to quickly calculate a number of geographic coordinates. A few things are important to consider though:

Converting Polygon to Point data:
Unless you're interested in the locations of polygon boundaries (shorelines, property boundaries, etc. - in which case you will convert the polygon boundaries to nodes), you will want to create a point coverage to represent centroids. Be sure to choose whether that center location will be the true center, or be preserved within the bounds of the polygon:

  • Show ArcToolbox in ArcMap (or ArcCatalog)
  • Open the Feature to Point tool
    (Under Data Management Tools :: Features :: Feature to Point)
  • Press Show Help to read more about the tool
  • Select a polygon or line feature to use as in input featre
  • Set an output location and name for the resulting feature class
  • Check the "Inside" check box to calculate a centroid within the boundary of a given feature (i.e. a "bent" polygon similar to the shape of Florida can have a centroid in the Gulf of Mexico if "Inside" is not selected)





There is insufficient information on the internets about this process works. There is a simple and automated calculator built into atribute table field calculations. To make this work properly in this situation (calculating geographic latitude/longitude coordinates) the coordinate system must be set to a geographic coordinate system, rather than a projected coordinate system.

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.

See also:

Angular Unit Conversion (convert between DD, DMS, and radians)
How To: Populate x, y, or z point data fields of an attribute table

How To: Calculate Latitude and Longitude values using the Field Calculator

13 comments:

Anonymous said...

thanks a f-n million for posting this! it really saved my ass at work today, since I should know how to do this kinda thing but clearly, I don't. until now!

keep up the good work!
/ Martin, Sweden

Anonymous said...

thanks a lot man -- could not find this info anywhere!!!

Anonymous said...

Saweeet! I cant believe my luck, thx, this should be the simplest task...

Anonymous said...

This is totally brilliant, thanks so much :D :D :D

Anonymous said...

Thank you for posting this!! It saved me from a whole lot of trouble :)

Anonymous said...

same as other commenters; this post was super helpful. Thank you for doing ersi's job for them!

Anonymous said...

Thanks for posting, everyone else had these complicated methods that don't work!

Seed of Abraham said...

Thanks so much for posting this!!!!!! could not find it anywhere. I just did a task that has been bordering me for so long. Once more thanks.

Anonymous said...

Thanks, this was really helpful.

cloudbeginners said...

cloudbeginners
aws inspector
openshift vs kubernetes
azure data lake
arm templates
azure traffic manager
azure bastion

Techystick said...

luxurious property of jaipur
kurti sharara set
traditional kurtis for women
best coaching classes for class 10 in gurgaon
azure expressroute
azure application gateway
azure resource group
azure blueprints
azure firewall

fairbet7 said...

Fairbet7
Fairbet7 id

aryanawslessions said...

Optimize your operations with our comprehensive Linux server management services. From setup to maintenance, trust us for reliable solutions.