Convert from ESPG 4326 to ESPG 3758

123 Views Asked by At

I am having a problem with converting geometry data in my rails application project. Currently, I am having one database storing data with SRID 4326 and I need to move it to another database that uses SRID 3758. I am using RGeo library and I have no idea how can it convert to a different SRID.

irb(main):031:0> Location.find_by(zip_code: "02020406").geom
#<RGeo::Geos::CAPIPointImpl:0xf9b0 "POINT (103.1408295 13.09251827)">
irb(main):031:0> Location.find_by(zip_code: "02020406").geom.srid
4326

To

irb(main):031:0> Location.find_by(zip_code: "02020406").geom
#<RGeo::Geos::CAPIMultiPointImpl:0xf690 "MULTIPOINT ((11481584.619935852 1470304.24217379))">
irb(main):031:0> Location.find_by(zip_code: "02020406").geom.srid
3758
1

There are 1 best solutions below

0
Sokmesa Khiev On

Finally, I found a solution as below

gem "rgeo-proj4"

My implentation

geom = Location.find_by(zip_code: "02020406").geom
factory_3758 = RGeo::Geographic.projected_factory(projection_proj4:"EPSG:3857", projection_srid: 3857)                                                                                                                                                                                                                        
geom_3857 = factory_3758.point(geom.x, geom.y)                                                                                                               
RGeo::Feature.cast(geom_3857.projection, type: RGeo::Feature::MultiPoint)