代码之家  ›  专栏  ›  技术社区  ›  patrick

将Lat/long转换为PointClass

  •  1
  • patrick  · 技术社区  · 14 年前
    IPoint pPoint = new ESRI.ArcGIS.Geometry.PointClass();
    pPoint.PutCoords(-92.96000, 44.9227); //This should be near Minneapolis
    mapControl.CenterAt(pPoint); //mapControl is a AxMapControl
    

    当我运行这个代码时,这个点总是在堪萨斯附近结束。有人能帮我把lat/long转换成一个能正常工作的PointClass吗?

    2 回复  |  直到 14 年前
        1
  •  3
  •   jsmith    14 年前

    这比你现在所说的要多得多。纬度/经度点和地图都有特定的空间参照。如果它们不匹配,很可能你的观点会以一种意想不到的方式出现。

    Geographical Coordinate System . 你很可能是想在一张纸上画出这一点 Projected Coordinate System .

    因为我不知道你的地图的空间参考,我只能给你一个例子,把一个Lat/Lon转换成MapControl当前的空间参考。

    ISpatialReferenceFactory srFactory = new SpatialReferenceEnvironmentClass();
    
    IGeographicCoordinateSystem gcs = srFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
    ISpatialReference sr1 = gcs;
    
    IPoint point = new PointClass() as IPoint;
    point.PutCoords(-92.96000, 44.9227);
    
    IGeometry geometryShape;
    geometryShape = point;
    geometryShape.SpatialReference = sr1;
    
    geometryShape.Project(mapControl.SpatialReference);
    
    mapControl.DrawShape(geometryShape);
    

    这将获取点并将其投影到MapControls当前空间参照,然后打印该点。

    祝你好运。

        2
  •  0
  •   patrick    14 年前

    mapControl.MapScale = mapControl.MapScale / 2; //for zooming
    ISpatialReferenceFactory srFactory = new SpatialReferenceEnvironmentClass(); //move up top later 
    IGeographicCoordinateSystem gcs = srFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); //World lat / long format
    ISpatialReference sr1 = gcs;
    IPoint point = new PointClass(); 
    point.SpatialReference = gcs;
    point.PutCoords(-92.96000, 44.9227);
    point.Project(mapControl.SpatialReference);
    mapControl.CenterAt(point);
    
    推荐文章