NAD83 (CA, Zone III) to WGS84 Projection Conversion Issues

Jan 21, 2010 at 9:15 PM

I'm trying to convert a shapefile from the NAD83 (State Plane) projection to the WGS84 (Lat/Long) Projection, but the calculation isn't coming out correctly. My code and results are below:

 

using SharpMap.CoordinateSystems;
using SharpMap.CoordinateSystems.Transformations;
using SharpMap.Data.Providers.ShapeFile;
using SharpMap.Geometries;
CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();
private string wkt4326 = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]]";
private string wkt2227 = "PROJCS[\"NAD_1983_StatePlane_California_III_FIPS_0403_Feet\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199432955]],PROJECTION[\"Lambert_Conformal_Conic\"],PARAMETER[\"False_Easting\",6561666.666666666],PARAMETER[\"False_Northing\",1640416.666666667],PARAMETER[\"Central_Meridian\",-120.5],PARAMETER[\"Standard_Parallel_1\",37.06666666666667],PARAMETER[\"Standard_Parallel_2\",38.43333333333333],PARAMETER[\"Latitude_Of_Origin\",36.5],UNIT[\"Foot_US\",0.304800609601219241]]";
ShapeFileProvider sf = null;
StringBuilder sb = new StringBuilder();
ICoordinateSystem cs2227 = SharpMap.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt2227) as ICoordinateSystem;
ICoordinateSystem cs4326 = SharpMap.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt4326) as ICoordinateSystem;
ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(cs2227, cs4326);
try
{
    sf = new ShapeFileProvider(selectedFilePath);
    sf.Open(false);
    if (sf.ShapeType == ShapeType.Polygon)
    {
        int counter = 0;
        BoundingBox ext = sf.GetExtents();
        IEnumerable<Geometry> geometries = sf.ExecuteGeometryIntersectionQuery(ext);
        foreach (Geometry geometry in geometries)
        {
            Polygon polygon = geometry as Polygon;
            if (polygon != null)
            {
                sb.Append("SET @polygon" + counter + " = geometry::STGeomFromText('");
                sb.Append("POLYGON((");
                int totalVertices = polygon.ExteriorRing.Vertices.Count;
                Point pt0 = trans.MathTransform.Transform(polygon.ExteriorRing.Vertices[0]);
                for (int i = 0; i < totalVertices; i++)
                {
                    Point pt1 = trans.MathTransform.Transform(polygon.ExteriorRing.Vertices[i]);
                    sb.Append(pt1.X + " " + pt1.Y);
                    sb.Append(",");
                }
                sb.Append(pt0.X + " " + pt0.Y);
                sb.Append("))");
                sb.Append("', 4326);");
            }
            sb.Append(Environment.NewLine);
            counter++;
        }
    }
}
finally
{
    if (sf != null) { sf.Close(); }
}
return sb.ToString();

My results:

Input: 6139949.19 , 1938696.8 (Easting / Northing)

Output: -125.37538163521, 39.0883958914316

Correct: -121.9501208, 37.3102349

Any help would be greatly appreciated. I've tried using the OGR2OGR tool from FWTools, but I get a very cryptic error, so I've abandoned that effort.

Thanks!

Coordinator
Feb 7, 2010 at 3:56 PM

Proj.NET does not automatically apply the datum shift. You must specify the TOWGS84 parameter manually. Note that this value might change from place to place (it's rarely a constant value and various from place to place)