-1

我在带有 CRS 的 shapefile 中有一个数据集:EPSG 3035,其范围是 xmax、xmin、ymax、ymin。我正在努力将其翻译成 long 和 lat 格式。你知道如何解决这个问题吗?

谢谢

4

1 回答 1

0

您可以使用名为GeoPandas的库在 Python 中执行此操作。这是示例代码:

# Imports the library
import geopandas as gpd

# String that points to the location of the
# shapefile on disk
input_file = 'path\to\file.shp'

# String that contains the filename of the 
# new/transformed shapefile
output_file = 'path\to\new_file.shp'

# Creates a GeoDataFrame which you can manipulate
my_data = gpd.read_file(input_file)

# Transforms the data to the new reference system
new_data = my_data.to_crs('epsg:4326')

# Exports the newly-created file
new_data.to_file(output_file)

如果您想在 R 中执行此操作,以下是相应的代码:

# Install spatial data packages
install.packages("rgdal")

# Load spatial data packages
library(rgdal)

# String that points to the location of the
# input shapefile on disk
input_file = 'path/to/file/my_shapefile.shp'

# Strings that point to the filename of the 
# new/transformed shapefile that will be generated
output_folder = 'path/to/file'
output_file   = 'new_shapefile.shp'

# Creates a SpatialLinesDataFrame which you can manipulate
my_data = readOGR(input_file)

# Transforms the data to the new reference system
new_data = spTransform(my_data,CRS("+init=epsg:4326"))

# Exports the newly-created file
writeOGR(new_data, dsn=output_folder,layer=output_file, driver="ESRI Shapefile")
于 2021-05-20T19:30:11.977 回答