首页 / 浏览问题 / 组件GIS / 问题详情
关于Python调用iobjectpy的问题
8EXP 2024年07月26日

使用产品:python3.6.5、iobjectsjava-11.1.1、supermap-iobjectspy-11.1.1 操作系统:win11 x64
问题详细描述:使用python IDLE调用iobjectpy写了一个读取字段属性信息的脚本,运行后出现类似许可问题的报错。我现在使用的是公有云许可,想问问这个问题该如何解决?
问题重现步骤:

1.python脚本

from iobjectspy import *

def get_data(input_shapefile, field_name, array):
    # 打开数据源
    ds = open_datasource(input_shapefile)
    if ds is None:
        print("打开数据源失败")
        return
    
    # 获取数据集
    dataset = ds.first_dataset
    if dataset is None:
        print("数据源中没有数据集")
        return
    
    # 检查字段名是否存在
    if field_name not in dataset.fields:
        print(f"字段名 {field_name} 不存在于数据集中")
        return
    
    # 遍历数据集
    for feature in dataset:
        value = feature.get_attribute(field_name)
        array.append(value)
    
    # 关闭数据源
    ds.close()

# 示例使用
data_dir = "D:\SuperMap\datasource\model_1.udbx"
input_shapefile = os.path.join(data_dir, "道路受监控范围.shp")
field_name = "SmArea"
array = []

get_data(input_shapefile, field_name, array)

print(array)

2.cmd弹窗 

3.idle报错内容

[iObjectsPy]: The Gateway service started successfully

Traceback (most recent call last):
  File "C:\Python36\test\get_data.py", line 35, in <module>
    get_data(input_shapefile, field_name, array)
  File "C:\Python36\test\get_data.py", line 5, in get_data
    ds = open_datasource(input_shapefile)
  File "I:\teamctiy\BuildAgent\work\test_111x/iobjectspy/_jsuperpy\data\ws.py", line 1221, in open_datasource
  File "I:\teamctiy\BuildAgent\work\test_111x/iobjectspy/_jsuperpy\data\ws.py", line 389, in __new__
  File "C:\Python36\lib\site-packages\py4j\java_gateway.py", line 1323, in __call__
    answer, self.gateway_client, self.target_id, self.name)
  File "C:\Python36\lib\site-packages\py4j\protocol.py", line 328, in get_return_value
    format(target_id, ".", name), value)
py4j.protocol.Py4JJavaError: An error occurred while calling z:com.supermap.jsuperpy.RegisterWorkspace.newPythonWorkspace.
: java.lang.RuntimeException: hasp_container_not_found

	at com.supermap.jsuperpy.RegisterWorkspace.newPythonWorkspace(RegisterWorkspace.java:31)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

	at java.base/java.lang.reflect.Method.invoke(Method.java:566)

	at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)

	at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)

	at py4j.Gateway.invoke(Gateway.java:282)

	at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)

	at py4j.commands.CallCommand.execute(CallCommand.java:79)

	at py4j.GatewayConnection.run(GatewayConnection.java:238)

	at java.base/java.lang.Thread.run(Thread.java:834)

1个回答

您好,看您这个报错,是许可没读取到;

如果是试用的话,可以尝试使用文件许可试试;

希望能帮助到您
855EXP 2024年07月29日

感谢回复heart,还想追问一下,试用的文件许可在哪里获取?

我已获取试用文件许可,也完成了激活更新和许可导入操作,但代码执行依旧报错(同一个错误),是否需要将它安装在某个位置才可以进行使用?
许可文件应该在C:\Program Files\Common Files\SuperMap\License目录,检查下有没有,没有放进去
...