This project is read-only.

Problem with projection when creating shapefile from SQL Server database

Jul 19, 2013 at 1:27 AM
Edited Jul 19, 2013 at 1:28 AM
I have an ASP.NET website that allows a user to export a shapefile from one of the selected features which have geodata stored in a SQL Server 2012 database. I am able to export the shapefile successfully, however when I import it into ArcMap, the points are mis-projected onto the map (they are all about 6.6 miles to the northwest of where they should be, to be exact).

I've checked the shapefile's projection information (State Plane Oklahoma North feet), and it looks good:
PROJCS["NAD_1983_StatePlane_Oklahoma_North_FIPS_3501_Feet",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",1968500.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-98.0],PARAMETER["Standard_Parallel_1",35.56666666666667],PARAMETER["Standard_Parallel_2",36.76666666666667],PARAMETER["Latitude_Of_Origin",35.0],UNIT["Foot_US",0.3048006096012192]]
I've even checked some of the individual points and converted them to lat/lon, and they are correct. Any ideas as to why they aren't projecting right in ArcMap? It seems like the projection may just not be working at all, and not have to do with the specific State Plane coordinate system, because when I use WGS 84 I still have the same problem.

Here is the C# code I use for exporting the shapefile. Thanks!
var featureSet = new FeatureSet(FeatureType.Point);
var dt = _dataAccessLayer.GetTableByFeature(shapeFileName);

// Copy all of the columns from the database table to the feature set
for (int colIdx = 0; colIdx < dt.Columns.Count; colIdx++)
{
    var col = dt.Columns[colIdx];
    featureSet.DataTable.Columns.Add(new DataColumn(col.ColumnName, 
            col.DataType));
}

int rowIndex = 0;
foreach (DataRow row in dt.Rows)
{
    // Convert the projection from Spherical Mercator to 
    //   NAD1983 State Plane Oklahoma North (feet)
    var vertices = new double[2];
    vertices[0] = Convert.ToDouble(row[COL_X_COORD]);
    vertices[1] = Convert.ToDouble(row[COL_Y_COORD]);
    var z = new double[1];

    Reproject.ReprojectPoints(vertices, z, KnownCoordinateSystems
.Projected.WorldSpheroid.Mercatorsphere, KnownCoordinateSystems.Projected.
StatePlaneNad1983Feet.NAD1983StatePlaneOklahomaNorthFIPS3501Feet, 0, 1);
    featureSet.AddFeature(new Feature(new Coordinate(vertices[0], vertices[1])));

    // Add the rest of the attributes to the feature set
    for (int colIdx = 0; colIdx < dt.Columns.Count - colOffset; colIdx++)
    {
        featureSet.DataTable.Rows[rowIndex][colIdx] = row[colIdx + colOffset];
    }
    rowIndex++;
}

featureSet.Projection = KnownCoordinateSystems.Projected
    .StatePlaneNad1983Feet.NAD1983StatePlaneOklahomaNorthFIPS3501Feet;
featureSet.SaveAs(shapefilePath + shapeFileName, true);
Jul 22, 2013 at 7:20 PM
Ahh, hooray! Figured it out: The mapping product I'm using to map our data refers to the projection I'm using as "Popular Spherical Mercator", which led me to choose "KnownCoordinateSystems .Projected.WorldSpheroid.Mercatorsphere" as the source projection. However, the correct source projection is actually "KnownCoordinateSystems.Projected.World.WebMercator".

The mapping product uses Bing Maps as it's base imagery and from what I was finding online it seems like there's some kind of a blur between referring to the Bing/Google projections as Web Mercator or as Spherical Mercator. Perhaps someone can still enlighten me more about that, but at least as far as my shapefile is concerned, all is better now that I've switched the projection.