跳转至

STK Data Type

这里做一些 STK基础数据类型 的介绍

Enum

  • 调用库: STK Object Model modules (e.g. agi.stk12.stkobjects)
  • 继承自: Python本身的 IntEnum / IntFlag
  • 使用方式: 通过 | 将Enum中的不同元素进行连接
Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from agi.stk12.stkobjects import AgESTKObjectType
# AgESTKObjectType is a enum: AgESTKObjectType = [a, b, c, d, ...]

fac = ObjectRoot.CurrentScenario.Children.New(AgESTKObjectType.eFacility, "fac1")

from agi.stk12.graphics import AgEStkGraphicsCylinderFill
# AgEStkGraphicsCylinderFill = [a, b, c, d, ...]

# AgEStkGraphicsCylinderFill inherits from IntFlag and may be combined
cyl_fill = AgEStkGraphicsCylinderFill.eStkGraphicsCylinderFillBottomCap | AgEStkGraphicsCylinderFill.eStkGraphicsCylinderFillTopCap

Array

  • 继承自: Python本身的 List
Python
1
2
3
4
5
6
7
from agi.stk12.stkdesktop import STKDesktop
from agi.stk12.stkutil import AgEExecMultiCmdResultAction

stk = STKDesktop.StartApplication()

connect_commands = ['GetStkVersion /', 'New / Scenario ExampleScenario'] #use a list of strings
command_results = stk.ExecuteMultipleCommands(commands, AgEExecMultiCmdResultAction.eContinueOnError)

Interfaces and Classes

有一套规范的写法,类似于这样:

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from agi.stk12.stkobjects import AgFacility, AgESTKObjectType

try:
# this facility is not a valid STK reference
my_facility_attempt = AgFacility()
my_facility_attempt.HeightAboveGround = 123.4
except STKRuntimeError as e:
print(e)

# this facility represents a valid STK object
my_facility = AgFacility(ObjectRoot.CurrentScenario.Children.New(AgESTKObjectType.eFacility, "fac1"))
my_facility.HeightAboveGround = 123.4
Tip

AgFacility(ObjectRoot.CurrentScenario.Children.New(AgESTKObjectType.eFacility, "fac1"))

这种写法是怎么记住的???

思考: 为什么上面这种写法不对

Python
1
2
my_facility_attempt = AgFacility()
my_facility_attempt.HeightAboveGround = 123.4

这段代码的问题在于, 它试图创建一个独立的 AgFacility 对象,而不将其与 STK 场景中的任何实际对象关联起来AgFacility() 构造函数在这里被调用,但是没有提供任何 STK 对象来初始化这个 `Python 对象。

因此,当你试图通过 my_facility_attempt.HeightAboveGround = 123.4 访问或修改对象的属性时,STK 运行时环境无法找到对应的 STK 对象,从而引发 STKRuntimeError。

简而言之,这种方式创建的 AgFacility 只是一个 Python 对象,它并没有在 STK 场景中实际存在。

Collections

These classes have an Item() method that may be used to get an indexed item from the collection, but they also support Python indexing and iteration.

Python
1
2
3
4
5
6
7
8
9
from agi.stk12.stkdesktop import STKDesktop
from agi.stk12.stkutil import AgEExecMultiCmdResultAction
stk = STKDesktop.StartApplication()

connect_commands = ['GetStkVersion /', 'New / Scenario ExampleScenario']
command_results = stk.Root.ExecuteMultipleCommands(connect_commands, AgEExecMultiCmdResultAction.eContinueOnError)

first_message = command_results.Item(0) # iterator format
also_first_message = command_results[0] # index format

对于这类数组而言,既可以通过下标访问,也可以通过迭代器访问 🔥

Tuple

有些函数返回值不止一个数,而是多个,因此我们要使用 元组(tuple) 进行接收

Python
1
(x, y, z) = my_facility.Position.QueryCartesian()

Colors

Color class represents an opaque color constructed from RGB values in the range [0, 255].

Python
1
2
3
4
5
6
from agi.stk12.utilities.colors import Color, Colors
fac = ObjectRoot.CurrentScenario.Children.New(AgESTKObjectType.eFacility, "fac1")

fac.Graphics.Color = Colors.Blue
fac.Graphics.Color = Color.FromRGB(127, 255, 212)
(r, g, b) = fac.Graphics.Color.GetRGB()

Data Types for Data Analysis

  • NumPy arrays
  • Pandas DataFrame

跟着官网把里面例子跑一遍就行了,没啥技术含量