将纬度/经度转换为 PointClass

发布于 2024-09-16 00:44:15 字数 311 浏览 7 评论 0原文

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

当我运行此代码时,该点总是在堪萨斯附近结束。谁能帮我将纬度/经度转换为可以正常工作的 PointClass?

我正在使用 VS2010 ArcEngine 10 C#

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

When I run this code the point always ends up near Kansas. Can anyone help me convert lat / longs to an PointClass that will work properly?

I'm using VS2010 ArcEngine 10 C#

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

無處可尋 2024-09-23 00:44:15

这比你目前给出的要多得多。纬度/经度点和您的地图都有特定的空间参考。如果它们不匹配,你的观点很可能会以意想不到的方式表达。

您显示的点是标准纬度/经度点。可能是 Nad83(北美)或 WGS84(世界)。这些是具有地理坐标系的空间参考。您可能试图在投影坐标系。

您需要使 MapControl 的空间参考与您尝试绘制的点类型相匹配。

由于我不知道您的地图的空间参考,因此我只能给您一个将纬度/经度转换为 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 当前空间参考,然后绘制该点。

祝你好运。

There is a lot more to this than you have currently given. Both a lat/long point and your map have a specific spatial reference. If they do not match, it is likely your point will plot in an unexpected way.

The point you are showing is a standard Latitude/Longitude point. Which is likely Nad83 (North American), or WGS84 (World). These are Spatial References with a Geographical Coordinate System. You are likely trying to plot the point on a Projected Coordinate System.

You need to make your MapControl's Spatial Reference match the types of points you are trying to plot.

Since I do not know the Spatial Reference of your Map, I can only give you an example of translating a Lat/Lon into what the MapControl's current spatial reference is.

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);

This takes your point and projects it to the MapControls current spatial reference, then plots the point.

Good Luck.

知足的幸福 2024-09-23 00:44:15

这是缩放并以纬度/经度为中心的代码,上面的海报很有帮助,但他的解决方案对我不起作用。

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);

Here is the code to zoom and center on a lat / long, the above poster was helpful but his solution did not work for me.

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文