2014-02-12 3 views
0

나는 mapwingis를 사용하고 있으며 필요한 모양의 파일을 모두 업로드했습니다. 이미 GPS에서 데이터를 얻었으므로 맵에 표시하고 싶습니다. 나는 drawcircleex를 사용할 수 있다고 연구했지만 정확한 위치를 알려주지 못하고 원이 중앙에 꽂혔다. 내 코드 heres :mapwindowGIS에 포인트를 플로팅하는 방법 GW

MapWinGIS.Shapefile plane = new MapWinGIS.Shapefile();// shape 1 
     MapWinGIS.Shapefile roads = new MapWinGIS.Shapefile();// shape 2 
     MapWinGIS.Shapefile gensan = new MapWinGIS.Shapefile();// shape 3 
     MapWinGIS.Shapefile pois = new MapWinGIS.Shapefile();// shape 4 
     MapWinGIS.Shapefile pofw = new MapWinGIS.Shapefile();// shape 5 
     MapWinGIS.Shapefile places = new MapWinGIS.Shapefile();// shape 6 
     MapWinGIS.Shapefile roadsfin = new MapWinGIS.Shapefile();// shape 7  
     MapWinGIS.Shapefile circle = new MapWinGIS.Shapefile();// shape 8 
     int shape1, shape2, shape3, shape4, shape5, shape6, shape7, shape8; 

     public static string varname; 




     public Form1() 
     { 
      InitializeComponent(); 

     } 
     private void Form1_Load(object sender, EventArgs e) 
     { 
      // layer of plane 
      plane.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/adminareasfinal.shp", null); 
      shape1 = axMap1.AddLayer(plane, true); 
      axMap1.set_ShapeLayerFillColor(shape1, (UInt32)(System.Drawing.ColorTranslator.ToOle 
      (System.Drawing.Color.Linen))); 
      axMap1.set_ShapeLayerLineColor(shape1, (UInt32)(System.Drawing.ColorTranslator.ToOle 
      (System.Drawing.Color.Linen))); 

      // layer of gensan 
      gensan.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/gensan_southcotabato/gensan_southcotabato.shp", null); 
      shape2 = axMap1.AddLayer(gensan, true); 
      axMap1.set_ShapeLayerFillColor(shape2, (UInt32)(System.Drawing.ColorTranslator.ToOle 
      (System.Drawing.Color.OldLace))); 
      axMap1.set_ShapeLayerLineColor(shape2, (UInt32)(System.Drawing.ColorTranslator.ToOle 
      (System.Drawing.Color.Black))); 

      // layer of longitude and latitude 
      Single LineWidth1 = 1; 
      roadsfin.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/roadsfin.shp", null); 
      shape7 = axMap1.AddLayer(roadsfin, true); 
      axMap1.set_UDPointType(shape7, roadsfin); 
      axMap1.set_ShapeLayerPointSize(shape7, LineWidth1); 
      axMap1.set_ShapeLayerPointColor(shape7, (UInt32)(System.Drawing.ColorTranslator.ToOle 
      (System.Drawing.Color.Transparent))); 


      // layer of roads 
      Single LineWidth = 2; 
      roads.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/roads.shp", null); 
      shape3 = axMap1.AddLayer(roads, true); 
      axMap1.set_ShapeLayerLineWidth(shape3, LineWidth); 
      axMap1.set_ShapeLayerLineColor(shape3, (UInt32)(System.Drawing.ColorTranslator.ToOle 
      (System.Drawing.Color.White))); 


      //layer of pois and pofw bitmap image 
      Single pointsize = 1; 

      pois.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/pois.shp", null); 
      shape4 = axMap1.AddLayer(pois, true); 
      pofw.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/pofw.shp", null); 
      shape5 = axMap1.AddLayer(pofw, true); 
      places.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/places.shp", null); 
      shape6 = axMap1.AddLayer(places, true); 


      int LineWidth7 = 10; 
      circle.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/newshape/finalepoint.shp", null); 
      shape8 = axMap1.AddLayer(circle, true); 
      axMap1.set_ShapeLayerPointColor(shape8, (UInt32)(System.Drawing.ColorTranslator.ToOle 
      (System.Drawing.Color.Black))); 
      axMap1.set_ShapeLayerPointSize(shape8, LineWidth7); 

      string circlelabel; 
      double x12, y12; 

      for (int j = 0; j < circle.NumShapes - 1; j++) 
      { 

       circlelabel = System.Convert.ToString(roads.get_CellValue(1, j)); 
       x12 = circle.get_Shape(j).Extents.xMin + (circle.get_Shape(j).Extents.xMax - circle.get_Shape(j).Extents.xMin)/2; 
       y12 = circle.get_Shape(j).Extents.yMin + (circle.get_Shape(j).Extents.yMax - circle.get_Shape(j).Extents.yMin)/2; 

       axMap1.AddLabel(shape8, circlelabel, (UInt32)(System.Drawing.ColorTranslator.ToOle 
         (System.Drawing.Color.Red)), x12, y12, MapWinGIS.tkHJustification.hjCenter); 
      } 


      MapWinGIS.Image poisimage = new MapWinGIS.Image(); 
      MapWinGIS.Image pofwimage = new MapWinGIS.Image(); 
      MapWinGIS.Image placesimage = new MapWinGIS.Image(); 

      poisimage.Open("C:/Users/User/Desktop/bitmap/poisimage.bmp", MapWinGIS.ImageType.USE_FILE_EXTENSION, true, null); 
      { 
       this.axMap1.set_ShapeLayerPointSize(shape4, pointsize); 
       this.axMap1.set_ShapeLayerPointType(shape4, MapWinGIS.tkPointType.ptUserDefined); 
       this.axMap1.set_UDPointType(shape4, poisimage); 
      } 
      axMap1.set_LayerVisible(shape4, true); 



      pofwimage.Open("C:/Users/User/Desktop/bitmap/pofwimage.bmp", MapWinGIS.ImageType.USE_FILE_EXTENSION, true, null); 
      { 
       this.axMap1.set_ShapeLayerPointSize(shape5, pointsize); 
       this.axMap1.set_ShapeLayerPointType(shape5, MapWinGIS.tkPointType.ptUserDefined); 
       this.axMap1.set_UDPointType(shape5, pofwimage); 
      } 
      axMap1.set_LayerVisible(shape5, true); 

      placesimage.Open("C:/Users/User/Desktop/bitmap/placesimage.bmp", MapWinGIS.ImageType.USE_FILE_EXTENSION, true, null); 
      { 
       this.axMap1.set_ShapeLayerPointSize(shape6, pointsize); 
       this.axMap1.set_ShapeLayerPointType(shape6, MapWinGIS.tkPointType.ptUserDefined); 
       this.axMap1.set_UDPointType(shape6, placesimage); 
      } 
      axMap1.set_LayerVisible(shape6, true); 

      // the following are the codes to show the names of Roads 

      string myLabel; 
      double x, y; 

      for (int i = 0; i < roads.NumShapes - 1; i++) 
      { 

       myLabel = System.Convert.ToString(roads.get_CellValue(4, i)); 
       x = roads.get_Shape(i).Extents.xMin + (roads.get_Shape(i).Extents.xMax - roads.get_Shape(i).Extents.xMin)/2; 
       y = roads.get_Shape(i).Extents.yMin + (roads.get_Shape(i).Extents.yMax - roads.get_Shape(i).Extents.yMin)/2; 


       axMap1.AddLabel(shape2, myLabel, (UInt32)(System.Drawing.ColorTranslator.ToOle 
         (System.Drawing.Color.Black)), x, y, MapWinGIS.tkHJustification.hjCenter); 
      } 

      // the following are the codes to show the names of pois 

      string poislabel; 
      double pois1, pois2; 
      int handle = axMap1.NewDrawing(MapWinGIS.tkDrawReferenceList.dlScreenReferencedList); 
      for (int ps = 0; ps < pois.NumShapes - 1; ps++) 
      { 

       poislabel = System.Convert.ToString(pois.get_CellValue(4, ps)); 
       pois1 = pois.get_Shape(ps).Extents.xMin + (pois.get_Shape(ps).Extents.xMax - pois.get_Shape(ps).Extents.xMin)/2; 
       pois2 = pois.get_Shape(ps).Extents.yMin + (pois.get_Shape(ps).Extents.yMax - pois.get_Shape(ps).Extents.yMin)/2; 
       double width = pois.get_Shape(ps).Extents.xMin + (pois.get_Shape(ps).Extents.xMax - pois.get_Shape(ps).Extents.xMin)/2; 
       double height = pois.get_Shape(ps).Extents.yMin + (pois.get_Shape(ps).Extents.yMax - pois.get_Shape(ps).Extents.yMin)/2; 
       axMap1.DrawCircleEx(handle, width, height, 5.0, 255, true); 
       axMap1.AddLabel(shape4, poislabel, (UInt32)(System.Drawing.ColorTranslator.ToOle 
         (System.Drawing.Color.Black)), pois1, pois2, MapWinGIS.tkHJustification.hjCenter); 

      } 

      // the following is to display the latitude 

      string latitude;// longitude; 
      double latx1, latx2; 
      for (int counter = 0; counter < roadsfin.NumShapes - 1; counter++) 
      { 
       latitude = System.Convert.ToString(roadsfin.get_CellValue(1, counter)); 
       latx1 = roadsfin.get_Shape(counter).Extents.xMin + (roadsfin.get_Shape(counter).Extents.xMax - roadsfin.get_Shape(counter).Extents.xMin)/2; 
       latx2 = roadsfin.get_Shape(counter).Extents.yMin + (roadsfin.get_Shape(counter).Extents.yMax - roadsfin.get_Shape(counter).Extents.yMin)/2; 

       axMap1.AddLabel(shape7, latitude, (UInt32)(System.Drawing.ColorTranslator.ToOle 
         (System.Drawing.Color.Black)), latx1, latx2, MapWinGIS.tkHJustification.hjCenter); 

      } 

      // sample displaying of location 
      // the following are the codes to show the names of pofw 

      string pofwlabel; 
      double pofw1, pofw2; 
      for (int pf = 0; pf < pofw.NumShapes - 1; pf++) 
      { 

       pofwlabel = System.Convert.ToString(pofw.get_CellValue(4, pf)); 
       pofw1 = pofw.get_Shape(pf).Extents.xMin + (pofw.get_Shape(pf).Extents.xMax - pofw.get_Shape(pf).Extents.xMin)/2; 
       pofw2 = pofw.get_Shape(pf).Extents.yMin + (pofw.get_Shape(pf).Extents.yMax - pofw.get_Shape(pf).Extents.yMin)/2; 

       axMap1.AddLabel(shape5, pofwlabel, (UInt32)(System.Drawing.ColorTranslator.ToOle 
         (System.Drawing.Color.Black)), pofw1, pofw2, MapWinGIS.tkHJustification.hjCenter); 

      } 

      // the following are the codes to show the names of places 

      string placeslabel; 
      double places1, places2; 

      for (int pl = 0; pl < places.NumShapes - 1; pl++) 
      { 

       placeslabel = System.Convert.ToString(places.get_CellValue(4, pl)); 
       places1 = places.get_Shape(pl).Extents.xMin + (places.get_Shape(pl).Extents.xMax - places.get_Shape(pl).Extents.xMin)/2; 
       places2 = places.get_Shape(pl).Extents.yMin + (places.get_Shape(pl).Extents.yMax - places.get_Shape(pl).Extents.yMin)/2;    
       axMap1.AddLabel(shape6, placeslabel, (UInt32)(System.Drawing.ColorTranslator.ToOle 
         (System.Drawing.Color.Black)), places1, places2, MapWinGIS.tkHJustification.hjCenter); 
      } 

      double x_etchos = 125.141; 
      double y_etchos = 6.117; 

      double x_leche = 125.141; 
      double y_leche = 6.117; 

//   MapWinGIS.Extents ext = axMap1.Extents as MapWinGIS.Extents; 
      double ewanko; 

      for (int test1 = 0; test1 < roadsfin.NumShapes; test1++) 
      { 
       ewanko = System.Convert.ToDouble(roads.get_CellValue(4, test1)); 

       if (x_etchos > roadsfin.get_Shape(test1).Extents.xMin && x_etchos < roadsfin.get_Shape(test1).Extents.xMax && y_etchos > roadsfin.get_Shape(test1).Extents.yMin && y_etchos < roadsfin.get_Shape(test1).Extents.yMax) 
       { 
        double width = roadsfin.get_Shape(test1).Extents.xMin + (roadsfin.get_Shape(test1).Extents.xMax - roadsfin.get_Shape(test1).Extents.xMin)/2; 
        double height = roadsfin.get_Shape(test1).Extents.yMin + (roadsfin.get_Shape(test1).Extents.yMax - roadsfin.get_Shape(test1).Extents.yMin)/2; 
        MessageBox.Show("width and height: " + width + " " + height); 
        //MessageBox.Show("x and y: " + ext.xMax + " <<max_X-min_X>> " + ext.xMin + " " + ext.yMax + " <<max_Y-min_X>> " + ext.yMin); 
        ext.SetBounds(x_etchos - width, y_etchos - height, 0.0, x_etchos + width, y_etchos + height, 0.0); 
        Application.DoEvents(); 


        axMap1.ProjToPixel(x_etchos, y_etchos, ref x_leche, ref y_leche); 
        axMap1.DrawCircleEx(handle, x_leche, y_leche, 5.0, 255, true); 

       } 
} 
+0

에 의해 호출

private Point getCenter(Extents ext) { Point p; p.X = ext.xMin + (ext.xMax - ext.xMin)/2.0; p.Y = ext.yMin + (ext.yMax - ext.yMin)/2.0; return p; } 

질문이 더 공식화하십시오. 너 뭐 해봤 니? 어떤 오류가 있었습니까? 정확히 어디서 붙어 있니? 전체 코드는 게시하지 말고 관련된 부분 만 게시하십시오. –

+0

원은 화면 중앙에 유지됩니다. 우리가지도를 확대함에 따라, 원은 여전히 ​​중앙에 머무르며지도의 정확한 위치를 찾지 못합니다. – user3301887

답변

0

이 코드의 문제점은 위치 및 위치를 한 번만 계산한다는 것입니다. 길 위에. 확대/축소 이벤트를 처리하고 모양 위치 및 크기를 다시 계산하려면 양식 클래스를 다시 작성해야합니다.

프로그램에는 일반적으로 둘 이상의 기능이 포함되어 있습니다. application.doEvents은 대기열의 이벤트를 처리하지만 이벤트를 기반으로 모양을 업데이트하지는 않습니다. 당신이 그 기능을 여러 번 호출하기 때문에

pofw1 = pofw.get_Shape(pf).Extents.xMin + (pofw.get_Shape(pf).Extents.xMax - pofw.get_Shape(pf).Extents.xMin)/2; 
pofw2 = pofw.get_Shape(pf).Extents.yMin + (pofw.get_Shape(pf).Extents.yMax - pofw.get_Shape(pf).Extents.yMin)/2; 

같은

팁도

일이 쉽게 함수에 배치됩니다.

Point pofwPoint = getCenter(pofw.get_Shape(pf).Extents); 
+0

정말요? - 내가 wapwingis가 다시 그리기를 처리 할 줄 알았 겠지? – Ross

관련 문제