[lp_math_GPSradius]

Description

Link: [lp_math_GPSradius]
Author: Bil Corry
Category: Math
Version: 8.x
License: Public Domain
Posted: Feb. 19, 2006
Updated: Jan. 01, 0001
More by this author...
Given a center point and radius, this type will return the upper-leftmost and lower-rightmost coordinates, forming a square around the center point.  A radius can be achieved by searching for all entities that fall within the square, then individually checking each one with [lp_math_GPSdistance] to see if it falls within the radius.

Unit Choices:
   km     = kilometers
   m     = meters
   ft     = feet
   mi     = miles
   nm     = nautical miles

Requires [lp_math_degtorad] [lp_decimal_precisionset]

Parameters

-lat decimal, required Latitude in signed decimal degrees.
-lon decimal, required Longitude in signed decimal degrees.
-radius decimal, required Size of radius.
-units string, optional Radius units. Default is kilometers.

Sample Usage

Zip codes from "zip_loc.txt.gz" located here under "Optional Data Files":
    http://www.cryptnet.net/fsp/zipdy/

From El Cajon (92021) to San Diego (92101) in miles: [lp_math_GPSdistance: 32.82213, -116.88550, 32.72110, -117.17436, 'mi']<br>
<br>

[var:'radius' = (lp_math_gpsRadius: 32.82213, -116.88550, 5, 'mi')]
5 mile radius around El Cajon, CA (32.82213, -116.88550) <br>
Low Point: ([$radius->lat_low], [$radius->lon_low])<br>
High Point: ([$radius->lat_high], [$radius->lon_high])<br>
<br><br>
Radius Intersections<br>
(all four values below should be close to 5 -- this is a double-check that our radius search is returning correct coordinates)<br>
<br>
[lp_math_GPSdistance: 32.82213, -116.88550, $radius->lat_low, -116.88550, 'mi']<br>
[lp_math_GPSdistance: 32.82213, -116.88550, $radius->lat_high, -116.88550, 'mi']<br>
[lp_math_GPSdistance: 32.82213, -116.88550, 32.82213, $radius->lon_low, 'mi']<br>
[lp_math_GPSdistance: 32.82213, -116.88550, 32.82213, $radius->lon_high, 'mi']<br>


returns:

From El Cajon (92021) to San Diego (92101) in miles: 18.163618834130652

5 mile radius around El Cajon, CA (32.82213, -116.88550)
Low Point: (32.749716606418723, -116.97166976690821)
High Point: (32.89454339358128, -116.79933023309178)


Radius Intersections
(all four values below should be close to 5 -- this is a double-check that our radius search is returning correct coordinates)

4.999998778467452
4.999998778467452
4.999998778467452
4.999998778467452
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
[

define_type:'lp_math_GPSradius',
	-description='Returns the high/low lat and lon coordinates via member tags given a center point and radius.',
	-prototype;
/*
	Given a center point and radius, this type will return the upper-leftmost and lower-rightmost coordinates,
	forming a square around the center point.  A radius can be achieved by searching for all entities that
	fall within the square, then individually checking each one to see if it falls within the radius.
	

	Default is metric kilometers.
	
		" Every time I return to the US from a country that uses the metric system,
		  I wonder what went wrong here. Why do we still use miles and pounds and quarts?
		  The old English system is arbitrary and inefficient, and it cuts us off from the rest
		  of the world?except for those powerhouses of trade and science Liberia and Myanmar,
		  the only remaining metric holdouts. Other than the US, every other country has seen
		  the light.  "
		 
		 from: http://www.robertsilvey.com/notes/2005/04/inching_along.html


	Unit Choices:
		km 	= kilometers
		m 	= meters
		ft 	= feet
		mi 	= miles
		nm 	= nautical miles
	
 */


	// define locals
	local:'lat_low'= decimal;
	local:'lat_high'= decimal;
	local:'lon_low'= decimal;
	local:'lon_high'= decimal;

	define_tag:'onCreate',
		-required='lat',	// as signed decimal degrees
		-required='lon',	// as signed decimal degrees
		-required='radius',
		-optional='units',-copy; // default is kilometers

		// get units
		select: (string:(local:'units'));
			case: 'ft'; // feet
				local:'units'=6076.00000;
			case: 'nm'; // nautical miles
				local:'units'=1.00000;
			case: 'mi'; // U.S. miles
				local:'units'=1.15080;
			case: 'm'; // meters
				local:'units'=1852.00000;
			case; // default kilometers
				local:'units'=1.85200;
		/select;

		// get radius units
		local:'lat_units'= decimal:((decimal:#radius) / (60.0 * #units));
		local:'lon_units'= decimal:(#lat_units / (math_cos:(lp_math_degtorad:(decimal:#lat))));

		// calc "radius"
		self->'lat_low' = decimal: (#lat - #lat_units);
		self->'lat_high'= decimal: (#lat + #lat_units);
		self->'lon_low' = decimal: (#lon - #lon_units);
		self->'lon_high'= decimal: (#lon + #lon_units);

	/define_tag;


	// ----- member tags -----

	define_tag:'lat_low';
		return: (lp_decimal_precisionset: (self->'lat_low'));
	/define_tag;

	define_tag:'lat_high';
		return: (lp_decimal_precisionset: (self->'lat_high'));
	/define_tag;

	define_tag:'lon_low';
		return: (lp_decimal_precisionset: (self->'lon_low'));
	/define_tag;

	define_tag:'lon_high';
		return: (lp_decimal_precisionset: (self->'lon_high'));
	/define_tag;


/define_type;

]

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular