sharpmap 2.0 坐标系转换 更新

来源:互联网 发布:sqlserver添加字段 编辑:程序博客网 时间:2024/06/15 21:44

sharpmap 2.0的坐标系统没有多弄懂,至于屏幕坐标如何转map 坐标,个人仅仅使用空间建立对应坐标关机,进行计算。


借鉴 网上一篇文章,http://hi.baidu.com/zhouyang027/item/59633425770bd953c28d595b

但是似乎开源代码总是更新。写上自己的修改后的 代码

ICoordinateFactory<Coordinate> coordinatefactory = new CoordinateFactory();



            ICoordinateSystemFactory<Coordinate> cFac = new CoordinateSystemFactory<Coordinate>(coordinatefactory,geometryfactory);
            IEllipsoid ellipsoid = cFac.CreateFlattenedSphere( 6377563.396, 299.32496, LinearUnit.Meter,"Airy 1830");
            IHorizontalDatum datum = cFac.CreateHorizontalDatum(DatumType.HorizontalGeocentric, ellipsoid, null,"Airy 1830");
            //创建地理坐标系


            Coordinate min = coordinatefactory.Create(-180, -90);
            Coordinate max = coordinatefactory.Create(180, 90);
            IExtents<Coordinate> wgs84Extents = geometryfactory.CreateExtents(min, max);
            IGeographicCoordinateSystem gcs =
                cFac.CreateGeographicCoordinateSystem(wgs84Extents, AngularUnit.Degrees, datum,
                                                      PrimeMeridian.Greenwich,
                                                      new AxisInfo( AxisOrientation.East,"Lon"),
                                                      new AxisInfo( AxisOrientation.North,"Lat"),"Airy 1830");
            //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5);
            IList<ProjectionParameter> parameters = new List<ProjectionParameter>();
            parameters.Add(new ProjectionParameter("latitude_of_origin", 49));
            parameters.Add(new ProjectionParameter("central_meridian", -2));
            parameters.Add(new ProjectionParameter("scale_factor", 0.9996012717));
            parameters.Add(new ProjectionParameter("false_easting", 400000));
            parameters.Add(new ProjectionParameter("false_northing", -100000));
             IProjection projection = cFac.CreateProjection("Transverse Mercator", parameters ,"Transverse_Mercator");
            IProjectedCoordinateSystem coordsys =
                cFac.CreateProjectedCoordinateSystem( gcs, projection,
                                                     LinearUnit.Meter, new AxisInfo( AxisOrientation.East,"East"),
                                                     new AxisInfo( AxisOrientation.North,"North"),"OSGB 1936 / British National Grid");
            ICoordinateTransformation trans = ctff.CreateFromCoordinateSystems(gcs, coordsys);
              //new CoordinateTransformationFactory<Coordinate>().CreateFromCoordinateSystems(gcs, coordsys);
            //Coordinate workpoint = new Point(e.X, e.Y);


            Coordinate workpoint = new CoordinateFactory().Create(e.X, e.Y);
            ICoordinate pUtm = trans.MathTransform.Transform(workpoint);
            IPoint click = geometryfactory.CreatePoint(pUtm);
            ICoordinate pGeo2 = trans.MathTransform.Inverse.Transform(pUtm);
原创粉丝点击