function coordinateTransformation(x, y) { var steps = new GeographicTransformationStep() steps.wkt = 'GEOGTRAN["Xian_1980_To_WGS_1984",' + 'GEOGCS["GCS_Xian_1980",DATUM["D_Xian_1980",SPHEROID["Xian_1980",6378140.0,298.257]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],' + 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],' + 'METHOD["Position_Vector"],PARAMETER["X_Axis_Translation",115.8],PARAMETER["Y_Axis_Translation",-154.4],PARAMETER["Z_Axis_Translation",-82.3],PARAMETER["X_Axis_Rotation",0.0],PARAMETER["Y_Axis_Rotation",0.0],PARAMETER["Z_Axis_Rotation",0.0],PARAMETER["Scale_Difference",8]]' var geographicTransformation = new GeographicTransformation({ steps: [steps] }) var inSpatialReference = new SpatialReference({ wkid: 2385 //Sphere_Sinusoidal }) var outSpatialReference = new SpatialReference({ wkid: 4326 }) let arr = [] projection.load().then(function() { var wgsPoints = new Point([x, y], inSpatialReference) var ttt = projection.project(wgsPoints, outSpatialReference, geographicTransformation) arr.push(ttt.x, ttt.y) console.log(arr, '0000') }) return arr }
时间: 2024-04-25 13:26:33 浏览: 34
这段代码定义了一个名为coordinateTransformation的函数,用于将给定的坐标点从一个空间参考系投影到另一个空间参考系。该函数接受两个参数,即坐标点的经度(x)和纬度(y)。函数内部首先创建了一个GeographicTransformationStep对象,用于指定空间参考系转换的具体方法,然后创建了一个GeographicTransformation对象,将GeographicTransformationStep对象添加到steps数组中,作为空间参考系转换的步骤。
接下来,该函数创建了两个SpatialReference对象,用于指定输入和输出的空间参考系。其中,inSpatialReference对象指定了输入坐标点的空间参考系为Sphere_Sinusoidal,outSpatialReference对象指定了输出坐标点的空间参考系为WGS 1984。
最后,该函数使用ArcGIS API的projection模块将输入坐标点从inSpatialReference投影到outSpatialReference,使用GeographicTransformation对象指定的空间参考系转换方法进行转换。转换后得到的坐标点存储在ttt变量中,并将其x和y坐标分别添加到数组arr中。最终,该函数返回arr数组,其中包含转换后的坐标点的x和y坐标。
相关问题
points_coordinate = np.random.rand(num_points, 2) # generate coordinate of points distance_matrix = spatial.distance.cdist(points_coordinate, points_coordinate, metric='euclidean')是什么意思
这段代码使用了NumPy库和Scipy库中的spatial模块,主要实现了两个功能:
1. 生成随机坐标点
``` python
points_coordinate = np.random.rand(num_points, 2)
```
这行代码使用了NumPy库中的`rand`函数,生成指定数量(`num_points`)的包含两个随机值的二维数组,这些随机值的范围是[0, 1)。
2. 计算坐标点间的欧几里得距离
``` python
distance_matrix = spatial.distance.cdist(points_coordinate, points_coordinate, metric='euclidean')
```
这行代码使用了Scipy库中的spatial模块中的`cdist`函数,计算了随机生成的坐标点之间的欧几里得距离,并将这些距离保存在一个二维数组`distance_matrix`中。其中,`metric='euclidean'`参数表示使用欧几里得距离作为计算距离的方式。
通过这段代码,你可以得到一个包含随机坐标点和它们之间欧几里得距离的数据结构,这个数据结构可以用于各种需要坐标点和它们之间距离信息的任务。
还是报错 merged_sheet[cell.coordinate]._style = cell._style.copy() # 复制格式信息 AttributeError: 'StyleArray' object has no attribute 'copy'
很抱歉,我的回答有误。在 openpyxl 3.x 版本中,`_style` 属性被移除了。正确的做法是使用 `cell.style` 属性来复制单元格的格式信息,而不是使用 `_style`。
以下是修改后的代码:
```python
import openpyxl
# 读取所有要合并的表格,将它们存储在一个列表中
workbooks = ['workbook1.xlsx', 'workbook2.xlsx', 'workbook3.xlsx']
sheets = []
for workbook in workbooks:
wb = openpyxl.load_workbook(workbook)
for sheet_name in wb.sheetnames:
sheet = wb[sheet_name]
sheets.append(sheet)
# 创建一个新的工作簿,并复制第一个表格到其中
merged_workbook = openpyxl.Workbook()
merged_sheet = merged_workbook.active
merged_sheet.title = sheets[0].title
for row in sheets[0].rows:
for cell in row:
merged_sheet[cell.coordinate].value = cell.value
merged_sheet[cell.coordinate].style = cell.style.copy() # 复制格式信息
# 将其他表格的内容复制到新工作簿中
for sheet in sheets[1:]:
new_sheet = merged_workbook.create_sheet(title=sheet.title)
for row in sheet.rows:
for cell in row:
new_sheet[cell.coordinate].value = cell.value
new_sheet[cell.coordinate].style = cell.style.copy() # 复制格式信息
# 保存新工作簿
merged_workbook.save('merged_workbook.xlsx')
```
在这个版本的代码中,我们使用了 `cell.style.copy()` 方法来复制单元格的格式信息,而不是使用 `_style` 属性。这样可以正确地复制单元格的填充颜色等格式。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)