Oracle Spatial's Spatial data applications are similar to those of Microsoft SQL Server 2008. SQL Server 2008 provides SQLCLR-based programming support, and Oracle Spatial does not yet have complete component support. In actual development and application scenarios, we can select a compromise solution, such as reading space data into a common space data expression format (such as WKT ), the open-source WKT reading component can be used to parse WKT data into coordinate points or coordinate sets of corresponding spatial data.
The following example shows how to read the Oracle Spatial Data as WKT, parse the data through the WKT component, and render the data in Bing Maps. Now we need to read the data of Sichuan province from the local city data configured in the database and render it in the map, oracle Spatial's sdo_geometry data type can be directly converted to clob data using the function (get_wkt.
Select t. areacode, t. areaname, (t. area. get_wkt () wkt from areainfo t where areacode like '20140901'
To facilitate the use of the client, the server can encapsulate the data to be returned as an array through the WCF Service. The following are the local object data structure and the definition of the WCF Service.
Namespace OracleSpatial. DataService. Models
{
[DataContract]
Public class AreaInfo
{
[DataMember]
Public string AreaCode {get; set ;}
[DataMember]
Public string AreaName {get; set ;}
[DataMember]
Public string WKT {get; set ;}
}
}
Namespace OracleSpatial. DataService
{
[ServiceContract]
Public interface IGeometryService
{
[OperationContract]
List <AreaInfo> GetAreaInfo ();
}
}
The Silverlight client of Bing Maps calls the WCF Service to obtain data in the database, which is not described in detail here. Here, we need to introduce several open-source applications:
1. SharpMap open source GeoAPI.
2. NetTopologySuite.
These two open-source libraries define the spatial standards for different GIS coordinate systems, as well as spatial objects, spatial computing, and spatial analysis interfaces based on geographical spaces, in application development, you can easily read, write, verify, compute, and analyze spatial data. This article uses the WKT reader component (WKTReader) to resolve a string in the WKT format to a common space object (Geometry) that complies with the GIS coordinate system standards ), this space object contains the complete WKT data description, such as the coordinate points, coordinate points set, internal coordinate points, and space area.
Public MainPage ()
{
InitializeComponent ();
This. Loaded + = (sender, e) =>
{
LoadChinaMap ();
GeometryServiceClient service = new GeometryServiceClient ();
Service. GetAreaInfoCompleted + = service_GetAreaInfoCompleted;
Service. GetAreaInfoAsync ();
};
}
Private void service_GetAreaInfoCompleted (object sender, GetAreaInfoCompletedEventArgs e)
{
If (e. Error = null)
{
ObservableCollection <AreaInfo> result = e. Result;
WKTReader reader = new WKTReader ();
IGeometry geometry = reader. Read (result [0]. WKT );
}
}
WKTReader is used to parse the space data in the WKT format into the space object of the IGeometry interface, so that various coordinate values in the WKT space data can be easily obtained. If the data obtained above is used, we can draw a polygon and render the data in the map using custom annotations.
Private void service_GetAreaInfoCompleted (object sender, GetAreaInfoCompletedEventArgs e)
{
If (e. Error = null)
{
ObservableCollection <AreaInfo> result = e. Result;
WKTReader reader = null;
Foreach (var item in result)
{
Reader = new WKTReader ();
IGeometry geometry = reader. Read (item. WKT );
// Boundary
MapPolygon line = new MapPolygon ();
Line. Locations = CoordinateConvertor. CoordinatesToLocationCollection (geometry. Coordinates );
Line. Fill = new SolidColorBrush (Colors. Gray );
Line. BorderBrush = new SolidColorBrush (Colors. Green );
Line. BorderThickness = new Thickness (2 );
Line. MouseEnter + = new MouseEventHandler (line_MouseEnter );
Line. MouseLeave + = new MouseEventHandler (line_MouseLeave );
This. mlayer. Children. Add (line );
// Name Annotation
This. mlayer. AddChild (new PointControl (item. AreaName ),
New Microsoft. Maps. MapControl. Location (geometry. InteriorPoint. Y, geometry. InteriorPoint. X ));
}
}
}
Private void line_MouseLeave (object sender, MouseEventArgs e)
{
MapPolygon mp = sender as MapPolygon;
Mp. Fill = new SolidColorBrush (Colors. Gray );
}
Private void line_MouseEnter (object sender, MouseEventArgs e)
{
MapPolygon mp = sender as MapPolygon;
Mp. Fill = new SolidColorBrush (Colors. Yellow );
}
Related Resources:
[1], SharpMap: http://sharpmap.codeplex.com
[2], NetTopologySuite: http://code.google.com/p/nettopologysuite
[3], WKT: http://www.opengis.org/techno/specs.htm
Copyright description
This article is an original article. You are welcome to repost it and indicate the source of the Article. Its copyright belongs to the author and the blog Park. To save the author's Creative Enthusiasm, mark the source of this article in an obvious position after reprinting.
Author: Beniao
Article Source: http://beniao.cnblogs.com/or http://www.cnblogs.com/