问题
I started with How can I transform the coordinates of a Shapefile? .
The response there started me on [what I think is] the right track, but I still haven't been able to solve my problem.
One issue is that I haven't found the correct projection yet: https://gis.stackexchange.com/questions/13330/how-can-i-correctly-transform-unproject-from-lcc
EDIT: That question on the gis site has been answered, and I was able to reproduce a correct transformation using the PROJ command line tool cs2cs. It looks like this:
larry$ cs2cs -f "%.8f" +proj=lcc +lat_1=37.06666666666667 +lat_2=38.43333333333333 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs +to +proj=lonlat +datum=WGS84 +ellps=WGS84
6011287.4999795845 2100857.2499904726
-122.40375492 37.74919006 0.00000000
Now, that I had the correct transformation, I was able to try the same thing in a simple form using RGeo:
ruby-1.9.2-p180 :001 > projection_str = ' +proj=lcc +lat_1=37.06666666666667 +lat_2=38.43333333333333 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs'
=> " +proj=lcc +lat_1=37.06666666666667 +lat_2=38.43333333333333 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs"
ruby-1.9.2-p180 :002 > projection = RGeo::CoordSys::Proj4.new(projection_str)
=> #<RGeo::CoordSys::Proj4:0x805cba18 " +proj=lcc +lat_1=37.06666666666667 +lat_2=38.43333333333333 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs +towgs84=0,0,0">
ruby-1.9.2-p180 :003 > desired_str = '+proj=lonlat +datum=WGS84 +ellps=WGS84'
=> "+proj=lonlat +datum=WGS84 +ellps=WGS84"
ruby-1.9.2-p180 :004 > desired = RGeo::CoordSys::Proj4.new(desired_str)
=> #<RGeo::CoordSys::Proj4:0x805271ac " +proj=lonlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0">
ruby-1.9.2-p180 :005 > RGeo::CoordSys::Proj4::transform_coords(projection, desired, 6011287.4999795845, 2100857.2499904726 )
=> [-140.92282523143973, 30.16981659183029]
- Why are the results different between RGeo and cs2cs?
- Once I can make RGeo perform the correct translation, is there a way I can create the proper factory to transform a complete Geometry instead of a point?
- Is there a command-line tool I can use as a workaround to transform all of the points in my shapefile so that I can move on with my life?
In general: Would someone please instruct me on how to properly use this library?
Thank you so much for looking.
回答1:
As a wild stab in the dark, because I don't know RGeo or even Ruby, try substituting your coordinates in feet with their metres equivalent: 1832244.0944819663048746863094224, 640342.57048223700783128534419392 (you probably won't need that number of decimal places though...) Another possibility is to swap the coordinates around - maybe RGeo makes some unconventional assumptions.
If you are able to call executables from Ruby, you could simply use ogr2ogr to convert your shapefiles.
来源:https://stackoverflow.com/questions/7006581/how-can-i-use-ruby-rgeo-to-transform-unproject-coordinates