0

I'm working on a problem, where I have to map indoor Cartesian coordinates to a certain zone.

The problem has numerous zones lets say zone1, zone 2, zone 3 and zone 4 with coordinates (x1,y1), (x2,y2) (x3,y3) and (x4,y4) respectively. I have a huge data set of visitors who are coming to visit the area and have there individual coordinates. The task is to map the visitor to a zone. A visitor is in that zone if he is within 10 mtrs of radius of a specific zone.

So, visitor A(a1,b1) is in Zone A(x1,y1) if visitors' coordinates are in radius of 10 mtrs from x1,y1.

So, a few questions:

  1. which data type to be used for storing coordinates. Will float work. I saw a discussion going for spatial coordinates, not sure what does it mean.

  2. Also, when I do the mapping, do I need to write the code in ETL? or do I need to use any other programming lang

  3. Lastly, how to code the above problem

sqluser
  • 5,502
  • 7
  • 36
  • 50
user4943236
  • 5,914
  • 11
  • 27
  • 40
  • http://stackoverflow.com/questions/29820927/given-a-users-location-select-rows-that-include-that-user-in-their-radius/29822023#29822023 – pala_ May 27 '15 at 06:42

1 Answers1

1

Here's how I'd do it. Let's assume that you have a zone table with one row per zone. I would define it like this:

create table dbo.Zones (
   ZoneID int identity not null,
   constraint [PK_Zone] primary key clustered (ZoneID),
   ZoneGeometry geometry
);

You'd populate it like so:

    insert into dbo.Zones 
      (ZoneGeometry)
    values 
      (geometry::STGeomFromText('POLYGON((1 1, 1 2, 2 2, 2 1, 1 1))', 0));

Similarly for your visitors:

create table dbo.Visitors (
   VisitorID int identity not null,
      constraint [PK_Visitors] primary key clustered (VisitorID),
   Location geometry
);

insert into dbo.Visitors 
   (Location)
values
   (geometry::STPointFromText('POINT (1.5 1)', 0));

Then to find which zone each visitor is in:

select *
from dbo.Visitors as v
left join dbo.Zones as z
   on z.ZoneGeometry.STBuffer(10).STContains(v.Location) = 1;
Ben Thul
  • 31,080
  • 4
  • 45
  • 68
  • Thanks Ben for your reply. I'm working first time on spatial data so please bear with me if I ask a few basic questions. – user4943236 May 28 '15 at 07:29
  • I'm working first time on spatial data so please bear with me if I ask a few basic questions. Firstly, for implementing your code, what should be the units of my coordinates. I only have the data provided, and not aware which reference system has been used to convert it from lattitude or longitude. – user4943236 May 28 '15 at 07:35
  • and secondly, how do I create polygon from from set of coordinates. Lets say, I have been given coordinate for a zone is (830,450). Actually, zone is a signal emitting device here. so, if any visitor is within 10mtrs of the zone coordinates, the visitor is defined in that zone – user4943236 May 28 '15 at 07:49
  • I can't answer what units you should use if you can't answer that yourself. That is, you need to know what the coordinates that you have represent so that you're doing the right thing. My assumption was that the unit in your coordinate system was a meter and the code I provided reflects that. And as for adding the polygons, it sounds like your zones are defined not as polygons, but rather as circles centered at a given point. If that's the case, store the zone as the point and use the `STBuffer()` method (shown above) to define the circle around it. – Ben Thul May 28 '15 at 16:08
  • Thanks Ben for your help – user4943236 May 29 '15 at 06:24