refactor: 重构项目结构,将geo_tools重命名为app并更新相关引用
- 将主包名从geo_tools改为app - 更新所有模块中的引用路径 - 迁移并更新测试用例 - 添加项目规则文档 - 保持原有功能不变,仅进行结构调整
This commit is contained in:
@@ -7,14 +7,21 @@ from pathlib import Path
|
||||
# 添加项目根目录到路径
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
import geo_tools
|
||||
import app
|
||||
|
||||
gdb_path = r"E:\@三普\@临时文件夹\临时数据库.gdb"
|
||||
gdb_path = r"E:\@三普\@临时文件夹\临时数据库.gdb\马关综合后图斑"
|
||||
shp_path = r"E:\@三普\@临时文件夹\新建文件夹\靖西二普样点\AK.shp"
|
||||
shp = r"E:\@三普\@临时文件夹\新建文件夹\靖西二普样点"
|
||||
|
||||
gdb = r"E:\@三普\@临时文件夹\新建文件地理数据库.gdb"
|
||||
|
||||
# 列出图层
|
||||
# layers = geo_tools.list_gdb_layers(gdb_path)
|
||||
# layers = geo_tools.readers.list_gdb_layers(gdb_path)
|
||||
# print(layers)
|
||||
|
||||
# 读取图层
|
||||
gdf = geo_tools.read_gdb(gdb_path, layer="马关综合后图斑")
|
||||
print(gdf.crs)
|
||||
gdf = app.readers.read_vector(gdb_path)
|
||||
print(gdf.crs)
|
||||
# 获取几何类型
|
||||
print(gdf.head())
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import pytest
|
||||
import geopandas as gpd
|
||||
from shapely.geometry import Point, Polygon
|
||||
|
||||
from geo_tools.analysis.spatial_ops import overlay, select_by_location
|
||||
from geo_tools.analysis.stats import area_weighted_mean, count_by_polygon, summarize_attributes
|
||||
from app.analysis.spatial_ops import overlay, select_by_location
|
||||
from app.analysis.stats import area_weighted_mean, count_by_polygon, summarize_attributes
|
||||
|
||||
|
||||
class TestOverlay:
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
import pytest
|
||||
from shapely.geometry import LineString, Point, Polygon
|
||||
|
||||
import geo_tools
|
||||
from geo_tools.core.geometry import (
|
||||
import app
|
||||
from app.core.geometry import (
|
||||
buffer_geometry,
|
||||
bounding_box,
|
||||
centroid,
|
||||
|
||||
@@ -4,8 +4,8 @@ import pytest
|
||||
import geopandas as gpd
|
||||
from pathlib import Path
|
||||
|
||||
from geo_tools.io.readers import read_vector, read_gpkg, list_gpkg_layers, read_csv_points
|
||||
from geo_tools.io.writers import write_vector, write_gpkg, write_csv
|
||||
from app.io.readers import read_vector, read_gpkg, list_gpkg_layers, read_csv_points
|
||||
from app.io.writers import write_vector, write_gpkg, write_csv
|
||||
|
||||
|
||||
class TestReadVector:
|
||||
@@ -61,7 +61,7 @@ class TestWriteReadRoundtrip:
|
||||
assert "geometry" in df.columns # 存在 WKT 几何列
|
||||
assert len(df) == len(sample_points_gdf) # 行数一致
|
||||
# 再用 read_csv_points 以 WKT 模式读回
|
||||
from geo_tools.io.readers import _read_csv_vector
|
||||
from app.io.readers import _read_csv_vector
|
||||
from pathlib import Path
|
||||
gdf_back = _read_csv_vector(Path(out), wkt_col="geometry")
|
||||
assert len(gdf_back) == len(sample_points_gdf)
|
||||
|
||||
@@ -3,19 +3,31 @@ import os
|
||||
os.environ["OGR_ORGANIZE_POLYGONS"] = "SKIP"
|
||||
|
||||
from pathlib import Path
|
||||
import geopandas as gpd
|
||||
|
||||
|
||||
# 添加项目根目录到路径
|
||||
project_root = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
import geo_tools
|
||||
from geo_tools.core import projection
|
||||
from geo_tools.config.project_enum import CRS
|
||||
import app
|
||||
from app.core import projection
|
||||
from app.config.project_enum import CRS
|
||||
|
||||
info = projection.get_crs_info(CRS.CGCS2000_6_DEGREE_ZONE_18.value)
|
||||
print(info)
|
||||
print(type(CRS.CGCS2000_3_DEGREE_ZONE_27))
|
||||
input_folder = r"E:\@三普\@二普和测土配方样点处理\云南省"
|
||||
output_folder = r"E:\@三普\@二普和测土配方样点处理\云南省_投影转换"
|
||||
|
||||
# aa = geo_tools.read_vector(r"E:\@三普\@临时文件夹\样点异常值剔除\容县\异常样点数据\AB_outliers.shp")
|
||||
# projection.reproject_gdf(aa,CRS.CGCS2000_3_DEGREE_ZONE_37).to_file(r"E:\@三普\@临时文件夹\样点异常值剔除\容县\AB_ou.shp")
|
||||
for root, dirs, files in os.walk(input_folder):
|
||||
for file in files:
|
||||
if file.endswith(".shp"):
|
||||
input_path = os.path.join(root, file)
|
||||
output_path = os.path.join(output_folder, os.path.relpath(input_path, input_folder))
|
||||
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
||||
|
||||
gdf = gpd.read_file(input_path)
|
||||
if gdf.crs is not None:
|
||||
reproject_gdf = projection.reproject_gdf(gdf, auto_crs=True)
|
||||
reproject_gdf.to_file(output_path)
|
||||
print("Reprojected CRS:", reproject_gdf.crs)
|
||||
else:
|
||||
print("No CRS information found.")
|
||||
@@ -4,7 +4,7 @@ import pytest
|
||||
import geopandas as gpd
|
||||
from shapely.geometry import Point
|
||||
|
||||
from geo_tools.core.vector import (
|
||||
from app.core.vector import (
|
||||
add_area_column,
|
||||
clip_to_extent,
|
||||
dissolve_by,
|
||||
|
||||
Reference in New Issue
Block a user