Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20 km shift with SRID 32188 #48

Closed
kaligrafy opened this issue Feb 20, 2013 · 7 comments
Closed

20 km shift with SRID 32188 #48

kaligrafy opened this issue Feb 20, 2013 · 7 comments

Comments

@kaligrafy
Copy link

Hi!

I tried to convert a lat/lon geographic geometry to MTM8 (SRID 32188) and I get a 20km shift (almost 20000 meters too high) for the y, but the x is correct.

If I use directly the postgis function ST_Transform, there is no shift.

Here is the rgeo command I use to transform (the one that shifts 20km):
RGeo::Feature.cast(geometry_attribute, :factory => RGeo::Cartesian.factory(:srs_database => RGeo::CoordSys::SRSDatabase::ActiveRecordTable.new, :srid => 32188), :project => true)

Thanks for any cue!

@kaligrafy
Copy link
Author

I think the problem comes from the projection. If I project srid 4326 on itself:

RGeo::Feature.cast(geometry_attribute, :factory => RGeo::Cartesian.factory(:srs_database => RGeo::CoordSys::SRSDatabase::ActiveRecordTable.new, :srid => 4326), :project => true)

I get the same shift (0.2 degrees north)

Is it possible that there is a bug that first projects the geographic (that should not happen) and than project to geometry? Or maybe the factory isn't right...

@kaligrafy
Copy link
Author

For testing:

SELECT ST_AsText(ST_Transform(ST_GeomFromText('POINT(-73.700666 45.528719)',4326), 32188))
RESULT => POINT(289125.877396516 5043219.80782975)

wgs84_factory = RGeo::Geographic.spherical_factory(:srid => 4326)
RGeo::Feature.cast(wgs84_factory.point(-73.700666, 45.528719), :factory => RGeo::Cartesian.factory(:srs_database => RGeo::CoordSys::SRSDatabase::ActiveRecordTable.new, :srid => 32188), :project => true)
RESULT => RGeo::Geos::CAPIPointImpl:0x3ff7fea7bcb0 "POINT (289179.3064137901 5064562.79613934)"

There is also a small shift with x. But the y shift is huge!!!
Comparison:
X: 289179 vs 289126
Y: 5064563 vs 5043220 (that's 21 km!!!)

@patrickespake
Copy link

+1
I have the same problem.

Any solution?

@ddd1600
Copy link

ddd1600 commented Jun 26, 2014

You do things a different way than I do, but if I wanted to convert geographic coordinates into (what are presumably) geometric coordinates, I'd do this:

lat, lng = -73.700666, 45.528719
srid = new_crs_srid = 32188
proj4 = new_crs_proj4 = "+proj=tmerc +lat_0=0 +lon_0=-73.5 +k=0.9999 +x_0=304800 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs " ##obtained from spatialreference.org
f = new_crs_factory = RGeo::Geographic.projected_factory(:projection_proj4 => proj4, :projection_srid => srid)
geom_shape_32188 = f.parse_wkt("POINT (#{lng} #{lat})").projection
#=> #<RGeo::Geos::CAPIPointImpl:0x3fe49ee7c404 "POINT (289125.8773965159 5043219.807829753)"> 

Is that correct now? (checking, yes, it is. hehe you're welcome)

@patrickespake
Copy link

I tried it, but don't work for me:

[5] pry(main)> geom_shape_32188 = f.parse_wkt("POINT (#{lng} #{lat})").projection
ArgumentError: wrong number of arguments (0 for 2+)
from /Users/patrickespake/.rvm/gems/ruby-2.1.1@quality-maps/gems/rgeo-0.3.20/lib/rgeo/geos/capi_factory.rb:352:in `point'

@kaligrafy
Copy link
Author

lat and lon are reversed...

@keithdoggett
Copy link
Member

keithdoggett commented Oct 11, 2020

I tried @ddd1600's solution (while flipping lat/lon) and it worked. This issue is very old and a lot has changed in the library since then, so I'm going to close but if this still isnt' working, please open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants