C#開發BIMFACE系列25 服務端API之獲取模型數據10:獲取樓層對應面積分區列表

在《C#開發BIMFACE系列22 服務端API之獲取模型數據7:獲取多個模型的樓層信息》中,返回的樓層信息結果中包含了樓層的具體信息,其中包含樓層ID。html

一個樓層中可能包含多個面積分區,本文介紹如何獲取樓層對應面積分區列表。api

請求地址:GET https://api.bimface.com/data/v2/files/{fileId}/areaside

說明:獲取單個模型中單個樓層對應的分區列表。
oop

參數:測試

請求 path(示例):https://api.bimface.com/data/v2/files/1211223382064960/areas?floorId=311ui

請求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"url

HTTP響應示例(200):spa

{
  "code" : "success",
  "data" : [ {
    "area" : 5.168684733047761E7,
    "boundary" : "",
    "id" : "313137",
    "levelId" : "11",
    "maxPt" : {
      "x" : -4938.068482562385,
      "y" : -3201.59397858169,
      "z" : 0.0
    },
    "minPt" : {
      "x" : -4938.068482562385,
      "y" : -3201.59397858169,
      "z" : 0.0
    },
    "name" : "dining room 4",
    "perimeter" : 28802.013920728663,
    "properties" : [ {
      "group" : "dimension",
      "items" : [ {
        "code" : "perimeter",
        "extension" : "object",
        "key" : "perimeter",
        "orderNumber" : 0,
        "unit" : "mm",
        "value" : 17200,
        "valueType" : 2
      } ]
    } ],
    "viewName" : "1 1"
  } ],
  "message" : ""
}

封裝成對應的C#類:3d

/// <summary>
///  獲取單個模型種單個樓層對應面積分區列表的返回結果類
/// </summary>
public class SingleModelSingleFloorAreas : GeneralResponse<List<Area>>
{

}

其中 Area 類定義爲code

 /// <summary>
    ///  樓層區域信息
    /// </summary>
    [Serializable]
    public class Area
    {
        /// <summary>
        ///  樣例 : 7.256476003661832E7
        /// </summary>
        [JsonProperty("area")]
        public double? AreaValue { get; set; }

        /// <summary>
        ///  邊界
        /// </summary>
        [JsonProperty("boundary")]
        public string Boundary { get; set; }

        /// <summary>
        ///  編號
        /// </summary>
        [JsonProperty("id")]
        public string Id { get; set; }

        /// <summary>
        ///  水平線編號
        /// </summary>
        [JsonProperty("levelId")]
        public string LevelId { get; set; }

        [JsonProperty("maxPt")]
        public Coordinate MaxPt { get; set; }

        [JsonProperty("minPt")]
        public Coordinate MinPt { get; set; }

        /// <summary>
        ///  對象名稱。例如:"dining room 4"
        /// </summary>
        [JsonProperty("name")]
        public string Name { get; set; }

        /// <summary>
        ///  樣例 : 40087.80000000279
        /// </summary>
        [JsonProperty("perimeter")]
        public double? Perimeter { get; set; }

        [JsonProperty("properties")]
        public PropertyGroup[] Properties { get; set; }

        /// <summary>
        ///   樣例 : "1 1"
        /// </summary>
        [JsonProperty("viewName")]
        public string ViewName { get; set; }

        /// <summary>返回表示當前對象的字符串。</summary>
        /// <returns>表示當前對象的字符串。</returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            if (Properties != null && Properties.Length > 0)
            {
                foreach (var property in Properties)
                {
                    sb.AppendLine(property.ToString());
                }
            }

            return string.Format("[area={0}, boundary={1}, id={2}, levelId={3}, maxPt={4}, minPt={5}, name={6}, perimeter={7}, properties={8}, viewName={9}]",
                                  AreaValue,  Boundary, Id, LevelId, MaxPt, MinPt, Name, Perimeter, sb, ViewName);
        }
    }

其中 Coordinate 、PropertyGroup 類請參考《C#開發BIMFACE系列17 服務端API之獲取模型數據2:獲取構件材質列表》

C#實現方法:

 1 /// <summary>
 2 ///  獲取單個模型中單個樓層對應面積分區列表
 3 /// </summary>
 4 /// <param name="accessToken">【必填】令牌</param>
 5 /// <param name="fileId">【必填】表明該單模型的文件ID</param>
 6 /// <param name="floorId">【必填】表明該單模型的樓層ID</param>
 7 /// <returns></returns>
 8 public virtual SingleModelSingleFloorAreas GetSingleModelSingleFloorAreas(string accessToken, long fileId, string floorId)
 9 {
10     // GET https://api.bimface.com/data/v2/files/{fileId}/areas
11     string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/areas?floorId={1}", fileId, floorId);
12 
13     BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
14     headers.AddOAuth2Header(accessToken);
15 
16     try
17     {
18         SingleModelSingleFloorAreas response;
19 
20         HttpManager httpManager = new HttpManager(headers);
21         HttpResult httpResult = httpManager.Get(url);
22         if (httpResult.Status == HttpResult.STATUS_SUCCESS)
23         {
24             response = httpResult.Text.DeserializeJsonToObject<SingleModelSingleFloorAreas>();
25         }
26         else
27         {
28             response = new SingleModelSingleFloorAreas
29             {
30                 Message = httpResult.RefText
31             };
32         }
33 
34         return response;
35     }
36     catch (Exception ex)
37     {
38         throw new Exception("[獲取樓層對應面積分區列表]發生異常!", ex);
39     }
40 }

其中調用到的 httpManager.Get() 方法,請參考《C# HTTP系列》

測試

在BIMFACE的控制檯中能夠看到咱們上傳的文件列表,模型狀態均爲轉換成功。

使用「bimface_2018_mdv_room.rvt」爲例測試上述方法。

在《C#開發BIMFACE系列22 服務端API之獲取模型數據7:獲取多個模型的樓層信息》中能夠查詢到該文件的樓層信息

 

下面查詢 FloorID 等於 245423 的面積分區列表

查詢到的完整的面積分區列表爲

success

[area=4480840.0410909, 
 boundary={"version":"2.0",
           "loops":[[[{"z":2999.9998798520546,"y":650.40599536995444,"x":6616.83125243813},
                      {"z":2999.9998798520546,"y":650.40599536996251,"x":4121.9313523570981}
                     ],
                     [{"z":2999.9998798520546,"y":650.40599536996251,"x":4121.9313523570981},
                      {"z":2999.9998798520546,"y":-1145.5939327014466,"x":4121.9313523570954}
                     ],
                     [{"z":2999.9998798520546,"y":-1145.5939327014466,"x":4121.9313523570945},
                      {"z":2999.9998798520546,"y":-1145.5939327014546,"x":6616.8312524381263}
                     ],
                     [{"z":2999.9998798520546,"y":-1145.5939327014546,"x":6616.8312524381263},
                      {"z":2999.9998798520546,"y":650.40599536995444,"x":6616.83125243813}
                     ]
                    ]
                  ]
           }, 
 id=1092832, 
 levelId=, 
 maxPt=[x=6616.83125243813, y=650.405995369963, z=2999.99987985205], 
 minPt=[x=4121.93135235709, y=-1145.59393270145, z=2999.99987985205], 
 name=面積 2, perimeter=8101.79967552855, properties=, viewName=
]
[area=4333552.00744229, 
 boundary={"version":"2.0",
           "loops":[[[{"z":2999.9998798520546,"y":-3201.5938503598827,"x":4505.6454184675295},
                      {"z":2999.9998798520546,"y":-3201.5938503598904,"x":7001.9312370150637}
                     ],
                     [{"z":2999.9998798520546,"y":-3302.5938463149096,"x":7001.9312370150637},
                      {"z":2999.9998798520546,"y":-1465.5939198856749,"x":7001.9312370150674}
                     ],
                     [{"z":2999.9998798520546,"y":-1465.5939198856749,"x":7001.9312370150665},
                      {"z":2999.9998798520546,"y":-1465.5939198856668,"x":4505.6454184675331}
                     ],
                     [{"z":2999.9998798520546,"y":-1465.5939198856677,"x":4505.6454184675331},
                      {"z":2999.9998798520546,"y":-3302.5938463149018,"x":4505.64541846753}
                     ]
                    ]
                   ]
          },
 id=1092841, 
 levelId=, 
 maxPt=[x=7001.93123701507, y=-1465.59391988567, z=2999.99987985205], 
 minPt=[x=4505.64541846753, y=-3302.59384631491, z=2999.99987985205], 
 name=面積 3, 
 perimeter=8104.57151246125, 
 properties=, 
 viewName=
]

測試代碼以下:

// 獲取樓層對應面積分區列表
protected void btnGetSingleModelSingleFloorAreas_Click(object sender, EventArgs e)
{
    long fileId = txtFileID.Text.Trim().ToLong();
    string floorId = txtFloorId.Text.Trim();
    FileConvertApi api = new FileConvertApi();
    SingleModelSingleFloorAreas response = api.GetSingleModelSingleFloorAreas(txtAccessToken.Text, fileId, floorId);

    txtResult.Text = response.Code.ToString2()
                   + Environment.NewLine
                   + response.Message.ToString2()
                   + Environment.NewLine
                   + response.Data.ToStringLine();
}

 

相關文章
相關標籤/搜索