ai_project_v1/touying/read_hongxian_file.py

351 lines
10 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
import uuid
from scipy.constants import point
from shapely.creation import points
from touying.ImageReproject_python.img_types import Point
# from Ai_tottle.touying.ImageReproject_python import Point
def generate_unique_id():
"""生成唯一ID"""
return str(uuid.uuid4())
def process_geojson_data(file_path):
try:
with open(file_path, 'r', encoding='utf-8') as f:
data = json.load(f)
# # 处理数据
# processed_data = process_geojson_data(data)
# print(processed_data)
# 写入输出文件
# with open(output_file, 'w', encoding='utf-8') as f:
# json.dump(processed_data, f, ensure_ascii=False, indent=2)
#
# print(f"数据处理完成,结果已保存到 {output_file}")
except FileNotFoundError:
print(f"错误:文件 {file_path} 未找到")
except json.JSONDecodeError:
print("错误文件内容不是有效的JSON格式")
except Exception as e:
print(f"发生未知错误: {str(e)}")
"""处理GeoJSON数据添加唯一ID"""
processed_data = {
"Point": [],
"LineString": [],
"Polygon": []
}
count = 0
# 处理Point数据
for point in data.get("Point", []):
new_point = point.copy()
# new_point["id"] = generate_unique_id()
new_point["coordinates"].append(count)
count=count+1
processed_data["Point"].append(new_point)
# 处理LineString数据
for line in data.get("LineString", []):
new_line = line.copy()
new_line["id"] = generate_unique_id()
for point in new_line["coordinates"]:
point.append(count)
count = count + 1
processed_data["LineString"].append(new_line)
# 处理Polygon数据
for polygon in data.get("Polygon", []):
new_polygon = polygon.copy()
new_polygon["id"] = generate_unique_id()
for point in new_polygon["coordinates"]:
point.append(count)
count = count + 1
processed_data["Polygon"].append(new_polygon)
return processed_data
def convert_processed_to_points(processed_data):
local_points = []
count=0
if processed_data["Point"] is not None and len(processed_data["Point"]) > 0:
for v in processed_data["Point"]:
if v["coordinates"] is not None and len(v["coordinates"]) > 0:
y = float(v["coordinates"][0]) # 103.99211191
x = float(v["coordinates"][1]) # 30.76381946
z = float(v["coordinates"][2]) # 高程
point_id = v["coordinates"][3]
point1 = Point(x, y, z, point_id)
count=count+1
local_points.append(point1)
if processed_data["LineString"] is not None and len(processed_data["LineString"]) > 0:
for v in processed_data["LineString"]:
if v["coordinates"] is not None and len(v["coordinates"]) > 0:
for vv in v["coordinates"]:
y = float(vv[0]) # 103.99211191
x = float(vv[1]) # 30.76381946
z = float(vv[2]) # 高程
point_id = vv[3]
point1 = Point(x, y, z, point_id)
count = count + 1
local_points.append(point1)
if processed_data["Polygon"] is not None and len(processed_data["Polygon"]) > 0:
for v in processed_data["Polygon"]:
if v["coordinates"] is not None and len(v["coordinates"]) > 0:
for vv in v["coordinates"]:
y = float(vv[0]) # 103.99211191
x = float(vv[1]) # 30.76381946
z = float(vv[2]) # 高程
point_id = vv[3]
point1 = Point(x, y, z, point_id)
count = count + 1
local_points.append(point1)
return local_points
def add_result_to_prcessdata(processed_data, result):
if processed_data["Point"] is not None and len(processed_data["Point"]) > 0:
for v in processed_data["Point"]:
if v["coordinates"] is not None and len(v["coordinates"]) >0:
# y = float(v["coordinates"][0]) # 103.99211191
# x = float(v["coordinates"][1]) # 30.76381946
# z = float(v["coordinates"][2]) # 高程
# point_id = v["id"]
# point1 = Point(x, y, z, point_id)
# local_points.append(point1)
for re in result:
if v["coordinates"][3] == re["id"]:
v["re"] = re
#
# point1 = {
# "u": 10,
# "v": 10,
# "id": 41
# }
# point2 = {
# "u": 1910,
# "v": 10,
# "id": 42
# }
# point3 = {
# "u": 10,
# "v": 540,
# "id": 41
# }
# point4 = {
# "u": 1910,
# "v": 540,
# "id": 41
# }
# point5 = {
# "u": 0,
# "v": 1070,
# "id": 41
# }
# point6 = {
# "u": 1910,
# "v": 1070,
# "id": 41
# }
# point7 = {
# "u": 960,
# "v": 540,
# "id": 41
# }
# processed_data["Point"].append({
# "re":point1
# })
# processed_data["Point"].append({
# "re":point2
# })
# processed_data["Point"].append({
# "re":point3
# })
# processed_data["Point"].append({
# "re":point4
# })
# processed_data["Point"].append({
# "re":point5
# })
# processed_data["Point"].append({
# "re":point6
# })
# processed_data["Point"].append(
# {
# "coordinates": [
# 103.9925256,
# 30.76395247,
# 471.192,
# 5
# ],
# "fillStyle": "red",
# "radius": 7,
# "comment": "point6",
# "re": {
# "u": 0,
# "v": 1070,
# "id": 41
# }
# }
# )
#
# processed_data["Point"].append(
# {
# "coordinates": [
# 103.9925256,
# 30.76395247,
# 471.192,
# 5
# ],
# "fillStyle": "red",
# "radius": 7,
# "comment": "point6",
# "re": {
# "u": 10,
# "v": 10,
# "id": 42
# }
# }
# )
#
# processed_data["Point"].append(
# {
# "coordinates": [
# 103.9925256,
# 30.76395247,
# 471.192,
# 5
# ],
# "fillStyle": "red",
# "radius": 7,
# "comment": "point6",
# "re": {
# "u": 1910,
# "v": 10,
# "id": 43
# }
# }
# )
#
# processed_data["Point"].append(
# {
# "coordinates": [
# 103.9925256,
# 30.76395247,
# 471.192,
# 5
# ],
# "fillStyle": "red",
# "radius": 7,
# "comment": "point6",
# "re": {
# "u": 10,
# "v": 540,
# "id": 44
# }
# }
# )
#
# processed_data["Point"].append(
# {
# "coordinates": [
# 103.9925256,
# 30.76395247,
# 471.192,
# 5
# ],
# "fillStyle": "red",
# "radius": 7,
# "comment": "point6",
# "re": {
# "u": 1910,
# "v": 540,
# "id": 45
# }
# }
# )
#
# processed_data["Point"].append(
# {
# "coordinates": [
# 103.9925256,
# 30.76395247,
# 471.192,
# 5
# ],
# "fillStyle": "red",
# "radius": 7,
# "comment": "point6",
# "re": {
# "u": 1910,
# "v": 1070,
# "id": 46
# }
# }
# )
#
# processed_data["Point"].append(
# {
# "coordinates": [
# 103.9925256,
# 30.76395247,
# 471.192,
# 5
# ],
# "fillStyle": "red",
# "radius": 7,
# "comment": "point6",
# "re": {
# "u": 960,
# "v": 540,
# "id": 47
# }
# }
# )
if processed_data["LineString"] is not None and len(processed_data["LineString"]) > 0:
for v in processed_data["LineString"]:
if v["coordinates"] is not None and len(v["coordinates"]) > 0:
v["re"] = []
#
# y = float(vv[0]) # 103.99211191
# x = float(vv[1]) # 30.76381946
# z = float(vv[2]) # 高程
# point_id = v["id"]
# point1 = Point(x, y, z, point_id)
# local_points.append(point1)
for re in result:
for vv in v["coordinates"]:
if vv[3]== re["id"]:
v["re"].append(re)
# if v["coordinates"][3] == re["id"]:
# v["re"].append(re)
if processed_data["Polygon"] is not None and len(processed_data["Polygon"]) > 0:
for v in processed_data["Polygon"]:
if v["coordinates"] is not None and len(v["coordinates"]) > 0:
v["re"] = []
for re in result:
for vv in v["coordinates"]:
if vv[3]== re["id"]:
v["re"].append(re)
# if v["coordinates"][3] == re["id"]:
# v["re"].append(re)
return processed_data