当前位置:网站首页>SuperMap 3D SDKs_ Unity plug-in development - connect data services for SQL queries
SuperMap 3D SDKs_ Unity plug-in development - connect data services for SQL queries
2022-06-30 12:26:00 【supermapsupport】
nannan
In actual projects , We often encounter the need to find objects and filter them through certain attributes . Another popular example is convenient for us to better understand , such as :“ There is a building , Would you like to inquire 2 All buildings in the building , And only show 2 floor , Other floors are hidden ”. At this time , You have to go through SQL Query out “2 floor ” Of all objects corresponding to this attribute ID, Re pass ID Array to control explicit and implicit ( adopt ID Array controls the explicit and implicit visibility of the blog ). adopt SQL The query needs to connect to the data service , Let's take a look at unity How to connect data services in .
1. Data preparation
Prepare model data for the project , Can be in SuperMap iDesktop Import model to generate model dataset , Then process the data , For example, add... In the attribute table “ floor ” Field , And assign corresponding field values ( See the picture 1.1). Last Make a projection surface on the model data set to generate a two-dimensional surface data set ( Publish data services to speed up requests ), Save the workspace ( See the picture 1.2) stay SuperMap iServer Publish data services and 3D services in ( See the picture 1.3). Xiaobian is here on his own iDesktop The drawn surface is then extruded into a volume , give the result as follows :


2. Implementation code
stay unity You need to create a new connection to the data service C# Script, establish button Control and make associated settings . Please refer to this blog for details https://blog.csdn.net/nan620403/article/details/124837056. Let's look at the code implementation process directly .
2.1 SQL Query parameters
Define global variables DataServer( Data services URL)、DatasourceName( Data source name ) and DatasetName( Dataset name ).
public string DataServer = "http://localhost:8090/iserver/services/data-LouCeng/rest/data/featureResults.rjson?returnContent=true";// Data services URL
public string DatasourceName = "unity"; // Data source name
public string DatasetName = " Architectural surface "; // Dataset name
Click in the event to write C# Connect to the data service SQL Query statement , This article is to query the 2 Floor object , The specific code is as follows :
string datasetNames = DatasourceName + ":" + DatasetName;
string json = "{\"getFeatureMode\":\"SQL\",\"datasetNames\":[\"" + datasetNames + "\"],\"maxFeatures\":\"1000\",\"queryParameter\":{\"sortClause\":null, \"ids\":null, \"name\":null, \"attributeFilter\":\" floor ='2 layer '\",\"groupClause\":null, \"linkItems\":null,\"joinItems\":null, \"fields\":null}}";
2.2 POST request
private string PostJson(string postJson)
{
string retString = "";
try
{
string result = string.Empty;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(DataServer);
var cookieContainer = new CookieContainer();
request.Method = "POST";
request.ContentType = "application/json";
request.CookieContainer = cookieContainer;
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(postJson);
writer.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string encoding = response.ContentEncoding;
if (encoding == null || encoding.Length < 1)
{
encoding = "UTF-8";
}
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
retString = reader.ReadToEnd();
}
catch (WebException wex)
{
Debug.Log(wex.Message);
}
catch (System.Exception ex)
{
Debug.Log(ex.Message);
}
return retString;
}
2.3 Get the... Of the object after query ID Array
private List<int> Listids(string json)
{
List<int> list = new List<int>();
Dictionary<string, string> fieldsDic = new Dictionary<string, string>();
JsonFile doc = new JsonFile();
doc.LoadFromString(json);
JsonFile feature = new JsonFile();
doc.GetValue("features", ref feature);
int size = feature.GetArraySize();
for(int j=0;j<size;j++)
{
var child = feature.GetAt(j);
JsonFile namesJson = new JsonFile();
child.GetValue("fieldNames", ref namesJson);
JsonFile valuesJson = new JsonFile();
child.GetValue("fieldValues", ref valuesJson);
var smid = -1;
child.GetValue("ID", ref smid);
Console.WriteLine(smid);
list.Add(smid);
}
return list;
}
2.4 adopt ID Array controls explicit and implicit
List<LayerInfo> layerInfos = SupermapGIS.Instance.Layers.LayerInfos;// Get all layers in the layer manager
for (int i = 0; i < layerInfos.Count; i++)
{
Layer3D layer3D = layerInfos[i].Layer as Layer3D;// Traverse to get each layer in the layer manager
if (layer3D.Type == Layer3DType.S3M&&layer3D.Name== " Architecture @unity")
{
Layer3DS3MFile layer3DS3MFile = layerInfos[i].Layer as Layer3DS3MFile;// obtain S3M Cache layers
layer3DS3MFile.SetObjectsVisible(list1, true);// according to ID Controls the display and hiding of selected objects , Just make it visible
}
}
3. Running results

For the data and codes used in this article, please refer to https://download.csdn.net/download/nan620403/85745014
边栏推荐
- Shutter start from zero 006 radio switches and checkboxes
- 8253 counter introduction
- ModelAtrs声音检测,基于声学特征的异响检测
- Generate entity classes from SQL Server database tables through EF core framework
- List集合
- Beego development blog system learning (II)
- Grep match lookup
- Subtrate 源码追新导读-5月上旬: XCM 正式启用
- After the node is installed in the NVM, the display is not internal or external when the NPM instruction is used
- iServer发布ES服务查询设置最大返回数量
猜你喜欢

How difficult is data governance and data innovation?

Building a database model using power designer tools

90. (cesium chapter) cesium high level listening events

MySQL built-in functions

edusoho企培版纯内网部署教程(解决播放器,上传,后台卡顿问题)

Map集合

SuperMap iDesktop 常见倾斜数据处理全流程解析

Lvgl widget styles

A Generic Deep-Learning-Based Approach for Automated Surface Inspection-論文閱讀筆記

聊聊怎么做硬件兼容性检测,快速迁移到openEuler?
随机推荐
List集合
浏览器播放rtsp视频,基于nodeJs
Construction de la plate - forme universelle haisi 3559: obtenir le codage après modification du cadre de données
Parallel interface 8255A
[target tracking] |pytracking configuring win to compile prroi_ pool. pyd
杂文:自家的智能家居方案研究
Map collection
Object mapping - mapping Mapster
Sword finger offer 05 Replace spaces: replace each space in the string s with "%20"“
redis在项目中的使用
A review of quantum neural networks 2022 for generating learning tasks
edusoho企培版纯内网部署教程(解决播放器,上传,后台卡顿问题)
lvgl 小部件样式篇
Pinda general permission system (day 7~day 8)
Getting started with the go language is simple: go handles XML files
Building a database model using power designer tools
Browser plays RTSP video based on nodejs
90.(cesium篇)cesium高度监听事件
STM32 porting the fish component of RT thread Standard Edition
药店管理系统