RGeo 0.5.2和RGeo :: CoordSys :: SRSDatabase :: ActiveRecordTable

时间:2016-01-30 06:28:15

标签: rgeo

首先,道歉,如果这很简单,但我似乎无法弄明白。我正在使用RGeo在UTM和lat / long之间进行转换,就像这样;

 srs_database = RGeo::CoordSys::SRSDatabase::ActiveRecordTable.new

 # create the coordinate factory for the relevant UTM zone
 utm_factory = RGeo::Cartesian.factory(:srid => srid,
                                       :srs_database => srs_database)
 utm_location = utm_factory.point(easting, northing)

 # create the standard WGS84 lat/long coordinate factory
 wgs84_proj4 = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'
 wgs84_factory = RGeo::Geographic.spherical_factory(proj4: wgs84_proj4, :srid => 4326)

 # perform the UTM -> lat/long cast
 RGeo::Feature.cast(utm_location, :factory => wgs84_factory, :project => true)

如您所见,我正在使用RGeo::CoordSys::SRSDatabase::ActiveRecordTable

我刚刚升级到RGeo 0.5.2,我注意到此类已被弃用。

足够公平,但我现在不确定替代方法是什么......我已经四处寻找并且似乎无法找到正确的文档。

另外,我原来的方法对我来说似乎总是有点复杂 - 有没有更简单的方法来完成UTM - >使用RGeo进行转换/长转换?

提前致谢!

2 个答案:

答案 0 :(得分:3)

好的,实际上我很快就设法解决了这个问题。这对我有用:

 if hemisphere == 'S'
   srid = 32700 + number.to_i
   utm_proj4 = "+proj=utm +zone=#{zone} +south +datum=WGS84 +units=m +no_defs"
 else
   srid = 32600 + number.to_i
   utm_proj4 = "+proj=utm +zone=#{zone} +datum=WGS84 +units=m +no_defs"
 end

 # create both the UTM and lat / long factories (we will project between them)
 utm_factory = RGeo::Cartesian.simple_factory(srid: srid, proj4: utm_proj4)
 wgs84_factory = RGeo::Geographic.spherical_factory(srid: 4326, proj4: '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')

 # create the UTM location
 utm_location = utm_factory.point(easting, northing)

 # perform the UTM -> lat/long cast
 RGeo::Feature.cast(utm_location, :factory => wgs84_factory, :project => true)

我正在根据我从spatial_ref_sys表中提取的Proj4字符串创建自己的工厂。

我不确定这是否正确'虽然可能有更好的方法。

但我希望这有助于某人! :)

答案 1 :(得分:0)

另一种方法:

EPSG_4326 = RGeo::CoordSys::Proj4.new("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
EPSG_3857 = RGeo::CoordSys::Proj4.new("+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs")

RGeo::CoordSys::Proj4.transform(EPSG_3857, geom, EPSG_4326, RGeo::Geographic.spherical_factory)

使用适当的坐标产生新的RGeo::Geographic::SphericalPointImpl