2014-02-12 123 views
0

我正在使用mapwingis,我已經上傳了所有需要的形狀文件..現在我已經有了來自GPS的數據,我想在我的地圖中顯示它。我研究過我可以使用drawcircleex,但它並沒有給我正確的位置,並且圓圈在中心被卡住了。繼承人我的代碼:如何在地圖上繪製點windwindGIS

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

叫請制定你的問題更好。你有什麼嘗試?你有沒有得到任何錯誤?你究竟在哪裏卡住?請不要發佈您的整個代碼,但只有相關的部分。 –

+0

圓圈保持在屏幕的中心。當我們放大地圖時,圓仍然停留在中心位置,並且在地圖 – user3301887

回答

0

該代碼的問題是你只計算位置和位置一次。負載。您需要重寫表單類以處理縮放/平移事件,並重新計算形狀位置和大小。

程序通常包含多個函數。 application.doEvents將處理隊列中的事件,但您沒有根據事件更新形狀。

TIP

還搞什麼

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; 

很容易放在一個功能,因爲你怎麼稱呼它在該函數多次。

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

通過

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

中沒有找到正確的位置? - 我會認爲wapwingis會處理重繪? – Ross