DK for ASPNET - Easy way to publish REST services
The DK.ASPNET can be used to easily create REST services exposing the full TatukGIS functionality using JSON encoding.
A sample REST project, demonstrating reprojection between coordinate systems, can be tested here.
The code behind the Geometry/Project sample:
- <%@ Page Language="VB" Debug="True" %>
- <%@ Import Namespace="TatukGIS.Web.Extensions.Rest" %>
- <%@ Import Namespace="TatukGIS.NDK" %>
-
- <!DOCTYPE html>
-
- <script runat="server">
- Function DoRest(_context As RestHelper) As Object
- Dim geo As JsonGeometry
- Dim res As JsonGeometry
-
- Dim i_from_cs As Integer = _context.ParamAsInteger("FromCS")
- Dim i_to_cs As Integer = _context.ParamAsInteger("ToCS")
- Dim s_geo As String = _context.ParamAsString("Geometry")
-
- Dim from_cs As TGIS_CSCoordinateSystem = TGIS_CSFactory.ByEPSG(i_from_cs)
- If from_cs.EPSG = 0 Then
- Throw New Exception("'FromCS' is unknown")
- End If
-
- Dim to_cs As TGIS_CSCoordinateSystem = TGIS_CSFactory.ByEPSG(i_to_cs)
- If to_cs.EPSG = 0 Then
- Throw New Exception("'ToCS' is unknown")
- End If
-
- If from_cs.EPSG = to_cs.EPSG Then
- _context.Message = "'FromCS & 'ToCS' represent same CS"
- End If
-
- Try
- geo = _context.FromJson(Of JsonGeometry)(s_geo)
- Catch ex_tmp As Exception
- Throw New Exception("Bad 'geometry'. " + ex_tmp.Message)
- End Try
-
- If (geo.Value Is Nothing) Or (geo.Value.IsEmpty) Then
- Throw New Exception("'Geometry' is null or empty")
- End If
-
- Dim la As TGIS_LayerVector = New TGIS_LayerVector()
- la.CS = from_cs
- la.Open()
- Dim shp_tmp = la.AddShape(geo.Value)
- res.Value = shp_tmp.CreateCopyCS(to_cs)
-
- Return res
- End Function
-
- Sub Page_Load()
- Dim rest As New RestHelper( AddressOf DoRest )
- End Sub
- </script>
-
- <head runat="server">
- <title>Rest - Project</title>
- </head>
- <body>
- Usage etc.
- </body>
- </html>