Accessing Points Stored in a Database


 

A database table should contain two columns (data type is Double) that are used to store/retrieve coordinates of points; for example, the points may be stored as longitude/latitude coordinates.

 

A sample table in a SQL Server database may look as the following:
 

ID

NAME

STATE

LONGITUDE

LATITUDE

1958

STEVENSON

AL

-85.803

34.8862

1956

CHAMBERS MUNI

AL

-85.2296

32.812

1583

ROY WILCOX

AL

-88.1945

31.4518

935

GROVE HILL MUNI

AL

-87.7614

31.6893

 

The LONGITUDE field contains coordinates by the X-axis, the LATITUDE field contains coordinates by the Y-axis.

 

Create a PointDataLayer object and pass the connection string, table name and X/Y field names to its constructor. Add the PointDataLayer to the Map control using the AddLayer method:


Imports AspMap
Imports AspMap.Data

Dim connectionString As String = "Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"
Dim tableName As String = "locations"
Dim providerName As String = "System.Data.SqlClient" ' SQL Server

Dim pointData As PointDataLayer 

pointData = New PointDataLayer(providerName, connectionString, tableName, "LONGITUDE", "LATITUDE")

Dim layer As Layer = map.AddLayer(pointData)

 

The PointDataLayer 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)