Data Projection Transformation

Topics: Developer Forum, User Forum
May 2, 2007 at 12:40 AM
I have data that I imported from a shapefile that is in WGS84 and I need to reproject my queried data to the following proj.4 Mercator projection. I was hoping someone could help me out with this.

+proj=merc +latts=0.0 +lon0=0.0 +x0=0.0 +y0=0 +k=1.0 +ellps=sphere +a=6378137 +b=6378137 +units=m +nadgrids=@null +no_defs

Any ideas?

Thanks,
Jim
May 3, 2007 at 3:47 PM
Edited May 3, 2007 at 3:48 PM
I figured out that it helps to give your shapefile in a spatial reference when you try to import it into SQL Server. I inserted a new record into the ST.SPATIALREFSYS table that has, for the SRTEXT field the string from my prj file that ogr2ogr created when it transformed the shapefile from an obscure Albers projection, and used that newly inserted SRID. Now, from what I can tell, my calculations that I perform on the geometry seemed to be right, but their actual position, geographically, is off about 29° in latitude. The points should be around 45° latitude and -115° longitude. Instead, they are 74° latitude and -115° longitude. I had to use ogr2ogr to do the point conversions from my Mercator projection to WGS84 in my C# code. When I tried to use ST.Transform (Perimeter, 4326) I received the transformation for each record of LINESTRING (Nan Nan,Nan Nan,...)

Any ideas?...

Jim
Coordinator
May 6, 2007 at 7:50 PM
It seems you want to apply the projection used by Google Maps/Virtual Earth/Yahoo Maps. What SRTEXT did you added? Maybe you should try the following:
PROJCS["Mercator", GEOGCS["WGS84_Sphere", DATUM["WGS84_Sphere", SPHEROID["GRS 1980 Authalic Sphere", 6378137, Infinity, AUTHORITY["EPSG", "7048"]], TOWGS84[0, 0, 0, 0, 0, 0, 0]], PRIMEM["Greenwich", 0, AUTHORITY["EPSG", "8901"]], UNIT["degree", 0.0174532925199433, AUTHORITY["EPSG", "9102"]], AXIS["E", EAST], AXIS["N", NORTH]], PROJECTION["Mercator_1SP"], PARAMETER["False_Easting", 0], PARAMETER["False_Northing", 0], PARAMETER["Central_Meridian", 0], PARAMETER["Latitude_of_origin", 0], UNIT["metre", 1, AUTHORITY["EPSG", "9001"]], AXIS["East", EAST], AXIS["North", NORTH]]

As simply stated by Morten Nielsen, this uses "the same center and orientation as WGS84, but without applying any flattening".

Best regards,
Ricardo Stuven.
Jun 5, 2007 at 8:51 PM
I am sorry that I was not able to get back to you sooner, but I was sidetracked with another project. Anyway, is there any special way that I need to insert a SRTEXT? I tried just to increase the existing SRID by one (32768), AUTHName ("Custom"), AUTHSRID (32768), and I used the above for the SRTEXT. I inserted this directly into the ST.Spatial.Ref.Sys table, but when I tried to transform the points, it gives me the following error:

Msg 6522, Level 16, State 1, Line 1
A .NET Framework error occurred during execution of user-defined routine or aggregate "Transform":
System.Exception: The token 'Infinity' is not a number at line 1 column 119.
System.Exception:
at GisSharpBlog.NetTopologySuite.Converters.WellKnownText.IO.StreamTokenizer.GetNumericValue()
at GisSharpBlog.NetTopologySuite.Converters.WellKnownText.CoordinateSystemWktReader.ReadEllipsoid(WktStreamTokenizer tokenizer)
at GisSharpBlog.NetTopologySuite.Converters.WellKnownText.CoordinateSystemWktReader.ReadHorizontalDatum(WktStreamTokenizer tokenizer)
at GisSharpBlog.NetTopologySuite.Converters.WellKnownText.CoordinateSystemWktReader.ReadGeographicCoordinateSystem(WktStreamTokenizer tokenizer)
at GisSharpBlog.NetTopologySuite.Converters.WellKnownText.CoordinateSystemWktReader.ReadProjectedCoordinateSystem(WktStreamTokenizer tokenizer)
at GisSharpBlog.NetTopologySuite.Converters.WellKnownText.CoordinateSystemWktReader.ReadCoordinateSystem(String coordinateSystem, WktStreamTokenizer tokenizer)
at GisSharpBlog.NetTopologySuite.Converters.WellKnownText.CoordinateSystemWktReader.Parse(String wkt)
at GisSharpBlog.NetTopologySuite.CoordinateSystems.CoordinateSystemFactory.CreateFromWkt(String WKT)
at UserDefinedFunctions.Transform(SqlBytes ewkb, SqlInt32 target_srid)

Any ideas?

Thanks,
Jim
Jun 6, 2007 at 4:46 AM
Change the 'Infinity' value to '0' in the WKT. See the link Ricardo refers to (and not the WKT :-)
There used to be a bug in the CS part with spheric ellipsoids, which has later been resolved, by I'm not sure this has made it into MsSqlSpatial yet.
Coordinator
Jun 6, 2007 at 7:55 PM

Change the 'Infinity' value to '0' in the WKT. See the link Ricardo refers to (and not the WKT :-)

Mmh... the WKTs are not the same anymore... Did you update the article?


There used to be a bug in the CS part with spheric ellipsoids, which has later been resolved, by I'm not sure this has made it into MsSqlSpatial yet.

I will check it out...

Best regards,
Ricardo Stuven.