spatial index performance guidelines

Sean Turcott 0 Reputation points
2024-12-28T17:29:11.23+00:00

I created a table to be used by QGIS (opensource GIS software) to display point locations. Since I have no control over how the application queries the table what are some performance guidelines for setting up spatial tables? Here's what I have so far (it takes 5 or more seconds to render the map layer of about 20,000 locations in QGIS every pan/zoom):

CREATE TABLE [GEO_PROD].[dbo].[Well_Version] (

well_guid               INT DEFAULT NEXT VALUE FOR seq_Wellguid PRIMARY KEY,  -- Unique DB Identifier

source                  VARCHAR(50) NOT NULL,  -- Data Source

source_well_id          VARCHAR(50) NOT NULL,  -- Unique source Identifier

well_government_id      VARCHAR(50) NOT NULL,    -- API

well_name               VARCHAR(255) NOT NULL,   -- Well name

well_alias              VARCHAR(255),           -- Alternate names

operator_id             VARCHAR(50),            -- Operator identifier (foreign key to Operator table)

surface_latitude        DECIMAL(10, 6),         -- Latitude of the well SH

surface_longitude       DECIMAL(10, 6),         -- Longitude of the well SH

surface_location        GEOGRAPHY,               -- SHL spatial column

bottom_latitude         DECIMAL(10, 8),         -- Latitude of the well BH

bottom_longitude        DECIMAL(10, 8),         -- Longitude of the well BH

bottom_location         GEOGRAPHY,               -- BHL spatial column

geo_datum               VARCHAR(50),            -- Surface location description

geo_datum_epsg_code     VARCHAR(50),            -- EPSG Code needed for spatial location

state_code              CHAR(2),                -- ISO country code

county_code             CHAR(3),                -- ISO country code

well_class              VARCHAR(50),            -- Type of well (oil, gas, etc.)

well_status             VARCHAR(50),            -- current operational state of a well (Active, Completed, Shut-in, Abandoned)

well_type               VARCHAR(50),            -- (Exploratory, Development, Injection, Service)

elev_reference          VARCHAR(50),            -- (Kelly Bushing, Rotary Table, etc.)

elev_datum              VARCHAR(50),            -- (Mean Sea Level, Ground, etc.)

elevation               DECIMAL(10, 6),         -- height above elev_datum

elev_uom                VARCHAR(50),            -- (FT, M, etc.)

spud_date               DATE,                   -- Spud date

effective_date          DATE,              		-- Effective date

well_status_date        DATE,            		-- well status date

completion_date         DATE,                   -- Completion date

permit_date             DATE,                 	-- completion date

measured_depth          DECIMAL(10, 2),         -- Measured depth in meters

true_vertical_depth     DECIMAL(10, 2),         -- True vertical depth in meters

trajectory              VARCHAR(50),            -- Trajectory (vertical, horizontal, etc.)

lease_id                VARCHAR(50),            -- Lease or block information

regulatory_authority    VARCHAR(255),           -- Regulatory authority overseeing the well

comments                VARCHAR(500),           -- Comments

created_date            DATE, 					-- Record creation date

updated_date            ROWVERSION 				-- Record last updated date

);

/* For QGIS performance */

CREATE TABLE [GEO_PROD].[dbo].[geometry_columns] (

   [f_table_catalog]   [varchar](128) NOT NULL

  ,[f_table_schema]    [varchar](128) NOT NULL

  ,[f_table_name]      [varchar](256) NOT NULL

  ,[f_geometry_column] [varchar](256) NOT NULL

  ,[coord_dimension]   [int]          NOT NULL

  ,[srid]              [int]          NOT NULL

  ,[geometry_type]     [varchar](30)  NOT NULL

  ,[qgis_xmin]         [float]

  ,[qgis_ymin]         [float]

  ,[qgis_xmax]         [float]

  ,[qgis_ymax]         [float]

  ,[qgis_pkey]         [varchar](128)

 CONSTRAINT [geometry_columns_pk] PRIMARY KEY CLUSTERED (

     [f_table_catalog]    ASC

     ,[f_table_schema]    ASC

     ,[f_table_name]      ASC

     ,[f_geometry_column] ASC

     ,[geometry_type]     ASC

 ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) 

ON [PRIMARY]

) ON [PRIMARY];

/* Insert spatial meta data */

INSERT INTO [GEO_PROD].[dbo].[geometry_columns]

SELECT

'GEO_PROD' AS f_table_catalog,

'dbo' AS f_table_schema,

'Well_Version' AS f_table_name,

'surface_location' AS f_geometry_column,

2 AS coord_dimension,

4269 AS srid,

'POINT' AS geometry_type,

min([surface_longitude]) AS qgis_xmin,

min([surface_latitude]) AS qgis_ymin,

max([surface_longitude]) AS qgis_xmax,

max([surface_latitude]) AS qgis_ymax,

'well_guid' AS qgis_pkey

from [GEO_PROD].[dbo].[Well_Version];

/* Spatial Index */

CREATE SPATIAL INDEX SIndx_WV_Location ON [GEO_PROD].[dbo].[Well_Version] (surface_location)

USING GEOGRAPHY_GRID

WITH (

CELLS_PER_OBJECT = 16,

GRIDS = (LEVEL_1 = MEDIUM, LEVEL_2 = HIGH, LEVEL_3 = HIGH, LEVEL_4 = HIGH)

 );
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,281 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.