sql - Can STWithin or STContains be used to update columns based on point within polygon relationship? -
sql - Can STWithin or STContains be used to update columns based on point within polygon relationship? -
given next tables:
create table #usgs_24k_topomap_boundaries( [objectid] [int] not null, [area] [numeric](38, 8) null, [perimeter] [numeric](38, 8) null, [qd24k_grsm] [numeric](38, 8) null, [qd24k_gr_1] [numeric](38, 8) null, [quadid] [numeric](38, 8) null, [centlat] [numeric](38, 8) null, [centlong] [numeric](38, 8) null, [name] [nvarchar](35) null, [state] [nvarchar](2) null, [latlong] [nvarchar](9) null, [ohio_index] [nvarchar](8) null, [grid60] [nvarchar](5) null, [reviewed] [int] null, [corrected] [int] null, [verified] [int] null, [globalid] [uniqueidentifier] not null, [shape] [geometry] null)
and
create table #tbl_locations( [objectid] [int] not null, [fcategory] [varchar](16) null, [mapmethod] [varchar](4) null, [herror] [varchar](50) null, [mapsource] [varchar](255) null, [sourcedate] [datetime2](7) null, [editdate] [datetime2](7) null, [notes] [varchar](255) null, [species_community] [varchar](50) null, [location_id] [uniqueidentifier] not null, [site_id] [uniqueidentifier] null, [gis_location_id] [varchar](50) null, [meta_mid] [varchar](50) null, [x_coord] [numeric](38, 8) null, [y_coord] [numeric](38, 8) null, [coord_units] [varchar](50) null, [coord_system] [varchar](50) null, [utm_zone] [varchar](50) null, [accuracy_notes] [varchar](255) null, [unit_code] [varchar](12) null, [loc_name] [varchar](100) null, [loc_type] [varchar](25) null, [updated_date] [varchar](50) null, [loc_notes] [varchar](255) null, [datum] [varchar](5) null, [watershed] [varchar](50) null, [streamname] [varchar](50) null, [nhdreachcode] [varchar](14) null, [topo_name] [varchar](50) null, [trail] [varchar](100) null, [road] [varchar](50) null, [elevation] [numeric](38, 8) null, [lat] [numeric](38, 8) null, [lon] [numeric](38, 8) null, [population_id] [uniqueidentifier] null, [year_] [varchar](4) null, [wgs_dat] [varchar](5) null, [wgs_cs] [varchar](5) null, [county] [varchar](20) null, [state] [varchar](15) null, [isextant] [varchar](3) null, [issenstive] [varchar](3) null, [speciesname] [varchar](125) null, [speciesid] [varchar](50) null, [species_id] [int] null, [shape] [geometry] null)
i'd populate #tbl_locations.topo_name #usgs_24k_topomap_boundaries.name. in other words, trying determine name of topo map point falls within, , programatically write points table. seems simple in theory, tbl_locations contains thousands of points occur in 1 of 36 topo map polygon boundaries.
i've gotten far
select name, loc_name, location_id #usgs_24k_topomap_boundaries a, #tbl_locations b a.shape.stcontains(b.shape)=1
which returns neat table can cross-walk tbl_locations through join, i'm stuck on getting accomplished through single query-update statement, , have many similar point-polygon relationships i'd automate way (e.g watershed, county, state, etc... point occurs in). thanks!
update tbl_locations set topo_name = dbo.qd24k_grsm.name --(select a.name, b.loc_name, b.location_id dbo.tbl_locations inner bring together dbo.qd24k_grsm on tbl_locations.location_id = tbl_locations.location_id (qd24k_grsm.shape.stcontains(tbl_locations.shape) = 1) ;
sql sql-server-2008 spatial
Comments
Post a Comment