VDS Technologies

 

Create Geometry points,polyline,polygon in MSSQL using Shape.shapeData

1/8/2015 12:16:20 AM
Total Posts 50

Create Geometry points,polyline,polygon in MSSQL using Shape.shapeData

Hi Sir, I follow sample ShapeEditor for Created Spatial and Edit data spatial. But I have problem when click SAVE. it was error Page loading, and no shape loaded. this is my code : Private Sub AddNewShape(ByVal title As String, ByVal color As String, ByVal shape As AspMap.Shape) Dim tableName As String Select Case shape.ShapeType Case AspMap.ShapeType.Point tableName = "ShapeDataPoint" Case AspMap.ShapeType.Line tableName = "ShapeDatalines" Case AspMap.ShapeType.Polygon tableName = "ShapeDataPolygons" Case Else Return End Select Dim sql As String = "INSERT INTO " & tableName & " (TITLE, COLOR, Sp_geometry) VALUES (?,?,?)" conATBGISMAPDB.Open() Dim cmd As SqlCommand = New SqlCommand(sql, conATBGISMAPDB) cmd.Parameters.AddWithValue("TITLE", title) cmd.Parameters.AddWithValue("COLOR", color) cmd.Parameters.AddWithValue("Sp_geometry", shape.ShapeData) cmd.ExecuteNonQuery() conATBGISMAPDB.Close() ReloadShapesDatabase() End Sub Private Sub UpdateShape(ByVal tableName As String, ByVal id As String, ByVal title As String, ByVal color As String) Dim sql As String = "UPDATE " & tableName & " SET TITLE = ?, COLOR = ? WHERE (ID = ?)" conATBGISMAPDB.Open() Dim cmd As SqlCommand = New SqlCommand(sql, conATBGISMAPDB) cmd.Parameters.AddWithValue("TITLE", title) cmd.Parameters.AddWithValue("COLOR", color) cmd.Parameters.AddWithValue("ID", Convert.ToInt32(id)) cmd.ExecuteNonQuery() conATBGISMAPDB.Close() ReloadShapesDatabase() End Sub What's wrong with it? Can we use SHAPE.SHAPEDATA to input GEOM spatial?
1/8/2015 3:21:14 AM
MVP
Total Posts 323

Re: Create Geometry points,polyline,polygon in MSSQL using Shape.shapeData

Try to use the ShapeDataLayer class. See the ShapeEditor sample, you have to change WkbDataLayer to ShapeDataLayer. AspMap 4.8 is required.

1/15/2015 1:38:39 PM
Total Posts 33

Re: Create Geometry points,polyline,polygon in MSSQL using Shape.shapeData

Hi arpat,

i also try to add new shape to database sql server with your code and reference from ShapeEditor sample

its really works,

this is my code :

<!-- in Aspx Form put this tool for add new polygon -->
<aspmap:MapToolButton id="MapToolButton1" runat="server" ToolTip="Polygon Tool" ImageUrl="image/poly.png"
Map="map" MapTool="Polygon" ></aspmap:MapToolButton>

'in code behind

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

'Call Database Layer
AddDatabaseLayer()

End Sub

Protected Sub map_PolygonTool(ByVal sender As Object, ByVal e As AspMap.Web.PolygonToolEventArgs) Handles map.PolygonTool

Dim mapShape As MapShape = map.MapShapes.Add(e.Polygon)
mapShape.Symbol.Size = 1
mapShape.Symbol.LineColor = Color.Red
mapShape.Symbol.FillStyle = FillStyle.LightGray
mapShape.Symbol.FillColor = Color.Red

AddNewShape("Your title", "Your color", mapShape.Shape)

End Sub

Private Sub AddDatabaseLayer()
'Get Connectionstring from app setting in web.config
Dim connectionString As String = "Data Source=server name;Persist Security Info=True;Password=password;User ID=user;Initial Catalog=databasename"

Dim tableName As String = "Your table name"
Dim SqlLayer As AspMap.Data.SqlServerLayer = New AspMap.Data.SqlServerLayer(connectionString, tableName, "Sp_geometry")
SqlLayer.FieldList = "TITLE, COLOR"

SqlLayer.ShapeType = ShapeType.Polygon 'Change type if not polygon type
Dim layer As AspMap.Layer = map.AddLayer(SqlLayer)

If layer Is Nothing Then
Return
End If

layer.Name = "polygons"
layer.Opacity = 0.4
layer.ShowLabels = True
layer.LabelStyle = LabelStyle.PolygonCenter
layer.LabelField = "TITLE"
layer.LabelFont.Name = "Verdana"
layer.LabelFont.Size = 12
layer.LabelFont.Color = Color.White
layer.LabelFont.OutlineColor = Color.Black
layer.LabelFont.Outline = True
layer.Symbol.Size = 1
layer.Symbol.FillColor = Color.LightGreen
layer.Symbol.LineColor = Color.Green

End Sub

'Method for add new shape layer name "polygons"
Private Sub AddNewShape(ByVal title As String, ByVal color As String, ByVal shape As AspMap.Shape)
Dim layer As AspMap.Layer = map("polygons")

Dim rs As AspMap.Recordset = layer.NewRecord()

If (Not rs.EOF) Then
rs("TITLE") = title
rs("COLOR") = color
rs.Shape = shape
rs.Update()
End If
End Sub

 

im from Jakarta, Indonesia :)

 

10/31/2017 12:45:23 AM
Total Posts 15

Re: Create Geometry points,polyline,polygon in MSSQL using Shape.shapeData

Hello Everyone,,

 

Please convert this working code into C# using Postgres database..

 

11/5/2017 11:09:18 PM
Total Posts 15

Re: Create Geometry points,polyline,polygon in MSSQL using Shape.shapeData

Please Reply as soon as possible...