SQL Server


SQL Server supports spatial extensions to enable the generation, storage, and analysis of geographic features.


AspMap supports the Geometry and Geography data type. The SqlServerLayer class can be used to access and edit such spatial data. A sample table in a SQL Server database may look as the following:

NAME            TYPE
ID              int IDENTITY(1,1)
CITY_NAME       nvarchar(255)
STATE_NAME      nvarchar(255)
POPULATION      bigint
GEOM              geometry



The GEOM field stores shapes in the Geometry data format. The GEOM field has a spatial index (SPATIAL INDEX cities_geom) which is required to speed up spatial queries (for fast map rendering).

Please note that the Geography data type of SQL Server 2008 does not support filter shapes/extents that span more than half of the Earth's surface (for example, a map of the entire world cannot be rendered). It is recommended to use the Geometry data type instead. SQL Server 2012 is free from this limitation.


Create a SqlServerLayer object and pass the connection string, table name and GEOM field to its constructor. It is also necessary to specify the FieldList property if you need attribute data for labeling or editing. Depending on the spatial data type, the DataType property should be specified.


Add the SqlServerLayer to the Map control using the AddLayer method:

Imports AspMap
Imports AspMap.Data

Dim connectionString As String = "Data Source=SERVER\\SQLEXPRESS;Initial Catalog=DB;Integrated Security=SSPI;"
Dim tableName As String = "cities"

Dim sqlLayer As SqlServerLayer 

sqlLayer = New SqlServerLayer(connectionString, tableName, "GEOM")
sqlLayer.FieldList = "ID, CITY_NAME, POPULATION"
sqlLayer.DataType = SqlServerDataType.Geometry

Dim layer As Layer = map.AddLayer(sqlLayer)


The SqlServerLayer class supports editing of data as described in the Editing Spatial and Attribute Data topic.


Note: If you use only database layers in your application, it must be necessary to specify the extent of each database layer. By default, the extent is set to (-180,90,180,-90) where the units are decimal degrees. The extent of a database layer can be set via the Extent property. If an incorrect extent is set, the database layer will not be visible.



© 2018 VDS Technologies
Converted from CHM to HTML with chm2web Standard 2.85 (unicode)