Lasso Soft Inc. > Home

[lp_math_GPSradius]

Linklp_math_GPSradius
AuthorBil Corry
CategoryMath
Version8.x
LicensePublic Domain
Posted19 Feb 2006
Updated19 Feb 2006
More by this author...

Description

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]

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']

[var:'radius' = (lp_math_gpsRadius: 32.82213, -116.88550, 5, 'mi')] 5 mile radius around El Cajon, CA (32.82213, -116.88550)
Low Point: ([$radius->lat_low], [$radius->lon_low])
High Point: ([$radius->lat_high], [$radius->lon_high])


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

[lp_math_GPSdistance: 32.82213, -116.88550, $radius->lat_low, -116.88550, 'mi']
[lp_math_GPSdistance: 32.82213, -116.88550, $radius->lat_high, -116.88550, 'mi']
[lp_math_GPSdistance: 32.82213, -116.88550, 32.82213, $radius->lon_low, 'mi']
[lp_math_GPSdistance: 32.82213, -116.88550, 32.82213, $radius->lon_high, 'mi']
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.

[

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

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft