Question re: .prj files

Topics: General Topics
Nov 22, 2006 at 11:05 PM
When I try assign a shapefile as a datasource using the code in the transformation page (demo site) as a guide I can't do it when I use it has a .prj with this form of data:
PROJCS"NAD_1983_StatePlane_Connecticut_FIPS_0600_Feet",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",999999.999996],PARAMETER["False_Northing",499999.999998],PARAMETER["Central_Meridian",-72.75],PARAMETER["Standard_Parallel_1",41.2],PARAMETER["Standard_Parallel_2",41.86666666666667],PARAMETER["Latitude_Of_Origin",40.83333333333334],UNIT["Foot_US",0.30480060960121924]

I can do it successfully with this .prj file:
GEOGCS"GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]

Obviously I'm missing something here -- could someome offer some guidance or point me to a resource. Thank you -- and also a huge thank you for the effort you have put into this. It is an awesome toolset.
Nov 23, 2006 at 2:02 AM
You can't do it??!? Please be more specific
Nov 23, 2006 at 2:30 AM
Here's the .prj I'm using for this test:
PROJCS"NAD_1983_StatePlane_Connecticut_FIPS_0600_Feet",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",999999.999996],PARAMETER["False_Northing",499999.999998],PARAMETER["Central_Meridian",-72.75],PARAMETER["Standard_Parallel_1",41.2],PARAMETER["Standard_Parallel_2",41.86666666666667],PARAMETER["Latitude_Of_Origin",40.83333333333334],UNIT["Foot_US",0.30480060960121924]

Here's a code snippet:
SharpMap.Data.Providers.ShapeFile datasource = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\Appdata\bg09d00.shp"), true);
layCountries.DataSource = datasource;
datacoordsys = datasource.CoordinateSystem;

//Set fill-style to green
layCountries.Style.Fill = new SolidBrush(Color.Green);
//Set the polygons to have a black outline
layCountries.Style.Outline = System.Drawing.Pens.Black;
layCountries.Style.EnableOutline = true;
layCountries.CoordinateTransformation = Transform2Mercator(datacoordsys);

After the call to Transform2Mercator I get an error, "Geographic Coordinate system was null" on this line:
IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Mercator", source as IGeographicCoordinateSystem, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

All of the code above (with slight modifications came from the transformation.aspx.cs demo file. I'm running the 09Prod release.

Thanks for looking into this and please let me know if you need any additional info.
Nov 23, 2006 at 8:04 AM
You should read the error literally to get an idea on what is going on:
"Geographic Coordinate system was null"
Since the method you are calling expects a geograchic coordinate system, it might be getting a null.

So why is it getting a null????

The 'AS' keyword either return the object as that object if could cast it, or as null if it couldn't convert it to null. So looking at 'source as IGeographicCoordinateSystem' gives you the indication that 'source' is not implementing IGeographicCoordinateSystem and thus cannot be cast to that object.

Looking at your WKT I would think you are parsing a projected coordinate system to a function that expects a geographics coordinate system. A projected coordinate system cannot be cast into a geograpchic coordinate system.

You might want to read up on the basics of coordinate systems, datums and projections before venturing into this world.
Nov 23, 2006 at 1:06 PM
Thank you for your detailed reply -- I can see it clearly now. No doubt I need a better understanding of the basics but I'm also trying to grasp this framework and how to use it. Your explanation was extremely helpful. I can now layer a census block group shapefile on top of a virtual earth application and this works at lightning speed (especially when compared to the AddPolygon feature of virtual earth).