You have to build the proj.4 string for the CRS from the parameters given:
+proj=lcc +lat_1=44.883333 +lat_2=45.133333 +lat_0=44.791111 +lon_0=-93.383333 +x_0=152400.000000 +y_0=30480.000000 +a=6378418.9409999996 +b=6357033.3098455509 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs
Note that x_0 and y_0 have to be in meters, while false Easting and Northing from the definition (and the WKT mkennedy added) are in units of the projection (us-ft).
With that, you can load the data as delimited text, with X
set to the itm
column and Y
to the utm
column. If you have not set QGIS to prompt for the CRS, rightclick on the layer -> Set CRS for layer
to get the right alignment:
I'm not sure why they have named the second column utm, the projection has nothing to do with Universal Tramnsverse Mercator.
If I've understood correctly, this code should do what you're after.
Using your input
Distance,Longitude,Latitude
,-77.60483,40.31117
,-77.58167,40.3045
,-77.52883,40.24917
,-77.508,40.14917
,-77.49617,40.13117
I'm producing this output. I've assumed that you want the distances to go forward - i.e. that line 2 has its distance set to the distance to the next point (line 3).The last line is set to 0 as there is no following line to measure to
Distance,Longitude,Latitude
2.0992,-77.6048,40.3112
7.6122,-77.5817,40.3045
11.2593,-77.5288,40.2492
2.2399,-77.5080,40.1492
0.0000,-77.4962,40.1312
Keep your existing code, and append this snippet. The csv library makes it nice and easy to work with CSV files.
I'm also using a deque. This is a FIFO (first in, first out) data structure. I use this to keep a queue of points. Once this has two entries, I compute the distance between the two points, write it out, then discard the oldest point.
import csv
import collections
filein = open("test.csv","rU") # universal newline mode
fileout = open("output.csv","w")
fileout.write("Distance,Longitude,Latitude\n")
csvrdr = csv.reader(filein, delimiter=",")
linecount = 0
# use a deque. once this hits 2 entries, compute the distance
# and then remove the oldest entry
todo = collections.deque()
for line in csvrdr:
if linecount > 0: # skip header
_, longitude, latitude = line # _ means discard
longitude = float(longitude)
latitude = float(latitude)
todo.append((longitude, latitude))
if len(todo)==2:
# got two points, compute distance and remove the oldest
oldlon, oldlat = todo.popleft()
distance = distance_on_unit_sphere(latitude, longitude, oldlat, oldlon)
fileout.write("%2.4f,%2.4f,%2.4f\n" % (distance, oldlon, oldlat))
linecount += 1
# got one entry in deque, spit that out with 0
assert(len(todo)==1)
oldlon, oldlat = todo.popleft()
fileout.write("%2.4f,%2.4f,%2.4f\n" % (0.0, oldlon, oldlat))
fileout.close()
filein.close()
Best Answer
This is quick and dirty. Most of this was adapted from the following website:
http://www.movable-type.co.uk/scripts/latlong.html
I haven't tested this too much but it seemed to work after initial testing. It will return a list of lat, long coordinate pairs along a line at a specified interval. I wrote it in python since I don't know php very well.
I hope this helps. sorry if not. :)
Ok, I added the ability for it to calculate the azimuth for you. I tested with the same location you were using and it turned out perfectly.http://www.darrinward.com/lat-long/?id=705140
I think I have fixed the bugs from the original and it should work (including change the interval). Let me know how it turns out.