Beispiel #1
0
        public static Shapefile TrackFromWaypoints()
        {
            if (WaypointsinLocalTine.Count > 0)
            {
                Shapefile shpFile = new Shapefile();
                if (shpFile.CreateNewWithShapeID("", ShpfileType.SHP_POLYLINE))
                {
                    shpFile.GeoProjection = globalMapping.GeoProjection;
                    var shp = new Shape();
                    if (shp.Create(ShpfileType.SHP_POLYLINE))
                    {
                        foreach (var wlt in WaypointsinLocalTine)
                        {
                            var shpIndex = shp.AddPoint(wlt.Longitude, wlt.Latitude);
                        }
                    }
                    shpFile.EditAddShape(shp);
                }

                return(shpFile);
            }
            else
            {
                throw new ArgumentException("Waypoint source cannot be null or cannot have zero elements");
            }
        }
Beispiel #2
0
        private void BtnAnotation_Click(object sender, EventArgs e)
        {
            btnAnotation.Checked = !btnAnotation.Checked;
            if (btnAnotation.Checked)
            {
                btnExport.Enabled = true;
                //toolStripButton6.Enabled
                axMap1.CursorMode = tkCursorMode.cmMeasure;
                axMap1.Measuring.MeasuringType = tkMeasuringType.MeasureArea;
                axMap1.Measuring.ShowLength    = false;
                axMap1.MeasuringChanged       += AxMap1_MeasuringChanged;
                tmpLayer = new Shapefile();
                if (!tmpLayer.CreateNewWithShapeID("", ShpfileType.SHP_POLYGON))
                {
                    MessageBox.Show("Failed to create shapefile: " + tmpLayer.ErrorMsg[tmpLayer.LastErrorCode]);
                    return;
                }

                idxLayerTmp = axMap1.AddLayer(tmpLayer, true);
                //i_layer1 = axMap1.AddLayer(sf_1, true);
                axMap1.set_ShapeLayerFillColor(idxLayerTmp, Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Aqua)));
                axMap1.set_ShapeLayerLineColor(idxLayerTmp, Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Aqua)));
            }
            else
            {
                btnExport.Enabled = false;
                axMap1.CursorMode = tkCursorMode.cmPan;
                if (idxLayerTmp >= 0)
                {
                    axMap1.RemoveLayer(idxLayerTmp);
                }
            }
        }
Beispiel #3
0
        private void button6_Click(object sender, EventArgs e)
        {
            // Create a polygon shapefile:
            var sfPolygon = new Shapefile();

            sfPolygon.CreateNewWithShapeID("", ShpfileType.SHP_POLYGON);
            var shp = new Shape();

            shp.ImportFromWKT(
                "POLYGON((330695.973322992 5914896.16305817, 330711.986129861 5914867.19586245, 330713.350435287 5914867.56644015, 330716.510827627 5914862.28973662, 330715.632568651 5914860.60107999, 330652.234582712 5914803.80510632, 330553.749382483 5914715.80328169, 330551.979355848 5914714.83347535, 330549.911988583 5914715.86502807, 330545.027807355 5914724.05916443, 330544.592985976 5914725.93531509, 330544.30963704 5914726.72754692, 330543.612620707 5914726.14904553, 330543.271515787 5914727.06633931, 330542.234090059 5914729.85597723, 330542.959654761 5914730.50411962, 330530.319252794 5914765.86064153, 330505.294840402 5914836.7930124, 330471.411812074 5914931.61558331, 330486.074748666 5914941.33795239, 330585.983154737 5915010.32749106, 330618.427962455 5915031.20447119, 330653.234601917 5914970.37328093, 330695.973322992 5914896.16305817))");
            sfPolygon.EditAddShape(shp);

            // Create some random points:
            var       random    = new Random();
            const int numPoints = 50;
            var       extents   = sfPolygon.Extents;
            var       width     = extents.xMax - extents.xMin;
            var       height    = extents.yMax - extents.yMin;

            var sfPoint = new Shapefile();

            sfPoint.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
            for (var i = 0; i < numPoints; i++)
            {
                var x        = extents.xMin + width * random.NextDouble();
                var y        = extents.yMin + height * random.NextDouble();
                var shpPoint = new Shape();
                shpPoint.Create(ShpfileType.SHP_POINT);
                shpPoint.AddPoint(x, y);
                sfPoint.EditAddShape(shpPoint);
            }

            axMap1.AddLayer(sfPolygon, true);
            axMap1.AddLayer(sfPoint, true);
        }
Beispiel #4
0
 private void polygonToolStripMenuItem_Click(object sender, EventArgs e)
 {
     polygonToolStripMenuItem.Checked = !polygonToolStripMenuItem.Checked;
     if (polygonToolStripMenuItem.Checked)
     {
         mapControl.CursorMode = tkCursorMode.cmMeasure;
         mapControl.Measuring.MeasuringType    = tkMeasuringType.MeasureArea;
         mapControl.Measuring.ShowLength       = false;
         mapControl.Measuring.ShowBearing      = false;
         mapControl.Measuring.ShowTotalLength  = false;
         mapControl.Measuring.FillTransparency = 50;
         mapControl.MeasuringChanged          += mapControl_MeasuringChanged;
         shp_tmp = new Shapefile();
         if (!shp_tmp.CreateNewWithShapeID("", ShpfileType.SHP_POLYGON))
         {
             MessageBox.Show("Failed to create shapefile: " + shp_tmp.ErrorMsg[shp_tmp.LastErrorCode]);
             return;
         }
         currentLayerIndex = mapControl.AddLayer(shp_tmp, true);
     }
     else
     {
         mapControl.CursorMode = tkCursorMode.cmPan;
         if (currentLayerIndex >= 0)
         {
             mapControl.RemoveLayer(currentLayerIndex);
         }
     }
 }
        private static void OnExentCreated(MapInterActionHandler s, LayerEventArg e)
        {
            if (EnableMapInteraction)
            {
                if (_hAOI >= 0)
                {
                    MapWindowManager.MapLayersHandler.RemoveLayer(_hAOI);
                }
                else
                {
                    AOIName = "New AOI";
                }

                _sfAOI = new Shapefile();
                if (_sfAOI.CreateNewWithShapeID("", ShpfileType.SHP_POLYGON))
                {
                    if (_sfAOI.EditAddShape(e.SelectionExtent.ToShape()) >= 0)
                    {
                        _hAOI = MapWindowManager.MapLayersHandler.AddLayer(_sfAOI, AOIName);
                        if (_hAOI >= 0)
                        {
                            var fldName = _sfAOI.EditAddField("Name", FieldType.STRING_FIELD, 1, 1);
                            _sfAOI.Key = "aoi";
                            FormatAOI(_sfAOI);
                        }
                    }
                }
            }
        }
Beispiel #6
0
        // <summary>
        // Creates a shapefile holding polygons with holes
        // </summary>
        public void PolygonsWithHoles(AxMap axMap1)
        {
            axMap1.Projection = tkMapProjection.PROJECTION_NONE;

            var  sf     = new Shapefile();
            bool result = sf.CreateNewWithShapeID("", ShpfileType.SHP_POLYGON);

            if (!result)
            {
                MessageBox.Show(sf.ErrorMsg[sf.LastErrorCode]);
            }
            else
            {
                double xMin = 0.0;
                double yMin = 0.0;
                double xMax = 1000.0;
                double yMax = 1000.0;
                Random rnd  = new Random(DateTime.Now.Millisecond);

                // builds 10 polygons
                for (int i = 0; i < 40; i++)
                {
                    double xCenter = xMin + (xMax - xMin) * rnd.NextDouble();
                    double yCenter = yMin + (yMax - yMin) * rnd.NextDouble();

                    // random radius from 10 to 100
                    double radius = 10 + rnd.NextDouble() * 90;

                    var shp = new Shape();
                    shp.Create(ShpfileType.SHP_POLYGON);

                    // polygon must have clockwise order of points (first argument - true)
                    this.AddRing(true, xCenter, yCenter, radius, ref shp);

                    // holes must have counter-clockwise order of points (fale for the last argument)
                    this.AddRing(false, xCenter + radius / 2.0, yCenter, radius / 4.0, ref shp);
                    this.AddRing(false, xCenter - radius / 2.0, yCenter, radius / 4.0, ref shp);
                    this.AddRing(false, xCenter, yCenter + radius / 2.0, radius / 4.0, ref shp);
                    this.AddRing(false, xCenter, yCenter - radius / 2.0, radius / 4.0, ref shp);

                    for (int j = 0; j < shp.NumParts; j++)
                    {
                        Debug.Print("Part is clocwise: " + shp.PartIsClockWise[j]);
                    }

                    Debug.Print("Shape is valid: " + shp.IsValid);
                    if (!shp.IsValid)
                    {
                        Debug.Print("Reason: " + shp.IsValidReason);
                    }

                    sf.EditInsertShape(shp, ref i);
                }

                axMap1.AddLayer(sf, true);
                axMap1.ZoomToLayer(0);

                sf.SaveAs(@"c:\polygons.shp", null);
            }
        }
Beispiel #7
0
        public void EditAddShapeTest()
        {
            // https://mapwindow.discourse.group/t/system-accessviolationexception-after-editaddshape/196
            var pnt = new Point {
                x = 6.7369281, y = 53.1603648
            };

            var shp = new Shape();

            shp.Create(ShpfileType.SHP_POLYGON);
            shp.InsertPoint(pnt, 0);

            var sf     = new Shapefile();
            var result = sf.CreateNewWithShapeID("", ShpfileType.SHP_POLYGON);

            Assert.IsTrue(result, "CreateNewWithShapeID failed: " + sf.ErrorMsg[sf.LastErrorCode]);

            var shpIndex = sf.EditAddShape(shp);

            Assert.IsTrue(shpIndex > -1, "EditAddShape failed: " + sf.ErrorMsg[sf.LastErrorCode]);

            sf.InteractiveEditing = true;
            Assert.IsTrue(sf.InteractiveEditing, "InteractiveEditing failed: " + sf.ErrorMsg[sf.LastErrorCode]);

            var layerIndex = _axMap1.AddLayer(sf, true);

            Assert.IsTrue(layerIndex > -1, "AddLayer failed: " + sf.ErrorMsg[sf.LastErrorCode]);

            result = _axMap1.ShapeEditor.StartEdit(layerIndex, shpIndex);
            Assert.IsTrue(result, "ShapeEditor.StartEdit failed: " + sf.ErrorMsg[sf.LastErrorCode]);
        }
Beispiel #8
0
        public void MarkPoints(AxMap axMap1, string dataPath)
        {
            //axMap1.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR;
            string filename = @"C:\Users\Admin\source\repos\GIS\GIS\bin\Debug\Shapefiles_Data\Hanoi\planet_105.141,20.676_106.164,21.273.osm.shp\shape\buildings.shp";

            if (!File.Exists(filename))
            {
                MessageBox.Show("Couldn't file the file: " + filename);
                return;
            }
            var sf = new Shapefile();

            //sf.Open(filename, null);
            //m_layerHandle = axMap1.AddLayer(sf, true);
            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;
            options.Picture        = this.OpenMarker(dataPath);
            sf.CollisionMode       = tkCollisionMode.AllowCollisions;
            axMap1.SendMouseDown   = true;
            axMap1.CursorMode      = tkCursorMode.cmNone;
            axMap1.MouseDownEvent += MainMap_MouseDownEvent;   // change MapEvents to axMap1
        }
Beispiel #9
0
        public static Shapefile PointsFromWayPointList(List <TripWaypoint> wpts, out List <int> handles, string gpsName, string fileName)
        {
            handles = new List <int>();
            Shapefile sf;

            if (wpts.Count > 0)
            {
                if (TripMappingManager.WaypointsShapefile == null || TripMappingManager.WaypointsShapefile.NumFields == 0)
                {
                    sf = new Shapefile();
                    if (sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT))
                    {
                        sf.EditAddField("Name", FieldType.STRING_FIELD, 1, 1);
                        sf.EditAddField("Type", FieldType.STRING_FIELD, 1, 1);
                        sf.EditAddField("Set number", FieldType.INTEGER_FIELD, 3, 1);
                        sf.EditAddField("TimeStamp", FieldType.DATE_FIELD, 1, 1);
                        sf.EditAddField("GPS", FieldType.STRING_FIELD, 1, 1);
                        sf.EditAddField("Filename", FieldType.STRING_FIELD, 1, 1);
                        sf.Key           = "trip_waypoints";
                        sf.GeoProjection = globalMapping.GeoProjection;
                        TripMappingManager.WaypointsShapefile = sf;
                    }
                }
                else
                {
                    sf = TripMappingManager.WaypointsShapefile;
                }

                foreach (var pt in wpts)
                {
                    var shp = new Shape();
                    if (shp.Create(ShpfileType.SHP_POINT))
                    {
                        if (shp.AddPoint(pt.Waypoint.Longitude, pt.Waypoint.Latitude) >= 0)
                        {
                            var shpIndex = sf.EditAddShape(shp);
                            if (shpIndex >= 0)
                            {
                                sf.EditCellValue(sf.FieldIndexByName["Name"], shpIndex, pt.WaypointName);
                                sf.EditCellValue(sf.FieldIndexByName["TimeStamp"], shpIndex, pt.TimeStampAdjusted);
                                sf.EditCellValue(sf.FieldIndexByName["Type"], shpIndex, pt.WaypointType);
                                sf.EditCellValue(sf.FieldIndexByName["Set number"], shpIndex, pt.SetNumber);
                                sf.EditCellValue(sf.FieldIndexByName["GPS"], shpIndex, gpsName);
                                sf.EditCellValue(sf.FieldIndexByName["Filename"], shpIndex, fileName);
                                handles.Add(shpIndex);
                            }
                        }
                    }
                }
                sf.DefaultDrawingOptions.PointShape = tkPointShapeType.ptShapeCircle;
                sf.DefaultDrawingOptions.PointSize  = 12;
                sf.DefaultDrawingOptions.FillColor  = _mapWinGISUtils.ColorByName(tkMapColor.Red);
                return(sf);
            }
            else
            {
                return(null);
            }
        }
Beispiel #10
0
        private void AddPoint(AxMap Map, double lng, double lat, string pointName)
        {
            var sf = new Shapefile();

            if (PointShapefileLayerHandle != -1)
            {
                sf = Map.get_Shapefile(PointShapefileLayerHandle);
            }

            if (PointShapefileLayerHandle == -1)
            {
                if (!sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT))
                {
                    MessageBox.Show("Failed to create shapefile: " + sf.ErrorMsg[sf.LastErrorCode]);
                    return;
                }
                PointShapefileLayerHandle = Map.AddLayer(sf, true);
            }

            var utils = new Utils();
            ShapeDrawingOptions options = sf.DefaultDrawingOptions;

            options.PointType        = tkPointSymbolType.ptSymbolStandard;
            options.PointShape       = tkPointShapeType.ptShapeCross;
            options.FillColor        = utils.ColorByName(tkMapColor.Black);
            sf.DefaultDrawingOptions = options;
            sf.CollisionMode         = tkCollisionMode.AllowCollisions;


            Shape shp = new Shape();


            //shp = sf.get_Shape(shapeIndex);
            shp.Create(ShpfileType.SHP_POINT);



            MapWinGIS.Point pnt = new MapWinGIS.Point();
            pnt.x   = lng;
            pnt.y   = lat;
            pnt.Key = pointName;

            int Index;

            Index = shp.NumPoints;

            shp.InsertPoint(pnt, ref Index);

            Index = sf.NumShapes;

            if (!sf.EditInsertShape(shp, Index))
            {
                MessageBox.Show("Failed to insert shape: " + sf.ErrorMsg[sf.LastErrorCode]);
                return;
            }

            points.Add(pnt);
            Map.Redraw();
        }
Beispiel #11
0
        public static Shapefile TrackFromTrip(List <Trip> trips, out List <int> handles)
        {
            handles = new List <int>();
            Shapefile sf       = null;
            var       shpIndex = -1;
            int       counter  = 0;

            foreach (var trip in trips)
            {
                if (counter == 0)
                {
                    if (TripMappingManager.TrackShapefile == null || TripMappingManager.TrackShapefile.NumFields == 0)
                    {
                        sf = new Shapefile();
                        if (sf.CreateNewWithShapeID("", ShpfileType.SHP_POLYLINE))
                        {
                            sf.EditAddField("GPS", FieldType.STRING_FIELD, 1, 1);
                            sf.EditAddField("Fisher", FieldType.STRING_FIELD, 1, 1);
                            sf.EditAddField("Vessel", FieldType.STRING_FIELD, 1, 1);
                            sf.EditAddField("Gear", FieldType.STRING_FIELD, 1, 1);
                            sf.EditAddField("Departed", FieldType.DATE_FIELD, 1, 1);
                            sf.EditAddField("Arrived", FieldType.DATE_FIELD, 1, 1);
                            sf.EditAddField("Filename", FieldType.STRING_FIELD, 1, 1);
                            sf.EditAddField("Length", FieldType.DOUBLE_FIELD, 1, 1);

                            sf.Key           = "trip_track";
                            sf.GeoProjection = globalMapping.GeoProjection;
                            TripMappingManager.TrackShapefile = sf;
                        }
                    }
                    else
                    {
                        sf = TripMappingManager.TrackShapefile;
                    }
                }

                var shp = new Shape();
                if (shp.Create(ShpfileType.SHP_POLYLINE))
                {
                    foreach (var wpt in trip.Track.Waypoints)
                    {
                        shp.AddPoint(wpt.Longitude, wpt.Latitude);
                    }
                }
                shpIndex = sf.EditAddShape(shp);
                handles.Add(shpIndex);
                sf.EditCellValue(sf.FieldIndexByName["GPS"], shpIndex, trip.GPS.DeviceName);
                sf.EditCellValue(sf.FieldIndexByName["Fisher"], shpIndex, trip.OperatorName);
                sf.EditCellValue(sf.FieldIndexByName["Vessel"], shpIndex, trip.VesselName);
                sf.EditCellValue(sf.FieldIndexByName["Departed"], shpIndex, trip.DateTimeDeparture);
                sf.EditCellValue(sf.FieldIndexByName["Arrived"], shpIndex, trip.DateTimeArrival);
                sf.EditCellValue(sf.FieldIndexByName["Gear"], shpIndex, trip.Gear);
                sf.EditCellValue(sf.FieldIndexByName["FileName"], shpIndex, trip.GPXFileName);
                sf.EditCellValue(sf.FieldIndexByName["Length"], shpIndex, trip.Track.Statistics.Length);
                counter++;
            }
            return(sf);
        }
Beispiel #12
0
        public static Shapefile NamedPointsFromGPX(GPXFile gpxFile, out List <int> shpIndexes)
        {
            shpIndexes = new List <int>();
            Shapefile sf;

            if (gpxFile.NamedWaypointsInLocalTime.Count > 0)
            {
                if (GPXMappingManager.WaypointsShapefile == null || GPXMappingManager.WaypointsShapefile.NumFields == 0)
                {
                    sf = new Shapefile();

                    if (sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT))
                    {
                        sf.GeoProjection = globalMapping.GeoProjection;
                        sf.Key           = "gpxfile_waypoint";
                        sf.EditAddField("Name", FieldType.STRING_FIELD, 1, 1);
                        sf.EditAddField("TimeStamp", FieldType.DATE_FIELD, 1, 1);
                        sf.EditAddField("GPS", FieldType.STRING_FIELD, 1, 1);
                        sf.EditAddField("Filename", FieldType.STRING_FIELD, 1, 1);
                        GPXMappingManager.WaypointsShapefile = sf;
                    }
                }
                else
                {
                    sf = GPXMappingManager.WaypointsShapefile;
                }

                foreach (var wlt in gpxFile.NamedWaypointsInLocalTime)
                {
                    var shp = new Shape();
                    if (shp.Create(ShpfileType.SHP_POINT))
                    {
                        if (shp.AddPoint(wlt.Longitude, wlt.Latitude) >= 0)
                        {
                            var shpIndex = sf.EditAddShape(shp);
                            if (shpIndex >= 0)
                            {
                                sf.EditCellValue(sf.FieldIndexByName["Name"], shpIndex, wlt.Name);
                                sf.EditCellValue(sf.FieldIndexByName["TimeStamp"], shpIndex, wlt.Time);
                                sf.EditCellValue(sf.FieldIndexByName["GPS"], shpIndex, gpxFile.GPS.DeviceName);
                                sf.EditCellValue(sf.FieldIndexByName["Filename"], shpIndex, gpxFile.FileName);
                                shpIndexes.Add(shpIndex);
                            }
                        }
                    }
                }

                sf.DefaultDrawingOptions.PointShape = tkPointShapeType.ptShapeCircle;
                sf.DefaultDrawingOptions.PointSize  = 12;
                sf.DefaultDrawingOptions.FillColor  = _mapWinGISUtils.ColorByName(tkMapColor.Red);
                return(sf);
            }
            else
            {
                return(null);
            }
        }
Beispiel #13
0
        //Creates a shape file that contains all flights lat and long points and then generates a feald in the table that contains all flights images
        private void CreatePointShapefile()
        {
            axMap1.Projection   = tkMapProjection.PROJECTION_WGS84;
            axMap1.TileProvider = tkTileProvider.OpenStreetMap;
            var positions = pR.GetPositionsFromDB();
            var sfPoints  = new Shapefile();

            sfPoints.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
            // creating points and inserting them in the shape
            foreach (Position position in positions)
            {
                int count = 0;
                var pnt   = new Point();
                pnt.x = Convert.ToDouble(position.longitude);
                pnt.y = Convert.ToDouble(position.latitude);
                Shape shp = new Shape();
                shp.Create(ShpfileType.SHP_POINT);
                int index = 0;
                shp.InsertPoint(pnt, ref index);
                sfPoints.EditInsertShape(shp, ref count);
                count++;
            }
            var _idShape = axMap1.AddLayer(sfPoints, true);
            int indexo   = sfPoints.Table.FieldIndexByName["MWShapeId"];
            var names    = new HashSet <string>();

            for (int i = 0; i < sfPoints.Table.NumRows; i++)
            {
                names.Add(sfPoints.Table.CellValue[indexo, i].ToString());
            }
            string[] files = Directory.GetFiles(@"D:\Faks\Druga godina\Treci Semestar\Programiranje_u_NET_okolini\Konstrukcijska_Vjezba\FlightTracker\FlightTracker\Resources\imagesOfPlanes");
            foreach (string file in files)
            {
                string name = Path.GetFileNameWithoutExtension(file);
                if (Path.GetExtension(file).ToLower() == ".png" && names.Contains(name))
                {
                    MapWinGIS.Image img = new MapWinGIS.Image();
                    if (img.Open(file, ImageType.USE_FILE_EXTENSION, true, null))
                    {
                        ShapefileCategory ct = new ShapefileCategory();
                        ct = sfPoints.Categories.Add(name);
                        ct.DrawingOptions.PointType     = tkPointSymbolType.ptSymbolPicture;
                        ct.DrawingOptions.PictureScaleX = 0.8;
                        ct.DrawingOptions.PictureScaleY = 0.8;
                        ct.DrawingOptions.DrawingMode   = tkVectorDrawingMode.vdmGDIPlus;
                        sfPoints.CollisionMode          = tkCollisionMode.AllowCollisions;
                        ct.Expression             = "[MWShapeId]=" + name;
                        ct.DrawingOptions.Picture = img;

                        sfPoints.DefaultDrawingOptions = ct.DrawingOptions;
                    }
                }
            }
            sfPoints.Categories.ApplyExpressions();
            axMap1.KnownExtents = tkKnownExtents.keCroatia;
        }
Beispiel #14
0
        public static void CreatePointShapefile(AxMap Map, List <GisPoint>[] ListData, int num)
        {
            var  sf     = new Shapefile();                                         //创建一个新的shp文件
            bool result = sf.CreateNewWithShapeID("", ShpfileType.SHP_MULTIPOINT); //初始化shp文件

            for (int j = 0; j < num - 1; j++)
            {
                Shape shp = new Shape(); //创建shp图层
                shp.Create(ShpfileType.SHP_MULTIPOINT);
                for (int i = 0; i < ListData[j].Count; i++)
                {
                    var pnt = new Point();
                    pnt.x   = ListData[j][i].X;
                    pnt.y   = ListData[j][i].Y;
                    pnt.Key = "fang";
                    int index = 0;
                    shp.InsertPoint(pnt, ref index);
                }
                sf.EditAddShape(shp);
                if (j == 0)
                {
                    var utils            = new Utils();
                    ShapefileCategory ct = sf.Categories.Add("0");
                    ct.DrawingOptions.FillType  = tkFillType.ftGradient;
                    ct.DrawingOptions.FillColor = utils.ColorByName(tkMapColor.Green);
                    sf.set_ShapeCategory(0, 0);
                }
                else if (j == 1)
                {
                    var utils            = new Utils();
                    ShapefileCategory ct = sf.Categories.Add("1");
                    ct.DrawingOptions.FillType  = tkFillType.ftStandard;
                    ct.DrawingOptions.FillColor = utils.ColorByName(tkMapColor.Blue);
                    sf.set_ShapeCategory(1, 1);
                }
                else if (j == 2)
                {
                    var utils            = new Utils();
                    ShapefileCategory ct = sf.Categories.Add("2");
                    ct.DrawingOptions.FillType  = tkFillType.ftStandard;
                    ct.DrawingOptions.FillColor = utils.ColorByName(tkMapColor.Yellow);
                    sf.set_ShapeCategory(2, 2);
                }
                else
                {
                    var utils            = new Utils();
                    ShapefileCategory ct = sf.Categories.Add("3");
                    ct.DrawingOptions.FillType  = tkFillType.ftStandard;
                    ct.DrawingOptions.FillColor = utils.ColorByName(tkMapColor.Red);
                    sf.set_ShapeCategory(3, 3);
                }
            }
            sf.DefaultDrawingOptions.SetDefaultPointSymbol(tkDefaultPointSymbol.dpsTriangleUp);
            Map.AddLayer(sf, true);
            Map.SendMouseMove = true;
        }
 private void CreateShapefile()
 {
     _shapefile = new Shapefile();
     _shapefile.CreateNewWithShapeID(Filename, ShapefileType);
     _shapefile.InteractiveEditing = true;
     foreach (var fld in Fields)
     {
         _shapefile.EditInsertField(fld, _shapefile.NumFields);
     }
 }
Beispiel #16
0
        public bool AddLayers(string name)
        {
            //this.mapControl.RemoveAllLayers();

            //this.mapControl.LockWindow(tkLockMode.lmLock);
            if (name.ToLower().EndsWith(".shp"))
            {
                Shapefile shp = new Shapefile();
                shp.Open(name, null);
                int layerID = mapControl.AddLayer(shp, true);
                //indexLayers.Insert(0, layerID);
            }
            else if (openDialog.SafeFileName.ToLower().EndsWith(".tif") ||
                     openDialog.SafeFileName.ToLower().EndsWith(".png") ||
                     openDialog.SafeFileName.ToLower().EndsWith(".jpg"))
            {
                MapWinGIS.Image img = new MapWinGIS.Image();
                img.Open(name, ImageType.TIFF_FILE, false, null);
                img.UseRgbBandMapping = true;
                for (int i = 0; i < img.NoBands; i++)
                {
                    bandIndex.Add(i);
                }
                //MessageBox.Show(img.UseRgbBandMapping.ToString());
                int layer = mapControl.AddLayer(img, true);

                //indexLayers.Insert(0, layer);
            }


            // List on Tree Layers
            var splited = openDialog.FileName.Split('\\');

            treeLayers.CheckBoxes  = true;
            treeLayers.AfterCheck += treeLayer_AfterCheck;
            TreeNode layerNode = new TreeNode(splited[splited.Length - 1].Split('.')[0]);

            layerNode.Checked = true;
            treeLayers.Nodes[0].Nodes.Add(layerNode);
            layerNode.Parent.Checked = true;

            // Draw Marker
            shp_tmp = new Shapefile();
            if (!shp_tmp.CreateNewWithShapeID("", ShpfileType.SHP_POINT))
            {
                MessageBox.Show("Failed to create shapefile: " + shp_tmp.ErrorMsg[shp_tmp.LastErrorCode]);
                return(false);
            }
            int layer_tmp = mapControl.AddLayer(shp_tmp, true);

            mapControl.CursorMode      = tkCursorMode.cmNone;
            mapControl.MouseDownEvent += mapControl_MouseDownEvent;
            return(this.mapControl.NumLayers > 0);
        }
Beispiel #17
0
        public void RemoveLayer()
        {
            if (layerHandle != -1)
            {
                map.RemoveLayer(layerHandle);

                sf = new Shapefile();
                sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
                layerHandle = -1;
            }
        }
Beispiel #18
0
        public static Shapefile CreateSf(ShpfileType shpfileType)
        {
            var sf = new Shapefile();

            if (!sf.CreateNewWithShapeID("", shpfileType))
            {
                throw new Exception("Can't create shapefile. Error: " + sf.ErrorMsg[sf.LastErrorCode]);
            }

            return(sf);
        }
Beispiel #19
0
        private static void MergeShapefile(tkGeometryEngine geometryEngine)
        {
            var tempFolder = Helper.WorkingFolder("MergeShapefile");

            const string sfInputfile  = @"D:\dev\GIS-Data\Issues\MWGIS-78 Clipper\FewPolygons.shp";
            var          sfOutputFile = Path.Combine(tempFolder, $"FewPolygons_Merged_{geometryEngine.ToString()}.shp");

            var sfInput = Helper.OpenShapefile(sfInputfile);

            if (File.Exists(sfOutputFile))
            {
                Helper.DeleteShapefile(sfOutputFile);
            }

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            sfInput.GeometryEngine = geometryEngine;
            var newShape = sfInput.Shape[0];

            for (var i = 1; i < sfInput.NumShapes; i++)
            {
                // Union all shapes together:
                newShape = newShape.Clip(sfInput.Shape[i], tkClipOperation.clUnion);
            }
            Helper.DebugMsg("Time it took: " + stopWatch.Elapsed);
            stopWatch.Restart();
            Assert.IsNotNull(newShape, "newShape is null: " + newShape.ErrorMsg[newShape.LastErrorCode]);

            var sfOutput = new Shapefile();

            sfOutput.CreateNewWithShapeID(sfOutputFile, ShpfileType.SHP_POLYGON);
            var numShape = 0;
            var retVal   = sfOutput.EditInsertShape(newShape, ref numShape);

            Assert.IsTrue(retVal, "Failed to add shape");
            sfOutput.StopEditingShapes();

            Assert.IsTrue(File.Exists(sfOutputFile), "Output does not exists");
            Helper.DebugMsg(sfOutputFile);

            Helper.DebugMsg("NumShapes: " + sfOutput.NumShapes);
            Assert.AreEqual(sfOutput.NumShapes, 1);

            if (!sfInput.Close())
            {
                Assert.Fail("Can't close sfBorder Error: " + sfInput.ErrorMsg[sfInput.LastErrorCode]);
            }
            if (!sfOutput.Close())
            {
                Assert.Fail("Can't close sfClipped Error: " + sfOutput.ErrorMsg[sfOutput.LastErrorCode]);
            }
        }
Beispiel #20
0
        private void UpdatePoint(AxMap Map, List <MapWinGIS.Point> PointsToUpdate)
        {
            var sf = new Shapefile();

            if (PointShapefileLayerHandle != -1)
            {
                sf = Map.get_Shapefile(PointShapefileLayerHandle);
            }

            if (PointShapefileLayerHandle == -1)
            {
                if (!sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT))
                {
                    MessageBox.Show("Failed to create shapefile: " + sf.ErrorMsg[sf.LastErrorCode]);
                    return;
                }
                PointShapefileLayerHandle = Map.AddLayer(sf, true);
            }
            ShapeDrawingOptions options = sf.DefaultDrawingOptions;

            options.PointType        = tkPointSymbolType.ptSymbolStandard;
            options.PointShape       = tkPointShapeType.ptShapeCross;
            sf.DefaultDrawingOptions = options;
            sf.CollisionMode         = tkCollisionMode.AllowCollisions;
            sf.EditClear();

            foreach (MapWinGIS.Point PointToUpdate in PointsToUpdate)
            {
                Shape shp = new Shape();
                shp.Create(ShpfileType.SHP_POINT);
                MapWinGIS.Point pnt = PointToUpdate;

                int Index;
                Index = shp.NumPoints;

                shp.InsertPoint(pnt, ref Index);

                Index = sf.NumShapes;

                if (!sf.EditInsertShape(shp, Index))
                {
                    MessageBox.Show("Failed to insert shape: " + sf.ErrorMsg[sf.LastErrorCode]);
                    return;
                }

                Map.Redraw();
            }
            if (PointsToUpdate.Count == 0)
            {
                Map.Redraw();
            }
        }
Beispiel #21
0
        public static Shapefile TrackFromGPX(GPXFile gpxFile, out List <int> handles)
        {
            handles = new List <int>();
            var       shpIndex = -1;
            Shapefile sf;

            if (gpxFile.TrackWaypoinsInLocalTime.Count > 0)
            {
                if (GPXMappingManager.TrackShapefile == null || GPXMappingManager.TrackShapefile.NumFields == 0)
                {
                    sf = new Shapefile();
                    if (sf.CreateNewWithShapeID("", ShpfileType.SHP_POLYLINE))
                    {
                        sf.EditAddField("GPS", FieldType.STRING_FIELD, 1, 1);
                        sf.EditAddField("Filename", FieldType.STRING_FIELD, 1, 1);
                        sf.EditAddField("Length", FieldType.DOUBLE_FIELD, 1, 1);
                        sf.EditAddField("DateStart", FieldType.DATE_FIELD, 1, 1);
                        sf.EditAddField("DateEnd", FieldType.DATE_FIELD, 1, 1);
                        sf.Key           = "gpxfile_track";
                        sf.GeoProjection = GPXManager.entities.mapping.globalMapping.GeoProjection;
                        GPXMappingManager.TrackShapefile = sf;
                    }
                }
                else
                {
                    sf = GPXMappingManager.TrackShapefile;
                }

                var shp = new Shape();
                if (shp.Create(ShpfileType.SHP_POLYLINE))
                {
                    foreach (var wlt in gpxFile.TrackWaypoinsInLocalTime)
                    {
                        shp.AddPoint(wlt.Longitude, wlt.Latitude);
                    }
                }
                shpIndex = sf.EditAddShape(shp);
                handles.Add(shpIndex);
                sf.EditCellValue(sf.FieldIndexByName["GPS"], shpIndex, gpxFile.GPS.DeviceName);
                sf.EditCellValue(sf.FieldIndexByName["FileName"], shpIndex, gpxFile.FileName);
                sf.EditCellValue(sf.FieldIndexByName["Length"], shpIndex, gpxFile.TrackLength);
                sf.EditCellValue(sf.FieldIndexByName["DateStart"], shpIndex, gpxFile.DateRangeStart);
                sf.EditCellValue(sf.FieldIndexByName["DateEnd"], shpIndex, gpxFile.DateRangeEnd);

                return(sf);
            }
            else
            {
                return(null);
            }
        }
Beispiel #22
0
        public int AddNewShapefileLayer(string layerName, ShpfileType shapefileType, bool isVisile = true, bool visibleInUI = false)
        {
            var sf = new Shapefile();

            if (sf.CreateNewWithShapeID("", shapefileType))
            {
                sf.GeoProjection = _axmap.GeoProjection;
            }
            var h = _axmap.AddLayer(sf, isVisile);

            if (h >= 0)
            {
                _axmap.set_LayerName(h, layerName);
            }
            return(h);
        }
Beispiel #23
0
        public static Shapefile AOIShapefileFromAOI(AOI aoi)
        {
            var sf = new Shapefile();

            if (sf.CreateNewWithShapeID("", ShpfileType.SHP_POLYGON))
            {
                var extent = new Extents();
                extent.SetBounds(aoi.UpperLeftX, aoi.LowerRightY, 0, aoi.LowerRightX, aoi.UpperLeftY, 0);
                if (sf.EditAddShape(extent.ToShape()) >= 0)
                {
                    sf.DefaultDrawingOptions.FillTransparency = 0.25F;
                    return(sf);
                }
            }
            return(null);
        }
Beispiel #24
0
        public static Shapefile TrackFromTrip1(Trip trip, out List <int> handles)
        {
            handles = new List <int>();
            var       shpIndex = -1;
            Shapefile sf;

            if (trip.Track.Waypoints.Count > 0)
            {
                if (TripMappingManager.TrackShapefile == null || TripMappingManager.TrackShapefile.NumFields == 0)
                {
                    sf = new Shapefile();
                    if (sf.CreateNewWithShapeID("", ShpfileType.SHP_POLYLINE))
                    {
                        sf.EditAddField("GPS", FieldType.STRING_FIELD, 1, 1);
                        sf.EditAddField("Filename", FieldType.STRING_FIELD, 1, 1);
                        sf.EditAddField("Length", FieldType.DOUBLE_FIELD, 1, 1);
                        sf.Key           = "trip_track";
                        sf.GeoProjection = globalMapping.GeoProjection;
                        TripMappingManager.TrackShapefile = sf;
                    }
                }
                else
                {
                    sf = TripMappingManager.TrackShapefile;
                }

                var shp = new Shape();
                if (shp.Create(ShpfileType.SHP_POLYLINE))
                {
                    foreach (var wpt in trip.Track.Waypoints)
                    {
                        shp.AddPoint(wpt.Longitude, wpt.Latitude);
                    }
                }
                shpIndex = sf.EditAddShape(shp);
                handles.Add(shpIndex);
                sf.EditCellValue(sf.FieldIndexByName["GPS"], shpIndex, trip.GPS.DeviceName);
                sf.EditCellValue(sf.FieldIndexByName["FileName"], shpIndex, trip.GPXFileName);
                sf.EditCellValue(sf.FieldIndexByName["Length"], shpIndex, trip.Track.Statistics.Length);

                return(sf);
            }
            else
            {
                return(null);
            }
        }
Beispiel #25
0
        public static Shapefile GPXTrackVertices(GPXFile gpxfile, out List <int> shpIndexes)
        {
            shpIndexes = new List <int>();
            Shapefile sf;

            if (gpxfile.GPXFileType == GPXFileType.Track && gpxfile.TrackWaypoinsInLocalTime.Count > 0)
            {
                sf = new Shapefile();
                if (sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT))
                {
                    sf.EditAddField("Name", FieldType.INTEGER_FIELD, 1, 1);
                    sf.EditAddField("Time", FieldType.DATE_FIELD, 1, 1);
                    sf.Key           = "gpx_track_vertices";
                    sf.GeoProjection = globalMapping.GeoProjection;
                    GPXMappingManager.TrackVerticesShapefile = sf;
                }
            }
            else
            {
                sf = GPXMappingManager.TrackVerticesShapefile;
            }

            foreach (var wlt in gpxfile.TrackWaypoinsInLocalTime)
            {
                var shp = new Shape();
                if (shp.Create(ShpfileType.SHP_POINT))
                {
                    if (shp.AddPoint(wlt.Longitude, wlt.Latitude) >= 0)
                    {
                        var shpIndex = sf.EditAddShape(shp);
                        if (shpIndex >= 0)
                        {
                            sf.EditCellValue(sf.FieldIndexByName["Name"], shpIndex, shpIndex + 1);
                            sf.EditCellValue(sf.FieldIndexByName["Time"], shpIndex, wlt.Time);
                            shpIndexes.Add(shpIndex);
                        }
                    }
                }
            }
            sf.DefaultDrawingOptions.PointShape      = tkPointShapeType.ptShapeRegular;
            sf.DefaultDrawingOptions.PointSize       = 10;
            sf.DefaultDrawingOptions.PointSidesCount = 4;
            sf.DefaultDrawingOptions.FillColor       = _mapWinGISUtils.ColorByName(tkMapColor.Orange);
            sf.DefaultDrawingOptions.LineColor       = _mapWinGISUtils.ColorByName(tkMapColor.Black);
            sf.DefaultDrawingOptions.LineWidth       = 1.5f;
            return(sf);
        }
Beispiel #26
0
        public void AddField()
        {
            bool result;
            var  sf = new Shapefile {
                GlobalCallback = this
            };

            try
            {
                // Create in-memory shapefile
                result = sf.CreateNewWithShapeID(string.Empty, ShpfileType.SHP_POINT);
                Assert.IsTrue(result, "Could not create shapefile");

                Assert.IsTrue(sf.EditingShapes, "Shapefile is not in edit shapes mode");
                Assert.IsTrue(sf.EditingTable, "Shapefile is not in edit table mode");

                // Add fields:
                Assert.IsTrue(sf.Table.EditingTable, "Table is not in edit table mode");
                // This should work:
                var fieldIndex = sf.Table.EditAddField("date", FieldType.STRING_FIELD, 0, 50);
                Assert.AreEqual(sf.NumFields - 1, fieldIndex, "Could not add string field");
                // This should work:
                fieldIndex = sf.Table.EditAddField("double", FieldType.DOUBLE_FIELD, 10, 20);
                Assert.AreEqual(sf.NumFields - 1, fieldIndex, "Could not add double field");

                // This should fail, because width cannot be 0:
                fieldIndex = sf.Table.EditAddField("date", FieldType.STRING_FIELD, 50, 0);
                Assert.AreEqual(-1, fieldIndex, "Field is not added but -1 is not returned. ");
                Console.WriteLine("Expected error: " + sf.Table.ErrorMsg[sf.Table.LastErrorCode]);

                // This should fail, because precsion cannot be 0 when type is double:
                fieldIndex = sf.Table.EditAddField("date", FieldType.DOUBLE_FIELD, 0, 20);
                Assert.AreEqual(-1, fieldIndex, "Field is not added but -1 is not returned. ");
                Console.WriteLine("Expected error: " + sf.Table.ErrorMsg[sf.Table.LastErrorCode]);
            }
            finally
            {
                // Close the shapefile:
                result = sf.Close();
                Assert.IsTrue(result, "Could not close shapefile");
            }
        }
Beispiel #27
0
        /// <summary>
        /// Creates a new in-memory FeatureSet not bound to any datasource.
        /// </summary>
        public FeatureSet(GeometryType geomType, ZValueType zValue = ZValueType.None, bool addShapeIdField = true)
        {
            if (geomType == GeometryType.None)
            {
                throw new ArgumentException("Invalid geometry type.");
            }

            var shpType = GeometryHelper.GeometryType2ShpType(geomType, zValue);

            _shapefile = new Shapefile();

            if (!addShapeIdField)
            {
                _shapefile.CreateNew("", shpType);
            }
            else
            {
                _shapefile.CreateNewWithShapeID("", shpType);
            }
        }
        // <summary>
        // Creates a point shapefile by placing 1000 points randomly
        // </summary>
        public void CreatePointShapefile(AxMap axMap1)
        {
            axMap1.Projection = tkMapProjection.PROJECTION_NONE;

            var sf = new Shapefile();

            // MWShapeId field will be added to attribute table
            bool result = sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT);

            // bounding box for the new shapefile
            double xMin = 0.0;
            double yMin = 0.0;
            double xMax = 1000.0;
            double yMax = 1000.0;

            // the location of points will be random
            Random rnd = new Random(DateTime.Now.Millisecond);

            // creating points and inserting them in the shape
            for (int i = 0; i < 1000; i++)
            {
                var pnt = new Point();
                pnt.x = xMin + (xMax - xMin) * rnd.NextDouble();
                pnt.y = yMin + (yMax - yMin) * rnd.NextDouble();

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

                int index = 0;
                shp.InsertPoint(pnt, ref index);
                sf.EditInsertShape(shp, ref i);
            }

            sf.DefaultDrawingOptions.SetDefaultPointSymbol(tkDefaultPointSymbol.dpsStar);

            // adds shapefile to the map
            axMap1.AddLayer(sf, true);

            // save if needed
            //sf.SaveAs(@"c:\points.shp", null);
        }
Beispiel #29
0
        public void SaveShapefileTest()
        {
            var tempFolder   = Path.GetTempPath();
            var tempFilename = Path.Combine(tempFolder, "CreateShapefileTest.shp");

            Helper.DeleteShapefile(tempFilename);

            bool result;
            // Create shapefile
            var sf = new Shapefile {
                GlobalCallback = this
            };

            try
            {
                result = sf.CreateNewWithShapeID(tempFilename, ShpfileType.SHP_POINT);
                Assert.IsTrue(result, "Could not create shapefile");

                Assert.IsTrue(sf.EditingShapes, "Shapefile is not in edit shapes mode");
                Assert.IsTrue(sf.EditingTable, "Shapefile is not in edit table mode");

                // Add fields:
                var fieldIndex = sf.EditAddField("date", FieldType.STRING_FIELD, 0, 50);
                Assert.AreEqual(1, fieldIndex, "Could not add field");
                fieldIndex = sf.EditAddField("remarks", FieldType.STRING_FIELD, 0, 100);
                Assert.AreEqual(2, fieldIndex, "Could not add field");
                fieldIndex = sf.EditAddField("amount", FieldType.INTEGER_FIELD, 0, 3);
                Assert.AreEqual(3, fieldIndex, "Could not add field");
                Assert.AreEqual(fieldIndex + 1, sf.NumFields, "Number of fields are incorrect");

                result = sf.Save();
                Assert.IsTrue(result, "Could not save shapefile");
                Assert.AreEqual(fieldIndex + 1, sf.NumFields, "Number of fields are incorrect");
            }
            finally
            {
                // Close the shapefile:
                result = sf.Close();
                Assert.IsTrue(result, "Could not close shapefile");
            }
        }
Beispiel #30
0
 private void axMap1_MouseDownEvent(object sender, AxMapWinGIS._DMapEvents_MouseDownEvent e)
 {
     if (PointF == 1 || PointF == 3)
     {
         double          xP     = 0;
         double          yP     = 0;
         Shapefile       sf     = new Shapefile();
         bool            result = sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
         MapWinGIS.Point pt     = new MapWinGIS.Point();
         axMap1.PixelToProj(e.x, e.y, ref xP, ref yP);
         pt.x           = xP;
         pt.y           = yP;
         comboBox1.Text = FindMinStop(xP, yP);
         Shape shp = new Shape();
         shp.Create(ShpfileType.SHP_POINT);
         shp.InsertPoint(pt, 0);
         sf.EditInsertShape(shp, 0);
         sf.DefaultDrawingOptions.SetDefaultPointSymbol(tkDefaultPointSymbol.dpsStar);
         axMap1.AddLayer(sf, true);
         axMap1.SendMouseDown = false;
     }
     if (PointF == 2 || PointF == 4)
     {
         double          xP     = 0;
         double          yP     = 0;
         Shapefile       sf     = new Shapefile();
         bool            result = sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
         MapWinGIS.Point pt     = new MapWinGIS.Point();
         axMap1.PixelToProj(e.x, e.y, ref xP, ref yP);
         pt.x           = xP;
         pt.y           = yP;
         comboBox2.Text = FindMinStop(xP, yP);
         Shape shp = new Shape();
         shp.Create(ShpfileType.SHP_POINT);
         shp.InsertPoint(pt, 0);
         sf.EditInsertShape(shp, 0);
         sf.DefaultDrawingOptions.SetDefaultPointSymbol(tkDefaultPointSymbol.dpsStar);
         axMap1.AddLayer(sf, true);
         axMap1.SendMouseDown = false;
     }
 }