AE中的坐标系统转换

在搞AE开发的时候,经常碰到的一个问题就是不同坐标系统之间的转换,AE中IGlobeControl控件中提供了IGlobeViewUtil类实现了大地坐标、屏幕坐标和地理坐标三者之间的转换,IMapControl中则提供了ToMapPoint和FromMapPoint两种方法实现屏幕坐标和地理坐标之间的转换,但在实际开发中,这些转换还不够,比如当我们需要实现地理坐标转换到自定义格式的大地坐标时,上述方法则不能解决这些问题,最好的解决方法是使用IGeometry对象的 Project方法,实现不同空间参照系之间的相互转换。以下以地理坐标转为自定义的Albers坐标系统为例予以说明,其主要用到的接口有 ISpatialReferenceFactory、IProjectedCoordinateSystem、IProjectedCoordinateSystemEdit、ISpatialReferenceFactory、IGeographicCoordinateSystem 、ISpatialReference 等:
        其C#代码如下:
        //将任意坐标系统转换为自定义Albers大地坐标(米)
        public static IPoint GeoToGra(IPoint point)
        {
            IPoint pt = new PointClass();
            pt.PutCoords(point.X,point.Y);

            ISpatialReferenceFactory2 pFact = new SpatialReferenceEnvironmentClass();

            //定义地理坐标,由输入的对象决定,也可以自己定义,参考: esriSRGeoCSType
            IGeographicCoordinateSystem pGCS = new GeographicCoordinateSystemClass();
            pGCS = pFact.CreateGeographicCoordinateSystem(point.SpatialReference.FactoryCode);
           
            //自定义投影方式
            IProjectedCoordinateSystem pProjectedCS = new ProjectedCoordinateSystemClass();
            IProjectedCoordinateSystemEdit pProjectedCSEdit = pProjectedCS as IProjectedCoordinateSystemEdit;

            //定义投影方式,参考: esriSRProjectionType
            IProjection pProjection = new ProjectionClass();
            pProjection = pFact.CreateProjection((int)esriSRProjectionType.esriSRProjection_Albers);

            //定义投影单位,参考: esriSRUnitType
            ILinearUnit pUnit = new LinearUnitClass();
            pUnit = pFact.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter) as ILinearUnit;

            //定义其他参数,参考: esriSRParameterType
            IParameter[] pParm = new IParameter[6];
            pParm[0] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseEasting);
            pParm[0].Value = 0;

            pParm[1] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseNorthing);
            pParm[1].Value = 0;

            pParm[2] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_CentralMeridian);
            pParm[2].Value = 110;

            pParm[3] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_StandardParallel1);
            pParm[3].Value = 25;

            pParm[4] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_StandardParallel2);
            pParm[4].Value = 47;

            pParm[5] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_LatitudeOfOrigin);
            pParm[5].Value = 0;

            //设置投影相关信息
            object name = "User_Defined_Albers";
            object alias = "Albers";
            object abbreviation = "Albers";
            object remarks = "User_Defined_Albers is the projection";
            object usage = "";
            object gcs = pGCS;
            object projectedUnit = pUnit;
            object projection = pProjection;
            object parameters = pParm;
            pProjectedCSEdit.Define(ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref gcs, ref  projectedUnit, ref projection, ref parameters);

            //获取自定义空间参考
            ISpatialReference pSpatialRef = pProjectedCS as ISpatialReference;
           
            IGeometry pGeometry = (IGeometry)pt;
            pGeometry.SpatialReference = pGCS as ISpatialReference;

            //重投影处理
            pGeometry.Project(pSpatialRef);

            return pt;
        }
       
        //将平面坐标转换为地理坐标WGS1984(经纬度)
        public static IPoint GetGeo(IGeometry pg)
        {
            IPoint pt = new PointClass();
            pt.PutCoords(pg.Envelope.XMax, pg.Envelope.YMax);    //这里IGeometry对象可换成IPoint等对象
            ISpatialReferenceFactory2 spatialReferenceFact = new SpatialReferenceEnvironmentClass();
            IGeometry geo = (IGeometry)pt;
            geo.SpatialReference = spatialReferenceFact.CreateProjectedCoordinateSystem(pg.SpatialReference.FactoryCode);
            ISpatialReference pSR = spatialReferenceFact.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
            geo.Project(pSR);              
            return pt;
        }

       以上实现可以参考ESRI提供的相关帮助示例文档:
                IProjectedCoordinateSystemEdit_Define_ExampleCreateParameter_Example
                ISpatialReferenceFactory_ExampleCreateProjection_ExampleCreateUnit_Example
                CreateGeographicCoordinateSystem_ExampleCreateProjectedCoordinateSystem_Example

      自定义不同的坐标系统,需要设置不同的参数,所有的地图投影都必须有FalseEasting 和 FalseNorthing两个参数,每种不同投影的其他参数的参数如下所示,具体参照: IProjectedCoordinateSystemEdit Interface

Aitoff
CentralMeridian

Albers
CentralMeridian
StandardParallel1
StandardParallel2
LatitudeOfOrigin

Azimuthal_Equidistant
CentralMeridian
LatitudeOfOrigin

Behrmann
CentralMeridian

Bonne
CentralMeridian
StandardParallel1

Cassini
CentralMeridian
ScaleFactor
LatitudeOfOrigin

Craster_Parabolic
CentralMeridian

Cylindrical_Equal_Area
CentralMeridian
StandardParallel1

Double_Stereographic
CentralMeridian
ScaleFactor
LatitudeOfOrigin

Eckert_I
CentralMeridian

Eckert_II
CentralMeridian

Eckert_III
CentralMeridian

Eckert_IV
CentralMeridian

Eckert_V
CentralMeridian

Eckert_VI
CentralMeridian

Equidistant_Conic
CentralMeridian
StandardParallel1
StandardParallel2
LatitudeOfOrigin

Equidistant_Cylindrical
CentralMeridian
StandardParallel1

Flat_Polar_Quartic
CentralMeridian

Gall_Stereographic
CentralMeridian

Gauss_Kruger
CentralMeridian
ScaleFactor
LatitudeOfOrigin

Gnomonic
LongitudeOfCenter
LatitudeOfCenter

Hammer_Aitoff
CentralMeridian

Hotine_Oblique_Mercator_Azimuth_Center
ScaleFactor
Azimuth
LongitudeOfCenter
LatitudeOfCenter

Hotine_Oblique_Mercator_Azimuth_Natural_Origin
ScaleFactor
Azimuth
LongitudeOfCenter
LatitudeOfCenter

Hotine_Oblique_Mercator_Two_Point_Center
LatitudeOf1st
LatitudeOf2nd
ScaleFactor
LongitudeOf1st
LongitudeOf2nd
LatitudeOfCenter

Hotine_Oblique_Mercator_Two_Point_Natural_Origin
LatitudeOf1st
LatitudeOf2nd
ScaleFactor
LongitudeOf1st
LongitudeOf2nd
LatitudeOfCenter

Krovak
PseudoStandardParallel1
ScaleFactor
Azimuth
LongitudeOfCenter
LatitudeOfCenter
XScaleFactor
YScaleFactor
Rotation

Lambert_Azimuthal_Equal_Area
CentralMeridian
LatitudeOfOrigin

Lambert_Conformal_Conic
CentralMeridian
StandardParallel1
StandardParallel2
ScaleFactor
LatitudeOfOrigin

Local
ScaleFactor
Azimuth
LongitudeOfCenter
LatitudeOfCenter

Loximuthal
CentralMeridian
CentralParallel

Mercator
CentralMeridian
StandardParallel1

Miller_Cylindrical
CentralMeridian

Mollweide
CentralMeridian

New_Zealand_Map_Grid
LongitudeOfOrigin
LatitudeOfOrigin

Orthographic
LongitudeOfCenter
LatitudeOfCenter

Plate_Carree
CentralMeridian

Polyconic
CentralMeridian
LatitudeOfOrigin

Quartic_Authalic
CentralMeridian

Rectified_Skew_Orthomorphic_Center
ScaleFactor
Azimuth
LongitudeOfCenter
LatitudeOfCenter
Rotation

Rectified_Skew_Orthomorphic_Natural_Origin
ScaleFactor
Azimuth
LongitudeOfCenter
LatitudeOfCenter
Rotation

Robinson
CentralMeridian

Robinson_ARC_INFO
CentralMeridian

Sinusoidal
CentralMeridian

Stereographic
CentralMeridian
ScaleFactor
LatitudeOfOrigin

Stereographic_North_Pole
CentralMeridian
StandardParallel1

Stereographic_South_Pole
CentralMeridian
StandardParallel1

Times
CentralMeridian

Transverse_Mercator
CentralMeridian
ScaleFactor
LatitudeOfOrigin

Transverse_Mercator_Complex
CentralMeridian
ScaleFactor
LatitudeOfOrigin

Two_Point_Equidistant
LatitudeOf1st
LatitudeOf2nd
LongitudeOf1st
LongitudeOf2nd

Van_der_Grinten_I
CentralMeridian

Vertical_Near_Side_Perspective
LongitudeOfCenter
LatitudeOfCenter
Height

Winkel_I
CentralMeridian
StandardParallel1

Winkel_II
CentralMeridian
StandardParallel1

Winkel_Tripel
CentralMeridian
StandardParallel1

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Android Camera2 API,自动对焦的坐标是从[-1000, 1000]的范围内进行定义的,其(0, 0)表示图像的心。 如果您需要将屏幕上的触摸坐标转换为适合于自动对焦的坐标,可以使用以下代码: ```java private MeteringRectangle[] getFocusAreaRect(float x, float y) { int areaSize = 200; int left = clamp((int) x - areaSize / 2, 0, mTextureView.getWidth() - areaSize); int top = clamp((int) y - areaSize / 2, 0, mTextureView.getHeight() - areaSize); RectF rectF = new RectF(left, top, left + areaSize, top + areaSize); return new MeteringRectangle[]{new MeteringRectangle(rectF, 1000)}; } private int clamp(int value, int min, int max) { return Math.max(min, Math.min(max, value)); } ``` 这个方法将返回一个MeteringRectangle数组,其包含一个矩形区域,该区域是在屏幕上给定的x和y坐标周围的一个固定大小。在这个例子,我们使用了一个200x200像素的矩形区域。您可以根据需要更改这个值。 接下来,您可以将这个MeteringRectangle数组传递给CameraCaptureSession的setRepeatingRequest方法,就可以开始自动对焦了。 ```java RectF rectF = new RectF(left, top, left + areaSize, top + areaSize); MeteringRectangle[] meteringRectangle = new MeteringRectangle[]{new MeteringRectangle(rectF, 1000)}; CameraCaptureRequest.Builder builder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); builder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO); builder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START); builder.set(CaptureRequest.CONTROL_AE_REGIONS, meteringRectangle); builder.set(CaptureRequest.CONTROL_AF_REGIONS, meteringRectangle); cameraCaptureSession.setRepeatingRequest(builder.build(), null, backgroundHandler); ``` 这个代码片段将启动自动对焦。请注意,我们使用了CONTROL_AF_TRIGGER_START触发器来开始自动对焦。在对焦完成后,您可以使用相同的代码将触发器设置为CONTROL_AF_TRIGGER_CANCEL,以停止自动对焦。 希望这可以帮助您解决您的问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值