GIS

arcGIS Server (ADF) 포인트로 그래픽레이어에 라인그리기-포인트콜렉션사용 (polyline from point)

조심이 2009. 11. 11. 10:36
반응형


2개 이상의 포인트 정보가 있을때 이 포인트를 이어 하나의 라인으로 그린다.
포인트를 포인트 콜렉션에 담아 그래픽 레이어에 라인을 생성한다.

public void Addpoint(){

//포인트 콜렉션 객체를 생성
ESRI.ArcGIS.ADF.Web.Geometry.PointCollection ptcollection = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();
 
//포인트 콜렉션에 포인트 정보를 추가
for (int j = 0; j < 조건; j++){ 
 ESRI.ArcGIS.ADF.Web.Geometry.Point adfpoint = new ESRI.ArcGIS.ADF.Web.Geometry.Point("X좌표","Y좌쵸");
 ptcollection .Add(adfpoint);
}

//그래픽 레이어에 라인을 그리기위한 함수 호출
AddGraphicsLine(Map1,ptcollection ,"line" );  //맵컨트롤, 포인트콜렉션,그래픽레이어명
Ma1.refreshResorce("line");
}


//포인트 콜렉션을 이용한 라인그리기
    public void AddGraphicsLine(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapctrl,ESRI.ArcGIS.ADF.Web.Geometry.PointCollection adfpointcollection, string LayerName)
    {

        ESRI.ArcGIS.ADF.Web.Geometry.Path adfpath = new ESRI.ArcGIS.ADF.Web.Geometry.Path();

        adfpath.Points = adfpointcollection;

        ESRI.ArcGIS.ADF.Web.Geometry.PathCollection adfpaths = new ESRI.ArcGIS.ADF.Web.Geometry.PathCollection();

        adfpaths.Add(adfpath);

        ESRI.ArcGIS.ADF.Web.Geometry.Polyline Hurricanepath = new ESRI.ArcGIS.ADF.Web.Geometry.Polyline();

        Hurricanepath.Paths = adfpaths;


        ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality adfGraphicsMapFunctionality = null;
        ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunctionality = mapctrl.GetFunctionality(LayerName);
        adfGraphicsMapFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)mapFunctionality;

        ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer = null;

        foreach (System.Data.DataTable dataTable in adfGraphicsMapFunctionality.GraphicsDataSet.Tables)
        {
            if (dataTable.TableName == LayerName)
            {
                elementGraphicsLayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dataTable;
                break;
            }
        }

        if (elementGraphicsLayer == null)
        {
            elementGraphicsLayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();
            elementGraphicsLayer.TableName = LayerName;
            adfGraphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer);
        }

        //임의의 라인색 설정 
        Random ran = new Random();
        int r = ran.Next(0, 256);
        int g = ran.Next(0, 256);
        int b = ran.Next(0, 256);
        Color color = Color.FromArgb(r, g, b);
      


        ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol simpleline = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol();
        //simpleline.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.LineType.Dash;
        simpleline.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.LineType.Solid; //라인타입
        simpleline.Width = 3; //라인굵기
        simpleline.Color = color; //색을 지정하고 싶다면 System.Draw.Color.Red 처럼 지정하면 됨

      

        ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement graphicElement = new   ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(Hurricanepath, simpleline);

        elementGraphicsLayer.Add(graphicElement);


    }


반응형