//单点-正投影 public PointF GetXYFromLatLon(PointF pointOrg, MapHandle.config.ProjPara proj) { pointOrg.X = (float)(pointOrg.X * DEG2RAD); pointOrg.Y = (float)(pointOrg.Y * DEG2RAD); //投影参数初始化 IntPtr pj = ProjWrapper.pj_init_plus(getSrcProj(proj)); projUV temp = new projUV(pointOrg.X, pointOrg.Y); projUV coord = ProjWrapper.pj_fwd(temp, pj); PointF pointPrj = new PointF(); pointPrj.X = (float)(coord.U); pointPrj.Y = (float)(coord.V); return(pointPrj); }
//单点-反投影 public PointF GetLatLonFromXY(PointF pointXY, MapHandle.config.ProjPara proj) { //投影参数初始化 PointF result = new PointF(); IntPtr pj = ProjWrapper.pj_init_plus(getSrcProj(proj)); projUV temp = new projUV(pointXY.X, pointXY.Y); projUV coord = ProjWrapper.pj_inv(temp, pj); result.X = (float)(coord.U); result.Y = (float)(coord.V); result.X = (float)(result.X * RAD2DEG); result.Y = (float)(result.Y * RAD2DEG); return(result); }
//从ProjPara参数中获取Proj4的投影参数 string getSrcProj(MapHandle.config.ProjPara proj) { string srcproj = ""; //获取投影方式对应的index int projType = getProjNum(proj.type); switch (projType) { case 1: //等经纬 srcproj = ProjParam("latlong", ProjectionAPI.Setting.ProjParamSetting.Ellps.WGS84, ProjectionAPI.Setting.ProjParamSetting.Daunm.WGS84, proj.std_paralle1, proj.std_paralle2, proj.center_lon, proj.false_easting, proj.false_northing, ProjectionAPI.Setting.ProjParamSetting.Units.m, proj.scale_factor, "-1"); break; case 2: //麦卡托 srcproj = ProjParam("merc", ProjectionAPI.Setting.ProjParamSetting.Ellps.WGS84, ProjectionAPI.Setting.ProjParamSetting.Daunm.WGS84, proj.std_paralle1, proj.std_paralle2, proj.center_lon, proj.false_easting, proj.false_northing, ProjectionAPI.Setting.ProjParamSetting.Units.m, proj.scale_factor, "-1"); break; case 3: //lambert srcproj = ProjParam("lcc", ProjectionAPI.Setting.ProjParamSetting.Ellps.WGS84, ProjectionAPI.Setting.ProjParamSetting.Daunm.WGS84, proj.std_paralle1, proj.std_paralle2, proj.center_lon, proj.false_easting, proj.false_northing, ProjectionAPI.Setting.ProjParamSetting.Units.m, proj.scale_factor, "-1"); //srcproj = "+proj=lcc +lat_1=25 +lat_2=47 +lat_0= 36 +lon_0=115 +x_0=0 +y_0=0 "; break; case 4: //stereographic srcproj = ProjParam("stere", ProjectionAPI.Setting.ProjParamSetting.Ellps.WGS84, 90.0f, proj.std_paralle1, proj.std_paralle2, proj.center_lon, proj.false_easting, proj.false_northing, ProjectionAPI.Setting.ProjParamSetting.Units.m, 1.0, "-1"); break; case 5: //albers srcproj = ProjParam("aea", ProjectionAPI.Setting.ProjParamSetting.Ellps.WGS84, ProjectionAPI.Setting.ProjParamSetting.Daunm.WGS84, proj.std_paralle1, proj.std_paralle2, proj.center_lon, proj.false_easting, proj.false_northing, ProjectionAPI.Setting.ProjParamSetting.Units.m, proj.scale_factor, "-1"); break; case 6: //Gauss srcproj = ProjParam("gstmerc", ProjectionAPI.Setting.ProjParamSetting.Ellps.WGS84, ProjectionAPI.Setting.ProjParamSetting.Daunm.WGS84, proj.std_paralle1, proj.std_paralle2, proj.center_lon, proj.false_easting, proj.false_northing, ProjectionAPI.Setting.ProjParamSetting.Units.m, proj.scale_factor, "-1"); break; case 7: //utm srcproj = ProjParam("utm", ProjectionAPI.Setting.ProjParamSetting.Ellps.WGS84, ProjectionAPI.Setting.ProjParamSetting.Daunm.WGS84, proj.std_paralle1, proj.std_paralle2, proj.center_lon, proj.false_easting, proj.false_northing, ProjectionAPI.Setting.ProjParamSetting.Units.m, proj.scale_factor, "-1"); break; } return(srcproj); }
public VectorLayer getSHPLayer(string layername, string fullPath, Color color, int lineWidth, MapHandle.config.ProjPara pjPara) { VectorLayer vl = new VectorLayer(layername); vl.DataSource = new ShapeFile(fullPath); vl.Enabled = true; vl.Style.Fill = new SolidBrush(Color.Transparent); vl.Style.Outline = new Pen(color, 0.4f); vl.Style.Line.Width = lineWidth; vl.Style.Line.Color = color; vl.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; vl.Style.EnableOutline = true; //设置投影参数 vl.CoordinateTransformation = pj.getmapTransform(pjPara); //vl.Envelope. return(vl); }
//add shp public void addSHPLayer(string layername, string fullPath, Color color, int width, MapHandle.config.ProjPara pjPara) { SHPLayer shplayer = new SHPLayer(); //shplayer.getCFG(cfg); mapControl1.addSHP(shplayer.getSHPLayer(layername, fullPath, color, width, pjPara)); }
//从ProjPara参数中获取坐标系 string getSrcCoordinate(MapHandle.config.ProjPara proj) { string srcproj = ""; //获取投影方式对应的index int projType = getProjNum(proj.type); if (projType == 1) { //等经纬投影 srcproj = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_84\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]"; } if (projType == 2) { //麦卡托投影 string wktparam2 = "PROJCS[\"Mercator-projection\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_84\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Mercator\"],PARAMETER[\"False_Easting\"," + proj.false_easting.ToString() + "],PARAMETER[\"False_Northing\"," + proj.false_northing.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"longitude_of_center\"," + proj.center_lon.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"latitude_of_center\"," + proj.center_lat.ToString() + "],PARAMETER[\"standard_parallel_1\"," + proj.std_paralle1.ToString() + "], PARAMETER[\"standard_parallel_2\", " + proj.std_paralle2.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"central_meridian\"," + proj.cen_meridian.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"latitude_of_origin\"," + proj.latitude_origin.ToString() + "], PARAMETER[\"scale_factor\", " + proj.scale_factor.ToString() + "], UNIT[\"Meter\", " + proj.unit.ToString() + "]]"; srcproj += wktparam2; } else if (projType == 3) { //lambert投影 string wktparam2 = "PROJCS[\"Lambert-projection\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_84\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"False_Easting\"," + proj.false_easting.ToString() + "],PARAMETER[\"False_Northing\"," + proj.false_northing.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"longitude_of_center\"," + proj.center_lon.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"latitude_of_center\"," + proj.center_lat.ToString() + "],PARAMETER[\"standard_parallel_1\"," + proj.std_paralle1.ToString() + "], PARAMETER[\"standard_parallel_2\", " + proj.std_paralle2.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"central_meridian\"," + proj.cen_meridian.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"latitude_of_origin\", " + proj.latitude_origin.ToString() + "], PARAMETER[\"scale_factor\", " + proj.scale_factor.ToString() + "], UNIT[\"Meter\", " + proj.unit.ToString() + "]]"; srcproj += wktparam2; } else if (projType == 5) { //Albers投影 string wktparam2 = "PROJCS[\"Albers-projection\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_84\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Albers\"],PARAMETER[\"False_Easting\"," + proj.false_easting.ToString() + "],PARAMETER[\"False_Northing\"," + proj.false_northing.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"longitude_of_center\"," + proj.center_lon.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"standard_parallel_1\"," + proj.std_paralle1.ToString() + "], PARAMETER[\"standard_parallel_2\", " + proj.std_paralle2.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"latitude_of_origin\", " + proj.latitude_origin.ToString() + "], PARAMETER[\"scale_factor\", " + proj.scale_factor.ToString() + "], UNIT[\"Meter\", " + proj.unit.ToString() + "]]"; srcproj += wktparam2; } else if (projType == 6) //未使用 { //高斯投影 string wktparam2 = "PROJCS[\"utm-projection\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_84\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\"," + proj.false_easting.ToString() + "],PARAMETER[\"False_Northing\"," + proj.false_northing.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"longitude_of_center\"," + proj.center_lon.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"standard_parallel_1\"," + proj.std_paralle1.ToString() + "], PARAMETER[\"standard_parallel_2\", " + proj.std_paralle2.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"central_meridian\"," + proj.cen_meridian.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"latitude_of_origin\", " + proj.latitude_origin.ToString() + "], PARAMETER[\"scale_factor\", " + proj.scale_factor.ToString() + "], UNIT[\"Meter\", " + proj.unit.ToString() + "]]"; srcproj += wktparam2; } else if (projType == 7)//未使用 { //UTM投影 string wktparam2 = "PROJCS[\"World_Robinson\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_84\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Robinson\"],PARAMETER[\"False_Easting\"," + proj.false_easting.ToString() + "],PARAMETER[\"False_Northing\"," + proj.false_northing.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"longitude_of_center\"," + proj.center_lon.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"standard_parallel_1\"," + proj.std_paralle1.ToString() + "], PARAMETER[\"standard_parallel_2\", " + proj.std_paralle2.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"central_meridian\"," + proj.cen_meridian.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"latitude_of_origin\", " + proj.latitude_origin.ToString() + "], PARAMETER[\"scale_factor\", " + proj.scale_factor.ToString() + "], UNIT[\"Meter\", " + proj.unit.ToString() + "]]"; srcproj += wktparam2; } else if (projType == 4) { //极射赤面 string wktparam2 = "PROJCS[\"Stereographic\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_84\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Stereographic\"],PARAMETER[\"False_Easting\"," + proj.false_easting.ToString() + "],PARAMETER[\"False_Northing\"," + proj.false_northing.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"longitude_of_center\"," + proj.center_lon.ToString() + "]"; srcproj += wktparam2; wktparam2 = ",PARAMETER[\"latitude_of_center\"," + proj.center_lat.ToString() + "]"; srcproj += wktparam2; wktparam2 = ", PARAMETER[\"scale_factor\", " + proj.scale_factor.ToString() + "], UNIT[\"Meter\", " + proj.unit.ToString() + "]]"; srcproj += wktparam2; } return(srcproj); }