- 积分
- 797
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-8-1
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2013-3-9 16:12:52
|
显示全部楼层
本帖最后由 tinysand 于 2013-3-9 16:26 编辑
风沙的星期六,王老师仍在认真的回答我们的问题,谢谢!
生成VectorLayer的代码如下,主程序仍是上次的工程。
- /// 生成等值线的shp文件
- /// 生成等值线的shp文件
- ///
- ///
- public void CreateShp(string sShapeFullName)
- {
- string strShapeFolder = System.IO.Path.GetDirectoryName(sShapeFullName);
- string strShapeFile = System.IO.Path.GetFileName(sShapeFullName);
- //New layer
- VectorLayer aLayer = new VectorLayer(ShapeTypes.Polyline);
- aLayer.LayerName = strShapeFile;
- //aLayer.LegendScheme = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Polyline, Color.Red, 2);
- Color[] colors = LegendManage.CreateColors(Color.Blue, Color.Red, _CValues.Count());
- aLayer.LegendScheme = LegendManage.CreateUniqValueLegendScheme(_CValues, colors, ShapeTypes.Polyline
- , m_fMinData, m_fMaxData, false, -999.0);
- aLayer.LegendScheme.FieldName = "Value"; //Add fields
- aLayer.EditAddField("Type", typeof(string));
- aLayer.EditAddField("Value", typeof(double));
- //Add shape
- for (int i = 0; i < _contourLines.Count; i++)
- {
- PolylineShape aPL = new PolylineShape();
- double fMinX=999, fMaxX = -999, fMinY=999, fMaxY = -999; //用于计算线的Extent
- double fLen = 0, fLastX=_contourLines[i].PointList[0].X, fLastY=_contourLines[i].PointList[0].Y; //用于计算线的Length
- for (int j = 0; j < _contourLines[i].PointList.Count; j++)
- {
- MeteoInfoC.PointD aPoint = new MeteoInfoC.PointD();
- aPoint.X = _contourLines[i].PointList[j].X;
- aPoint.Y = _contourLines[i].PointList[j].Y;
- aPL.Points.Add(aPoint);
- //计算线的范围
- if(fMinX > aPoint.X)
- fMinX = aPoint.X;
- if(fMinY > aPoint.Y)
- fMinY = aPoint.Y;
- if(fMaxX < aPoint.X)
- fMaxX = aPoint.X;
- if(fMaxY < aPoint.Y)
- fMaxY = aPoint.Y;
- //计算线的长度
- fLen = fLen + Math.Sqrt((aPoint.X - fLastX)*(aPoint.X - fLastX) +
- (aPoint.Y - fLastY)*(aPoint.Y - fLastY));
- fLastX = aPoint.X;
- fLastY = aPoint.Y;
- }
- MeteoInfoC.Global.Extent ext = new MeteoInfoC.Global.Extent(fMinX, fMaxX, fMinY, fMaxY);
- aPL.Extent = ext;
- aPL.value = _contourLines[i].Value;
- int shapeNum = aLayer.ShapeNum;
- if (aLayer.EditAddShape(aPL))
- {
- //Edit record value
- aLayer.EditCellValue("Type", shapeNum, _contourLines[i].Type);
- aLayer.EditCellValue("Value", shapeNum, _contourLines[i].Value);
- }
- }
- MeteoInfoC.Global.Extent extent = new MeteoInfoC.Global.Extent(m_fLBLon, m_fRTLon, m_fLBLat, m_fRTLat);
- aLayer.Extent = extent;
- aLayer.ProjInfo = m_MainMapView.ActiveMapFrame.MapView.Layers[1].ProjInfo;
- //aLayer.ProjInfo
- m_MainMapView.ActiveMapFrame.AddLayer(aLayer);
-
- }
复制代码
用这个加入代码VectorLayer在投影为lambert投影时,会出现异常。图片
VS中的详细异常信息如下:
未处理 System.NullReferenceException
Message="未将对象引用设置到对象的实例。"
Source="MeteoInfoC"
StackTrace:
在 MeteoInfoC.Geoprocess.GeoComputation.(List`1 , Object )
在 MeteoInfoC.Geoprocess.GeoComputation.ClipPolylineShape_Lon(PolylineShape aPLS, Double lon)
在 MeteoInfoC.Map.ProjectionSet.ProjectLayer(VectorLayer oLayer, ProjectionInfo toProj, Boolean projectLabels)
在 MeteoInfoC.Map.ProjectionSet.ProjectLayer(VectorLayer oLayer, ProjectionInfo toProj)
在 MeteoInfoC.Map.ProjectionSet.ProjectLayers(MapView aMapView, ProjectionInfo toProj)
在 MeteoInfoC.Map.MapView.ProjectLayers(ProjectionInfo toProj)
在 MeteoTest.MainFrm.buttonItemLambert_Click(Object sender, EventArgs e) 位置 E:\meteoinfoStudy\MeteoShow\MeteoShow\MainFrm.cs:行号 243
在 DevComponents.DotNetBar.BaseItem.RaiseClick(eEventSource source)
在 DevComponents.DotNetBar.BaseItem.InternalMouseUp(MouseEventArgs objArg)
在 DevComponents.DotNetBar.PopupItem.InternalMouseUp(MouseEventArgs objArg)
在 DevComponents.DotNetBar.ButtonItem.InternalMouseUp(MouseEventArgs objArg)
在 DevComponents.DotNetBar.BaseItem.InternalMouseUp(MouseEventArgs objArg)
在 DevComponents.DotNetBar.GenericItemContainer.InternalMouseUp(MouseEventArgs objArg)
在 DevComponents.DotNetBar.Bar.OnMouseUp(MouseEventArgs e)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 DevComponents.DotNetBar.Bar.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 MeteoShow.Program.Main() 位置 E:\start\meteoinfoStudy\MeteoShow\MeteoShow\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
调试时我仔细的对比了自己生成的VectorLayer和王老师示例代码的river.shp生成的VectorLayer对象的值,好象就是缺Lenght值的原因。
|
|