Show Point

Feb 3, 2015 at 3:07 AM
Hello, im new user of mapWinGis
i want to draw a point on my C# project based on MySQL data, for first time i try to create just one point and not use the SQL.
but i didn't get the point show at my map
this is my code

private void btnShow_Click(object sender, EventArgs e)
    {
        MarkPoints();
        drawPoints();
    }

    public void MarkPoints()
    {
        //axMap1.Projection = tkMapProjection.PROJECTION_WGS84;

        var sf = new Shapefile();
        sf = axMap1.get_Shapefile(m_layerHandle);// in case a copy of shapefile was created by GlobalSettings.ReprojectLayersOnAdding

        sf = new Shapefile();
        if (!sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT))
        {
            MessageBox.Show("Failed to create shapefile: " + sf.ErrorMsg[sf.LastErrorCode]);
            return;
        }

        m_layerHandle = axMap1.AddLayer(sf, true);

        ShapeDrawingOptions options = sf.DefaultDrawingOptions;
        options.PointType = tkPointSymbolType.ptSymbolPicture;

        // Opens a marker from the file
        // </summary>
        string imgfilename = @"D:\Users\Alexander\Documents\Visual Studio 2010\Projects\SQL with MapWinGis\SQL with MapWinGis\icon\marker.png";
        if (!File.Exists(imgfilename))
        {
            MessageBox.Show("Can't find the file: " + imgfilename);
        }
        else
        {
            Image img = new Image();
            if (!img.Open(imgfilename, ImageType.USE_FILE_EXTENSION, true, null))
            {
                MessageBox.Show(img.ErrorMsg[img.LastErrorCode]);
                img.Close();
            }
            else
                options.Picture = img;
        }

        sf.CollisionMode = tkCollisionMode.AllowCollisions;

    }

    public void drawPoints()
    {
        Shapefile sf = axMap1.get_Shapefile(m_layerHandle);

        Shape shp = new Shape();
        shp.Create(ShpfileType.SHP_POINT);

        Point pnt = new Point();
        double x = 0.0;
        double y = 0.0;
        x = -6.412;
        y = 106;
        pnt.x = x;
        pnt.y = y;
        int index = shp.numPoints;
        shp.InsertPoint(pnt, ref index);

        index = sf.NumShapes;
        if (!sf.EditInsertShape(shp, ref index))
        {
            MessageBox.Show("Failed to insert shape: " + sf.ErrorMsg[sf.LastErrorCode]);
            return;
        }
        axMap1.Redraw();
        MessageBox.Show("Draw Ok");
    }
i receive Draw Ok, but i can't see the marker on my map.
Developer
Feb 3, 2015 at 7:17 AM
Edited Feb 3, 2015 at 7:19 AM
Hi, try to add axMap1.ZoomToLayer(m_layerHandle) call.
Also y is latitude, i.e. should be in range [-90; 90], so perhaps x and y are mixed up.
Line
  sf = axMap1.get_Shapefile(m_layerHandle);// in case a copy of shapefile was created by GlobalSettings.ReprojectLayersOnAdding
int the beginning isn't necessary, you haven't added the layer to the map at this point.
Shape.AddPoint rather than Shape.InsertPoint in the second function can spare you some code lines.
axMap1.Projection = tkMapProjection.PROJECTION_WGS84 is fine if you want to see background tiles and provide coordinates in decimal degrees.
Also perhaps samples listed here may be helpful (9th in particular).

Hope it'll help,
Sergei
Marked as answer by pmeems on 2/6/2015 at 2:39 AM
Feb 5, 2015 at 9:24 AM
Thanks for your suggestion. Now i can draw a point based MySQL data