【问题标题】:Translate EPSG 3035 to EPSG 4326(lon lat) from shapefile从 shapefile 将 EPSG 3035 转换为 EPSG 4326(lon lat)
【发布时间】:2021-08-09 22:43:57
【问题描述】:

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

谢谢

【问题讨论】:

    标签: shapefile epsg


    【解决方案1】:

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

    # 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")
    

    【讨论】:

    • 您好!我已经在 R 中添加了相关代码。如果这回答了您的问题,请单击左侧的复选标记并“接受”答案 =)
    猜你喜欢
    • 1970-01-01
    • 2021-08-28
    • 2014-04-27
    • 2021-11-10
    • 2017-10-14
    • 1970-01-01
    • 2016-09-28
    • 2022-01-08
    • 1970-01-01
    相关资源
    最近更新 更多