Click or drag to resize
XDL

NXPlanetLayerCompositesHitTest Method

화면에 도시된 XDMComposite 중에서 특정 위치에 Hitting 되는 가장 상위의 XDMComposite 를 가져온다.(Planet2D 모드에서만 가능하다.)

Namespace: Pixoneer.NXDL.NXPlanet
Assembly: NXPlanet (in NXPlanet.dll) Version: 3.0.0.0
Syntax
C#
public bool HitTest(
	XVertex3d vWorld,
	ref XDMComposite pHitComp
)

Parameters

vWorld  XVertex3d
테스트를 위한 월드 좌표(위경도 또는 WebMercator 좌표)
pHitComp  XDMComposite
[out] Hitting 되는 최상위 XDMComposite

Return Value

Boolean
성공이면 true, 실패하면 false를 반환한다.
Example
예제 #1: 컨트롤 화면을 클릭할 시 화면에 도시된 XDMComposite들 중 해당 위치에 Hitting 되는 가장 상위의 XDMComposite 를 가져온다.
C#
using Pixoneer.NXDL;
using Pixoneer.NXDL.NXPlanet;
using Pixoneer.NXDL.NRS;
using Pixoneer.NXDL.NIO;

namespace XDL_PlanetView
{
public partial class MainWindow : Window
{
    public XRasterIO RasterIO;

    public MainWindow()
    {
        InitializeComponent();
        nxPlanetView1.MouseDown += NxPlanetView1_MouseDown;
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        // Image load
        RasterIO = new XRasterIO();
        String StrError;
        if (RasterIO.Initialize(out StrError) == false)
        {
             MessageBox.Show(StrError);
        }

        String strFilePathLoad1 = "C:\\Pixoneer\\PG-STEAMER 5.0\\data\\IKONOS.xdm";
        String strFilePathLoad2 = "C:\\Pixoneer\\PG-STEAMER 5.0\\data\\DEM.xdm";
        XRSLoadFile xrsFileInput1 = new XRSLoadFile();
        XRSLoadFile xrsFileInput2 = new XRSLoadFile();
        xrsFileInput1 = RasterIO.LoadFile(strFilePathLoad2, out StrError, false, eIOCreateXLDMode.All_NoMsg);
        xrsFileInput2 = RasterIO.LoadFile(strFilePathLoad1, out StrError, false, eIOCreateXLDMode.All_NoMsg);

        // Create Composite
        if (xrsFileInput1 == null && xrsFileInput2 == null) return;
        XDMComposite newComp1 = CreateComposite(xrsFileInput1, 0, 1, 2);
        XDMComposite newComp2 = CreateComposite(xrsFileInput2, 0, 1, 2);
        XDMCompManager xdmCompManager = nxPlanetLayerComposites1.GetXDMCompManager();

        nxPlanetLayerComposites1.Lock();
        xdmCompManager.AddXDMComposite(ref newComp1);
        xdmCompManager.AddXDMComposite(ref newComp2);
        nxPlanetLayerComposites1.ZoomFit();
        nxPlanetLayerComposites1.Invalidate();
        nxPlanetLayerComposites1.UnLock();
        nxPlanetView1.RefreshScreen();
        nxPlanetView1.SetCameraPosition(XGeoPoint.FromDegree(127.37, 36.37, 50000), XAngle.FromDegree(0));
    }

    private void NxPlanetView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        // e.X, e.Y : 스크린 좌표(컨트롤 화면 기준 좌상단(0,0) 픽셀 단위)

        // PlanetView 는 지도 투영 방식에 따라 EEC 또는 Web Mercator 를 사용한다.
        // PlanetView 의 지도 투영 방식은 Planet 환경설정 파일 XDLConfiguration.xml의 <Planet2DProjection> 태그로 설정 가능하다. 
        // EEC : <Planet2DProjection>EEC</Planet2DProjection>
        // Web Mercator : <Planet2DProjection>WEBMERCATOR</Planet2DProjection>
        // PlanetView의 지도 투영 형식을 EEC로 설정하면  NXPlanetLayerComposites의 좌표계는 위경도 좌표계를 사용하고,
        // WebMercator로 설정하면 NXPlanetLayerComposites의 좌표계는 Web Mercator 좌표계를 사용한다.

        XDMComposite newComp = null;
        if (nxPlanetView1.Planet2DProjection == NXPlanetView.ePlanet2DProjection.EEC)
        {
            // PlanetView 컨트롤의 스크린 좌표를 위경도 좌표로 변환
            XGeoPoint geoPos = nxPlanetView1.ScreenToGeographic(e.X, e.Y);
            XVertex3d vtPos = new XVertex3d(geoPos.lond, geoPos.latd, geoPos.hgt);
            nxPlanetLayerComposites1.HitTest(vtPos, ref newComp);
        }
        else if (nxPlanetView1.Planet2DProjection == NXPlanetView.ePlanet2DProjection.WebMercator)
        {
            // PlanetView 컨트롤의 스크린 좌표를 World 좌표로 변환=>Web Mercator 좌표값과 동일
            XVertex3d mercatorPos = nxPlanetView1.ScreenToWorld(e.X, e.Y);
            nxPlanetLayerComposites1.HitTest(mercatorPos, ref newComp);
        }

        // Hit Composite 결과를 출력한다.
        if (newComp != null && !string.IsNullOrEmpty(newComp.Name))
        {
            System.Windows.MessageBox.Show($"선택된 Composite 이름: {newComp.Name}\n모드: {newComp.Mode}");
        }
        else
        {
            System.Windows.MessageBox.Show("해당 위치에 Composite가 없습니다.");
        }
    }

    XDMComposite CreateComposite(XRSLoadFile xrsFileInput, int nBandIdx0, int nBandIdx1, int nBandIdx2)
    {
        XDMComposite newComp = new XDMComposite();

        int nNumBand = xrsFileInput.NumBand;
        if (nNumBand < 3)
        {
            XDMBand band = xrsFileInput.GetBandAt(0);
            newComp.Name = band.BandName;
            newComp.Mode = eCompMode.Gray;
            newComp.SetBand(ref band, 0);
            newComp.SetCutType(eCompCutType.Ct95, 0);
            newComp.SetStretchCoverage(eCompStretchCoverage.Band, 0);
            newComp.SetStretchType(eCompStretchType.Gaussian, 0);
        }
        else
        {
            XDMBand band1 = xrsFileInput.GetBandAt(0);
            XDMBand band2 = xrsFileInput.GetBandAt(1);
            XDMBand band3 = xrsFileInput.GetBandAt(2);
            newComp.Name = xrsFileInput.FileName;

            newComp.Mode = eCompMode.RGB;
            newComp.SetBand(ref band3, nBandIdx0);
            newComp.SetBand(ref band2, nBandIdx1);
            newComp.SetBand(ref band1, nBandIdx2);

            for (int i = 0; i < 3; i++)
            {
                newComp.SetCutType(eCompCutType.Ct95, i);
                newComp.SetStretchCoverage(eCompStretchCoverage.Band, i);
                newComp.SetStretchType(eCompStretchType.Gaussian, i);
            }
        }
        return newComp;
    }

    private void Window_Closed(object sender, EventArgs e)
    {
        Xfn.Close();
    }
 }
See Also