Geography

 -- ============================================= 
-- Author:  cao you gang 
-- Create date: <Create Date,,> 
-- Description: <Description,,> 
-- ============================================= 
CREATE PROCEDURE [dbo].[P_FSRS_ReportDetail_SearchByLatLon]  
      @p_caseid bigint, 
   @p_latitude decimal(30,20), 
   @p_longitude decimal(30,20), 
   @p_radius float 
AS 
BEGIN 
 DECLARE @centre geography  
  SET @centre = geography::STGeomFromText('POINT('+CAST(@p_longitude AS NVARCHAR(40))+' '+CAST(@p_latitude AS NVARCHAR(40))+')', 4326); 
 --SET @centre = geography::STGeomFromText('POINT('+CONVERT(nchar,@p_latitude)+' '+CONVERT(nchar,@p_longitude)+')', 4757); 
  
    SELECT  
      t.ID, 
      t.CaseID, 
      t.Title, 
      t.Remark, 
      t.[Length], 
      t.Depth, 
      t.Assignee, 
      t.Zone, 
      (select c.Code from T_FSRS_Code c where c.ID= t.PubCategoryID) as PubCategoryID, 
      -- t.PubCategoryID, 
     -- t.PublicCategoryID, 
      t.Lanes_Affected, 
      t.Compound_Affected, 
      t.House_Affected, 
      t.Flood_Status, 
      t.Media_Around, 
      (select top 1 s.Code from T_PFAS_Station s where s.ID=t.StationID and s.Deleted=0) as StationID, 
      t.Action_Taken, 
      CONVERT( decimal(30,20), t.Latitude) as Latitude, 
      CONVERT( decimal(30,20), t.Longitude) as Longitude, 
      CONVERT( decimal(30,20), t.Latitude) as LatitudeDeci,     
      CONVERT( decimal(30,20), t.Longitude) as LongitudeDeci,       
      t.[Primary], 
      t.Map_Status, 
      t.[Status], 
      t.Radius, 
      t.ReporterID, 
      t.Deleted, 
      t.Created_By, 
      t.Created_Time, 
      t.Last_Updated_By, 
      t.Last_Updated_Time 
    FROM T_FSRS_ReportDetail t 
 where t.Deleted = 0 
 and( t.[Primary] = 0 or t.[Primary] is  NULL) 
 and t.CaseID = @p_caseid 
 and LOWER(t.Map_Status) = LOWER('VFD') 
 and @centre.STDistance(geography::STGeomFromText('POINT('+CAST(t.Longitude AS NVARCHAR(40))+' '+CAST(t.Latitude AS NVARCHAR(40))+')', 4326)) <= @p_radius 
  
 --and @centre.STDistance(geography::STGeomFromText('POINT('+CONVERT(nchar,t.Latitude)+' '+CONVERT(nchar,t.Longitude)+')', 4757)) <= @p_radius 
 union 
     SELECT  
      t.ID, 
      t.CaseID, 
      t.Title, 
      t.Remark, 
      t.[Length], 
      t.Depth, 
      t.Assignee, 
      t.Zone, 
        (select c.Code from T_FSRS_Code c where c.ID= t.PubCategoryID) as PubCategoryID, 
      
      t.Lanes_Affected, 
      t.Compound_Affected, 
      t.House_Affected, 
      t.Flood_Status, 
      t.Media_Around, 
       (select top 1 s.Code from T_PFAS_Station s where s.ID=t.StationID and s.Deleted=0) as StationID, 
      t.Action_Taken, 
      CONVERT( decimal(30,20), t.Latitude) as Latitude, 
      CONVERT( decimal(30,20), t.Longitude) as Longitude, 
      CONVERT( decimal(30,20), t.Latitude) as LatitudeDeci,     
      CONVERT( decimal(30,20), t.Longitude) as LongitudeDeci,       
      t.[Primary], 
      t.Map_Status, 
      t.[Status], 
      t.Radius, 
      t.ReporterID, 
      t.Deleted, 
      t.Created_By, 
      t.Created_Time, 
      t.Last_Updated_By, 
      t.Last_Updated_Time 
    FROM T_FSRS_ReportDetail t 
 where t.Deleted = 0 
 and( t.[Primary] = 0 or t.[Primary] is  NULL) 
 and  t.CaseID = @p_caseid 
 and  CONVERT(decimal(30,20), t.Latitude) =  @p_latitude 
 and  CONVERT(decimal(30,20),  t.Longitude) = @p_longitude 
 and  LOWER(t.Map_Status) = LOWER('VFD') 
   order by t.Last_Updated_Time desc   
 print(@p_latitude) 
 print(@p_longitude) 
END 

///

 

 

ALTER PROCEDURE [dbo].[P_FSRS_Region_GetAreaByLanLon]
   @p_latitude decimal(30,20),
   @p_longitude decimal(30,20),
   @p_areaName varchar(50) OUTPUT
AS
BEGIN
 
 DECLARE @g geometry;
 print('POINT('+CAST(@p_longitude AS VARCHAR(40))+' '+CAST(@p_latitude AS VARCHAR(40))+')');
 SET @g =  'POINT('+CAST(@p_longitude AS VARCHAR(40))+' '+CAST(@p_latitude AS VARCHAR(40))+')';

 set  @p_areaName =(select r.name from T_FSRS_Region r where r.area.STIntersects(@g)=1)
 --select @p_areaName
END

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值