在python中加入shapefile,改变其投影坐标系并输出shapefile。

问题描述 投票:0回答:1

我试图在python 3.7中沿着一个共同的属性(ZCTA邮编号)将两个文件连接起来,然后输出一个包含沿着ZCTA连接的shapefile,并添加属性Manufa_EMP(制造业就业),然后改变投影坐标系(PCS或CRS)。然而下面代码输出的shapefile却把输出的文件的地理投影的比例和大小搞乱了。当我在ArcMap中把shapfile作为地图上的一个图层打开,并与第一次导入的shapefile进行比较时,输出的shapfile的投影小了很多很多。有人知道为什么会出现这种情况吗?

import sys
import pandas as pd
import geopandas as gpd
import numpy

# Set Working Directory
sys.path.append(r"G:\MAX-Filer\Collab\Labs-kbuzard-S18\Admin\Block Level Analysis")

# Read in gz.csv file as "ZCTA" Table
Table = pd.read_csv('DEC_00_SF3_DP3_with_ann.csv', skiprows = 1)

# Create new table "ZCTA_Manufa" with only Block ID and Total employment columns
Tab2 = Table.loc[:,["Id2", "Number; Employed civilian population 16 years and over - INDUSTRY - Manufacturing"]].values

# renaming headers
Tab2 = pd.DataFrame(data=Tab2, columns=["ZCTA5CE00", "Manufa_Emp"])

# Import Shapefile
zips = r"G:\MAX-Filer\Collab\Labs-kbuzard-S18\Admin\Block Level Analysis\tl_2010_06_zcta500.shp"
data = gpd.read_file(zips)

# To join the two together
Table3 = data.merge(Tab2, on='ZCTA5CE00')

zFeatures = gpd.read_file(zips).filter(['Manufa_Emp', 'ZCTA5CE00', 'geometry'], axis = 1)

# Set geometry and CRS
geometry = zFeatures.geometry
geo_df = gpd.GeoDataFrame(Table3, geometry = geometry)
geo_df.crs = {'init':'epsg:5070'}

# Export out as a shapefile
result = ("CA_ZCTA_Man.shp")
geo_df.to_file(result)
pandas python-3.7 shapefile geopandas arcmap
1个回答
0
投票

将GeoDataFrame投射到另一个CRS中,使用的方法是 .to_crs(). 你不能随便分配,那样只会覆盖现有的投影元数据,而不会改变几何体。

所以下面这行。

geo_df.crs = {'init':'epsg:5070'}

应该是这样的

geo_df = geo_df.to_crs('epsg:5070')  # EPSG number would be enough
© www.soinside.com 2019 - 2024. All rights reserved.