Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting an area with a map tool

Status
Not open for further replies.

cdm99

IS-IT--Management
Sep 9, 2005
4
US
From my VFP program, I want to call a mapping service and allow the user to choose either 4 (or more) points of a polygon, or draw a radius from a center point, to define an area based on latitude and longitude. I need the boundaries of the selected area passed back to my program, which will then scan a list of addresses to see if any of them are within the selected area.
Can this be done?

-C Darryl Mattison
Utica NY

 
It's a lot of code needed, map automation, geometry, too much asked for a forum answer. But it's possible. There are pitfalls, I don't know if a mapping service supports selection of an area via boundary points, but for sure you could get coordinates or single points and make an area of that on your own. Can be overcome. If the area is sufficiently large spherical geomety would need to be applied, but you can neglect that.

First of all you'd need to decide for a map service and have an account, most probably not free for commercial use.

If you search the forum you find ways to automate eg google maps. A good search term for it would be geocoding.

Bye, Olaf.



 
I would think this might be quite difficult if you are defining the area as a polygon. But it is much simpler if you are defining it as a circle within a given radius of a fixed point. In that case, as far as I can see, you don't need a mapping service.

If you have the co-ordinates of the fixed point, and those of all the addresses you want to test, then you should be able to do the whole thing with basic trigonometry. Essentially, you calculate the distance between each address and the fixed point, and check to see if that is less than or equal to your radius.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike, thats true from that standpoint it's much simpler to verify an adress to be in a circle, within a distance from the center. But there are also quite simple tests of a point inside a polygon. I don't want to go into details, but the task of course also is simpler with rectangle or triangle areas.

Waht is simple to do is the so called ray casting algorithm described at wikipedia
In short, you test whether you have an odd or even number of intersections with boundary lines, and most often even not need to calculate exact intersection points, the mere number of intersections is all you need and if both x coordinates of a boundary line are higher than the checked point and y coordinate of the chekced point is between y coordinates of a boundary line, that's one intersection.

Sometimes wikipedia is a good starting point even for programming.

Bye, Olaf.
 
Point taken, Olaf.

Reading that Wikipedia aritcle, I realised I knew about the ray casting algorithm, but I had forgotten that I knew (if you see what I mean).

Of course, when dealing with latitude / longitude, you have the added complication of spherical geometry to deal with. It's easier if you are working in a small area, and can use a simple cartesian co-ordinate system, like the national grid system we have in Great Britain (and I think there is a similar system in Germany?).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I was rather pointing Darryl Mattison to that wikipeadia article, but interesting to see another area of experience. As developer you often do things once in a lifetime, which add to a richer profile than you have of yourself.

I don't know about the grid system, in a first approximation longitude and lattitude can be computed, as if they were cartesian coordinates, eg in a city. Calculations of course get worse in the polar regions, but there are little addresses in that area.

In the problem description the worst case might be missing some addresses. If that is a concern, you might simply enlarge the area a bit automatically, to ensure you don't have too few hits. It get's hilarious if you miss an address just because it's the wrong road side and a boundary goes along a street, for example. What you do depends on the exact needs of course.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top