on 2015 Apr 24 7:21 PM
We are using SQL Anywhere v12.01.
We have captured a list of GPS coordinates that define a sales territory. I want to determine if a customer's coordinate will be inside that territory. Looking for some direction on how this might possibly be implemented. I am new to spatial data, is that is possible solution and how would I go about converting my list of GPS coordinates to a special data?
Thanks in advance for any guidance.
Brian
Request clarification before answering.
I think we have a pretty solid implementation started for this project.
We are capturing gps coordinates for our territory boundaries for a given territory. We load these into a table using a column of type st_polygon. Here is an example:
insert into sy_territory
(territory_id, territory_name, boundaries)
VALUES
(10, 'Douglas County', NEW ST_Polygon('Polygon ((46.036599 -95.302208, 46.039553 -94.170480, 45.464620 -93.831735,45.374654 -95.168405, 46.036599 -95.302208))'));
We can then compare our customer table which contains a column of type st_point which hold the gps coordinate of the customer against the sy_territory table:
select customer.customer, customer_name, customer.city, customer.location, customer_in_territory = (select customer.location.st_within(boundaries) from sy_territory where territory_id = 10) from customer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just a tip, if you start to see confusing results around the boundaries of your territories, you might want to consider using a locally-relevant planar SRID. You would construct the polygon as the SRID that matches your GPS (e.g. either planar or round-earth WGS-84, depending on how you want the edges to be connected), then transform to your local planar SRID. Make sure your customer location is using the same SRID.
You might also consider using ST_Intersects instead of ST_Within, as ST_Within excludes the boundary. If you use ST_Within and query a point that is also a point of the boundary, you will get 0 back. ST_Intersects also works directly on the round-Earth SRS, so you could just use 4326 if you want. ST_Intersects may, however, show a customer being in multiple territories if your boundary lines intersect/overlap.
User | Count |
---|---|
87 | |
10 | |
9 | |
8 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.