1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
/* Latitude / Longitude to UTM conversion */
#include <stdio.h>
#include <stdlib.h>
#include "LatLong-UTMconversion.h"
static void usage();
void main (int argc, char *argv[])
{
double easting;
double northing;
double lat, lon;
char zone[8];
if (argc != 3) usage();
lat = atof(argv[1]);
if (lat < -90 || lat > 90) {
fprintf (stderr, "Latitude value is out of range.\n\n");
usage();
}
lon = atof(argv[2]);
if (lon < -180 || lon > 180) {
fprintf (stderr, "Longitude value is out of range.\n\n");
usage();
}
LLtoUTM (WSG84, lat, lon, &northing, &easting, zone);
printf ("zone = %s, easting = %.0f, northing = %.0f\n", zone, easting, northing);
}
static void usage (void)
{
fprintf (stderr, "Latitude / Longitude to UTM conversion\n");
fprintf (stderr, "\n");
fprintf (stderr, "Usage:\n");
fprintf (stderr, "\tll2utm latitude longitude\n");
fprintf (stderr, "\n");
fprintf (stderr, "where,\n");
fprintf (stderr, "\tLatitude and longitude are in decimal degrees.\n");
fprintf (stderr, "\t Use negative for south or west.\n");
fprintf (stderr, "\n");
fprintf (stderr, "Example:\n");
fprintf (stderr, "\tll2utm 42.662139 -71.365553\n");
exit (1);
}
|