首页 / 浏览问题 / 组件GIS / 问题详情
添加图层时报错
80EXP 2021年01月13日
您好添加图层的时候报错 :数据集的投影坐标类型不支持 Parameter name: dataset.PrjCoordSysType

1个回答

代码如下 麻烦看看是什么问题:

using HWS.Forms.Common;
using HWS.Forms.Common.Map;
using HWS.Forms.DataAccess.Model.Entity;
using Newtonsoft.Json;
using SuperMap.Data;
using SuperMap.Realspace;
using SuperMap.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
           
            InitializeComponent();
            bind();
        }

        public void bind()
        {
            SceneControl sceneControl = new SceneControl();
            Workspace workspace = new SuperMap.Data.Workspace(this.components);

            workspace.Description = "";
            workspace.DesktopInfo = "";
            sceneControl.Action = SuperMap.UI.Action3D.Pan;
            sceneControl.BackColor = System.Drawing.Color.White;
            //sceneControl.ControlMode = SuperMap.Realspace.ControlMode3D.Normal;
            //sceneControl.InteractionMode = SuperMap.UI.InteractionMode3D.Default;
            sceneControl.IsAlwaysActive = false;
            sceneControl.IsAlwaysUpdate = false;
            sceneControl.IsCursorCustomized = false;
            sceneControl.IsDynamicSelection = false;
            sceneControl.IsFPSVisible = false;
            sceneControl.IsKeyboardNavigationEnabled = false;
            sceneControl.IsMouseNavigationEnabled = true;
            sceneControl.IsStatusBarShowAltitude = false;
            sceneControl.IsStatusBarVisible = true;
            sceneControl.IsWaitCursorEnabled = false;
            sceneControl.LayerIDUnit = 8;
            sceneControl.Location = new System.Drawing.Point(0, 28);
            sceneControl.Name = "sceneControl";
            sceneControl.Size = new System.Drawing.Size(800, 424);
            sceneControl.SnapMode = SuperMap.Realspace.SnapMode3D.NONE;
            sceneControl.SnapTolerance = 10;
            sceneControl.TabIndex = 2;
            sceneControl.TrackMode = SuperMap.UI.TrackMode3D.Edit;
            sceneControl.Scene.LatLonGrid.IsVisible = false;
            sceneControl.Dock = DockStyle.Fill;
            this.Controls.Add(sceneControl);

            DatasourceConnectionInfo info = new DatasourceConnectionInfo();
            info.Server = ":memory:";
            info.EngineType = EngineType.UDB;
            workspace.Datasources.Create(info);

            Datasets datasets = workspace.Datasources[0].Datasets;
            DatasetVectorInfo vectorInfo = new DatasetVectorInfo();
            vectorInfo.Name = "point";
            vectorInfo.Type = DatasetType.Point3D;
            DatasetVector datasetVector = datasets.Create(vectorInfo);
            Dataset dataset = datasets["point"];

            Recordset recordset = null;

            try
            {
                recordset = datasetVector.GetRecordset(false, CursorType.Dynamic);
                Dictionary<string, object> dic = new Dictionary<string, object>();
                dic.Add("0", "test1");
                Point3D point3D = new Point3D(100, 31, 1);
                GeoPoint3D geoPoint3D = new GeoPoint3D();
                geoPoint3D.Position = point3D;
                recordset.AddNew(geoPoint3D, dic);
                recordset.Update();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                // recordset 使用完毕后必须 Dispose
                // The recordset must be disposed after using
                if (recordset != null)
                {
                    recordset.Dispose();
                }
            }

            Layer3DSettingVector settingPoint = new Layer3DSettingVector();
            settingPoint.Style.AltitudeMode = AltitudeMode.RelativeToUnderground;
            settingPoint.Style.BottomAltitude = -15;
            sceneControl.Scene.Layers.Add(dataset, settingPoint,true);
            
        }
    }
}
80EXP 2021年01月13日

根据报错信息看,问题很明确了,这种类型的数据集坐标系不支持,你看一下你的数据集是什么坐标系,只有地理坐标系或者投影坐标系的数据能够添加到三维球面场景,你这个数据集是新建的,你可以设置一下dataset的坐标系属性,

Dataset..::.PrjCoordSys 属性

再给你说一下,你看一下你添加到数据集里面的点的坐标是多少,如果x是正常的+-180范围内,Y在+-90范围内,那就是地理坐标,你设置一个地理坐标系就可以了,如果是很大的值,就是投影坐标,设置一个投影坐标系
设置了地理坐标系 但是球上不显示呢
下面这段代码 能否麻烦您修改成能够在球上显示呢

 SceneControl sceneControl = new SceneControl();
            Workspace workspace = new SuperMap.Data.Workspace(this.components);
            sceneControl.Scene.Workspace = workspace;
            workspace.Description = "";
            workspace.DesktopInfo = "";
            sceneControl.Action = SuperMap.UI.Action3D.Pan;
            sceneControl.BackColor = System.Drawing.Color.White;
            //sceneControl.ControlMode = SuperMap.Realspace.ControlMode3D.Normal;
            //sceneControl.InteractionMode = SuperMap.UI.InteractionMode3D.Default;
            sceneControl.IsAlwaysActive = false;
            sceneControl.IsAlwaysUpdate = false;
            sceneControl.IsCursorCustomized = false;
            sceneControl.IsDynamicSelection = false;
            sceneControl.IsFPSVisible = false;
            sceneControl.IsKeyboardNavigationEnabled = false;
            sceneControl.IsMouseNavigationEnabled = true;
            sceneControl.IsStatusBarShowAltitude = false;
            sceneControl.IsStatusBarVisible = true;
            sceneControl.IsWaitCursorEnabled = false;
            sceneControl.LayerIDUnit = 8;
            sceneControl.Location = new System.Drawing.Point(0, 28);
            sceneControl.Name = "sceneControl";
            sceneControl.Size = new System.Drawing.Size(800, 424);
            sceneControl.SnapMode = SuperMap.Realspace.SnapMode3D.NONE;
            sceneControl.SnapTolerance = 10;
            sceneControl.TabIndex = 2;
            sceneControl.TrackMode = SuperMap.UI.TrackMode3D.Edit;
            sceneControl.Scene.LatLonGrid.IsVisible = false;
            sceneControl.Dock = DockStyle.Fill;
            this.Controls.Add(sceneControl);
          

            Point3Ds point3Ds = new Point3Ds();
            point3Ds.Add(new Point3D(103, 32, 0));
            point3Ds.Add(new Point3D(95, 24, 0));
            point3Ds.Add(new Point3D(96, 33, 0));
            point3Ds.Add(new Point3D(97, 50, 0));
            point3Ds.Add(new Point3D(103, 32, 0));
            GeoRegion3D geoRegion3D = new GeoRegion3D(point3Ds);
            GeoStyle3D geoStyle3D = new GeoStyle3D();
            geoStyle3D.FillBackColor = Color.Aqua;
            geoStyle3D.FillForeColor = Color.Aqua;
            geoStyle3D.AltitudeMode = AltitudeMode.ClampToGround;
            geoStyle3D.AltitudeMode = AltitudeMode.Absolute;
            geoStyle3D.ExtendedHeight = 10000000;

            geoRegion3D.Style3D = geoStyle3D;

            DatasourceConnectionInfo info = new DatasourceConnectionInfo();
            info.Server = ":memory:";
            info.EngineType = EngineType.UDB;
            workspace.Datasources.Create(info);

            Datasets datasets = workspace.Datasources[0].Datasets;
            DatasetVectorInfo vectorInfo = new DatasetVectorInfo();
            vectorInfo.Name = "Region3D";
            vectorInfo.Type = DatasetType.Region3D;
            DatasetVector datasetVector = datasets.Create(vectorInfo);
            Dataset dataset = datasets["Region3D"];

            Recordset recordset = null;

            try
            {
                recordset = datasetVector.GetRecordset(false, CursorType.Dynamic);
                Dictionary<string, object> dic = new Dictionary<string, object>();
                dic.Add("0", "test1");
               
                recordset.AddNew(geoRegion3D, dic);
                recordset.Update();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                // recordset 使用完毕后必须 Dispose
                // The recordset must be disposed after using
                if (recordset != null)
                {
                    recordset.Dispose();
                }
            }

            Layer3DSettingVector settingPoint = new Layer3DSettingVector();
           
            PrjCoordSys prjCoordSys =  new PrjCoordSys();
            prjCoordSys.Type = PrjCoordSysType.WorldPlateCarree;
            workspace.Datasources[0].Datasets["Region3D"].PrjCoordSys = prjCoordSys;
            sceneControl.Scene.Layers.Add(workspace.Datasources[0].Datasets["Region3D"], settingPoint,true);
PrjCoordSys prjCoordSys =  new PrjCoordSys();

prjCoordSys.FromEPSGCode(4326);

workspace.Datasources[0].Datasets["Region3D"].PrjCoordSys = prjCoordSys;

这么设置

添加进去后,定位当当前图层

Scene.EnsureVisible()上面的图层
可以了  十分感谢
客气啦,解决了可以点击一下采纳结题
...