我正在建立一个系统,让用户上传shapefile。然后,它使用shp2pgsql将这些shapefile转换为PostGIS。此命令需要EPSG代码形式的SRS ID。
因此,我需要一个ruby gem,它可以读取shapefile的*.prj文件(它包含编码为WKT的投影/空间参考系统)并返回相应的SRS。
发布于 2011-10-17 03:48:32
我不确定Ruby绑定到GDAL是如何工作的,但是OSR (GDAL的一部分)可以提取投影WKT (文本)或SRID (整数)。
有关Python/GDAL/OSR的解决方案,请参阅this gis.SE answer。
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发布于 2012-09-13 12:16:37
仅供参考,http://prj2epsg.org/允许您查找PRJ文件并获取SRID / EPSG代码。
更新:站点已关闭。请看这个答案:https://gis.stackexchange.com/questions/372381/is-there-an-alternative-to-prj2epsg-org
https://stackoverflow.com/questions/7751470
复制相似问题