繁体   English   中英

SQL 服务器指向多边形问题

[英]SQL Server Point to polygon issue

所以我有一个形状文件,这个查询可以通过抓取一堆纬度和经度来工作

DECLARE 
    @GeoUnitBoundaries GEOGRAPHY 
    ,@State char(2)
    ,@GeoUnitControlKey int
    
    
DECLARE contact_cursor CURSOR FOR
 SELECT id, geom
 FROM [GIS].[dbo].[oh_2020_state_upper_2021-09-16_2031-06-30]
 where geom is not null

  
OPEN contact_cursor

FETCH NEXT FROM contact_cursor
INTO @geounitboundaries,@GeoUnitControlKey


WHILE @@FETCH_STATUS = 0
BEGIN


    SELECT 
        @GeoUnitBoundaries = geom
        ,@GeoUnitControlKey = ID  
    FROM [GIS].[dbo].[oh_2020_state_upper_2021-09-16_2031-06-30]
    WHERE ID = @GeoUnitControlKey and geom is not null
    
    
    update   [work_old].[dbo].[oh_jk] 
    set sd_new = @GeoUnitControlKey
    from   [work_old].[dbo].[oh_jk] a
    where geography::STGeomFromText( 'POINT('+RegistrationAddressLongitude+' '+RegistrationAddressLatitude+')',4326 ).STIntersects(@GeoUnitBoundaries) = 1
    and sd_new is null  and RegistrationAddressLongitude <> ' ' and RegistrationAddressLatitude <> ' '

    raiserror(@geounitcontrolkey,0,1) with nowait


   FETCH NEXT FROM contact_cursor
   INTO @geounitboundaries,@GeoUnitControlKey
END


CLOSE contact_cursor
DEALLOCATE contact_cursor
GO

我知道我的问题是传入的形状文件数据类型是几何

我必须假设它们是一种更简单的方法,可以从形状文件文件中加入列,并根据点是否位于形状内将其添加到现有表中。 提前道歉,我像8年前一样把这个放在一起。

一个简单的加入更新看起来应该可以工作

UPDATE jk
SET sd_new = su.ID
from [work_old].[dbo].[oh_jk] jk
JOIN [GIS].[dbo].[oh_2020_state_upper_2021-09-16_2031-06-30] su
WHERE geography::STGeomFromText(
    'POINT(' + RegistrationAddressLongitude + ' ' + RegistrationAddressLatitude + ')',
     4326 ).STIntersects(su.geom) = 1
  AND jk.sd_new IS NULL
  AND jk.RegistrationAddressLongitude <> ' '
  AND jk.RegistrationAddressLatitude <> ' '
  AND su.geom is not null;

对于大型数据集,预先计算geography值并在其上创建索引可能会更高效。

想出来了,很容易。 使用 SQLServerSptialTools 你可以这样做:

SET GEOjk = dbo.MakeValidGeographyFromGeometry(GEOM)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM