how to use GeoProjection or how can I change the projection of a shapefile

May 8, 2013 at 4:06 AM
Hi all,
In my project, I open .shp files converted by Universal Translator from MapInfo Tab,
Everything is good,
But There is a problem that has troubled me for a long time:
In higher latitude places the gis map looks Flat...
I guess this is the geo projection Problem, so i tried the GeoProjection operations of Shapefile:

my code is here, It doesn't work, however i try~~
(I'm using MapWinGis.ocx 4.8.6,)
Shapefile sf = new Shapefile();
if (sf.Open("D:\demoshp.shp", null))
{
    GeoProjection proj = new GeoProjection();
    bool bset = proj.ImportFromESRI("PROJCS[\"WGS_1984_Web_Mercator_Auxiliary_Sphere\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223562997]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]], PROJECTION[\"Mercator_Auxiliary_Sphere\"],PARAMETER[\"False_Easting\",0],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",0],PARAMETER[\"Standard_Parallel_1\",0],PARAMETER[\"Scale_Factor\",1],PARAMETER[\"Latitude_Of_Origin\",0],PARAMETER[\"Auxiliary_Sphere_Type\",0.0],UNIT[\"Meter\",1]]");
    if(bset)
    {
      sf.GeoProjection = proj;
      int hnd = mapControl.AddLayer(sf, true);
    }
          
}
I also used ReprojectInPlace function, it doesn't work either...
// 
sf.StartEditingShapes(true, null);
int ct =0;
sf.ReprojectInPlace(proj, ref ct);//always return false
Any way out?
thanks a lot
Coordinator
May 8, 2013 at 8:08 AM
First you need to give your source shapefile the correct projection, like you do in your first snippet.
Next your can reproject your shapefile to another projection.
If ReprojectInPlace returns false you can get the error message using sf.get_ErrorMsg(sf.lastErrorCode));
You might also want to look at the specific projection error message in the GlobalSettings class.
Look at http://svn.mapwindow.org/svnroot/TestingScripts/TestReprojectShapefile.cs for some inspiration.

Paul
May 8, 2013 at 9:33 AM
pmeems wrote:
First you need to give your source shapefile the correct projection, like you do in your first snippet.
Next your can reproject your shapefile to another projection.
If ReprojectInPlace returns false you can get the error message using sf.get_ErrorMsg(sf.lastErrorCode));
You might also want to look at the specific projection error message in the GlobalSettings class.
Look at http://svn.mapwindow.org/svnroot/TestingScripts/TestReprojectShapefile.cs for some inspiration.

Paul
Thank you for your suggestion, yes, it works, the map gis no longer looks Flat now, great !
while, another problem is here,
the longi/lati i got is not as before...(-180,180),
in the following codes:
double projX = 0;
double projY = 0;
axMap.PixelToProj(pntSrc.X, pntSrc.Y, ref projX, ref projY);
the result projX,projY got a very big value, like 20195892.447378647,2509140.245386349...
i guess the new value is of a new projection,but all the data in my program use normal longi/lati,
how can i handle it?