1

我正在构建一个允许用户上传 shapefile 的系统。然后它将这些 shapefile 转换为 PostGIS,使用shp2pgsql. 此命令需要 EPSG 代码形式的 SRS ID。

所以我需要一个可以读取 shapefile*.prj文件(其中包含编码为 WKT 的投影/空间参考系统)并返回相应 SRS ID 的 ruby​​ gem。

4

2 回答 2

2

我不确定 Ruby 绑定如何对 GDAL 起作用,但 OSR(GDAL 的一部分)可以提取投影 WKT(文本)或 SRID(整数)。

有关 Python/GDAL/OSR 的解决方案,请参阅此 gis.SE 答案

更新:事实证明 Ruby 绑定按预期工作得很好。为了让您继续前进,请尝试以下代码:

require 'gdal/osr'

prj_fname = 'myfile.prj'
prj = File.open( prj_fname )

# Import the WKT from the PRJ file
srs = Gdal::Osr::SpatialReference.new()
srs.import_from_wkt( prj.read )

# Various exports
puts srs.export_to_wkt

srs.auto_identify_epsg
puts srs.get_authority_name(nil)
puts srs.get_authority_code(nil)

如果您需要投影的其他方面,请探索可用的公共方法:

srs.public_methods.sort
于 2011-10-16T19:48:32.170 回答
2

仅供参考,http ://prj2epsg.org/可让您查找 PRJ 文件并获取 SRID / EPSG 代码。

更新:网站已关闭。看到这个答案:https ://gis.stackexchange.com/questions/372381/is-there-an-alternative-to-prj2epsg-org

于 2012-09-13T04:16:37.127 回答