阅读:4588回复:12
[求助]如何在MO+VB实现绘制矩形和椭圆并保存。
前段时间我在MO+VB中实现了绘制点、线、多边形并保存。但没有实现绘制矩形和椭圆并保存,我觉得前三者的实现是完全一样,通过在map控件中定点然后保存点的记录就可以实现。但在实现了绘制矩形和椭圆后怎样保存已绘制的对象我觉得按照实现点、线、多边形的思路是无法实现的。请斑竹和大虾指点迷津。谢谢了
学习MO贵在交流,现在我真的深有感触,在这里学到了不少东西!!,希望能有更大的收获!! |
|
1楼#
发布于:2006-11-22 22:48
矩形和椭圆保存时需要转换为多边形
|
|
2楼#
发布于:2006-11-03 21:34
mapobjects上的帮助说明是:如果是建立新的shapefile图层,则addgeodataset只支持点、线、多变形,那么圆该怎么保存呢?请教了!!!挺郁闷的
|
|
3楼#
发布于:2006-11-03 20:24
<P>矩形是可以通过变换成多边形来保存,可圆形呢?我试过dc.AddGeoDataset(sName, moShapeTypePolygon, desc)把其中的moshapetype换成moshapetypeellipse根本就不行,而且moshapetyperectangle也不行,可书上说语法就是这样的啊!而且我保证desc也没有设错!对了,我用的是mo2.2,哪位好心人给解释一下啊?<BR></P>
|
|
4楼#
发布于:2003-09-29 10:27
好,支持,期待更多兄弟来交流!
|
|
5楼#
发布于:2003-09-29 10:10
不知为什么,我的中文标注一拷进去就变成了乱码。不过我想不会影响大家看代码的。有问题就跟我联系!!
|
|
6楼#
发布于:2003-09-29 10:07
以下是绘制矩形并保存的代码,希望对大家有帮助。绘制椭圆保存的代码基本相同。
Option Explicit Dim rect As MapObjects2.Rectangle Dim moSymbol As New MapObjects2.Symbol Dim moRectangles As New Collection '----------------------------------------------------------------------------------- '----------------------------------------------------------------------------------- Private Sub Command1_Click() Dim gds As MapObjects2.GeoDataset Dim sName As String Dim desc As New TableDesc Dim dc As New DataConnection Dim lyr As New MapObjects2.MapLayer Dim lrect As Long With CommonDialog1 .Filter = "ESRI Shapefiles (*.shp)|*.shp" .DefaultExt = ".shp" .ShowSave If Len(.FileName) = 0 Then Exit Sub ' cancel dc.Database = CurDir If Not dc.Connect Then Exit Sub ' bad dataConnection ' È¥³ýÀ©Õ¹Ãû¡££¨remove the extension£© sName = Left(.FileTitle, Len(.FileTitle) - 4) End With With desc ' ¶¨Òå¼Ç¼Êý¡££¨define three additional fields£© .FieldCount = 3 'set the field names .FieldName(0) = "Name" .FieldName(1) = "Area" .FieldName(2) = "Perimeter" ' set the type of field .FieldType(0) = moString .FieldType(1) = moDouble .FieldType(2) = moDouble ' set the length of a character field .FieldLength(0) = 16 ' set the number of digits used in the field .FieldPrecision(1) = 15 .FieldPrecision(2) = 15 ' set the number of digits to the right of the decimal point .FieldScale(1) = 3 .FieldScale(2) = 3 End With Set gds = dc.AddGeoDataset(sName, moShapeTypePolygon, desc) If gds Is Nothing Then Exit Sub ' invalid file Set lyr.GeoDataset = gds For lrect = 1 To moRectangles.Count With lyr.Records .AddNew .Fields("Shape").Value = moRectangles(lrect) .Fields("Name").Value = "Name " & lrect .Fields("Area").Value = moRectangles(lrect).Area .Fields("Perimeter").Value = moRectangles(lrect).Perimeter .Update End With Next lyr.Records.StopEditing End Sub Private Sub Form_Load() With moSymbol .SymbolType = moFillSymbol .Style = moSolidFill .Color = moPaleYellow End With Command1.Caption = "±£´æͼ²ã(*.shp)" End Sub Private Sub Map1_AfterTrackingLayerDraw(ByVal hDC As Stdole.OLE_HANDLE) Dim Plog As New MapObjects2.Polygon If moRectangles.Count <> 0 Then For Each Plog In moRectangles Map1.DrawShape Plog, moSymbol Next End If End Sub Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) Dim rect As MapObjects2.Rectangle Dim Plog As MapObjects2.Polygon Set rect = Map1.TrackRectangle Map1.TrackingLayer.AddEvent rect, 0 Set Plog = rect.Buffer(0) moRectangles.Add Plog Map1.TrackingLayer.Refresh True End Sub |
|
7楼#
发布于:2003-09-27 11:02
期待!
|
|
8楼#
发布于:2003-09-27 10:32
终于实现了。谢谢ly_sunny和斑竹,谢谢大虾。我把代码整理一下再发到帖子上让有这方面问题的同道们功享!!
|
|
9楼#
发布于:2003-09-27 09:48
画圆形时,第一次点的是圆心,然后拖运得到半径;
画矩形时,第一次点的是起点,然后拖运得到大小。 |
|
|
上一页
下一页