Ejemplo n.º 1
0
        public void TrackCars(AxMap axMap1, string dataPath)
        {
            if (!InitMap(axMap1, dataPath))
            {
                return;
            }

            string filename = dataPath + "path.shp";

            if (!File.Exists(filename))
            {
                MessageBox.Show("Path.shp wasn't found: " + dataPath);
                return;
            }

            int handle = axMap1.AddLayerFromFilename(filename, tkFileOpenStrategy.fosAutoDetect, false);

            var sf      = axMap1.get_Shapefile(handle);
            var service = new CarService(axMap1.Extents as Extents, sf, 20);

            _carShapefile               = CreateCarShapefile(service);
            _carShapefile.Volatile      = true;
            _carShapefile.CollisionMode = tkCollisionMode.AllowCollisions;
            axMap1.AddLayer(_carShapefile, true);

            axMap1.ZoomToLayer(handle);

            service.StateChanged += ServiceStateChanged;
        }
Ejemplo n.º 2
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);
            }
        }
        public bool ZoomToLayer(string name)
        {
            ILayer zoomToLayer = MapControlTools.Layers.Where(m => m.Name == name).FirstOrDefault();

            if (zoomToLayer == null)
            {
                return(false);
            }
            if (zoomToLayer.GetType() == typeof(ResTBDamagePotentialLayer))
            {
                AxMap.ZoomToLayer(((ResTBDamagePotentialLayer)zoomToLayer).PointHandle);
            }
            else if (zoomToLayer.GetType() == typeof(ResTBRiskMapLayer))
            {
                AxMap.ZoomToLayer(((ResTBRiskMapLayer)zoomToLayer).PointHandle);
            }
            else
            {
                AxMap.ZoomToLayer(zoomToLayer.Handle);
            }
            return(true);
        }
Ejemplo n.º 4
0
 public void ZoomToLayer(int layerHandle)
 {
     _axmap.ZoomToLayer(layerHandle);
 }
Ejemplo n.º 5
0
 public static void ZoomToLayer(AxMap map, int layerHandle)
 {
     map.ZoomToLayer(layerHandle);
 }
        /// <summary>
        /// Creates a polygon shapefile by placing 100 circles randomly.
        /// </summary>
        public void CreatePolygonShapefile(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;
                var    rnd  = new Random(DateTime.Now.Millisecond);

                int fldX    = sf.EditAddField("x", FieldType.DOUBLE_FIELD, 9, 12);
                int fldY    = sf.EditAddField("y", FieldType.DOUBLE_FIELD, 9, 12);
                int fldArea = sf.EditAddField("area", FieldType.DOUBLE_FIELD, 9, 12);

                // In a loop we are creating 100 different points using the box established above.
                for (int i = 0; i < 100; 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;

                    // polygons must be clockwise
                    Shape shp = new Shape();
                    shp.Create(ShpfileType.SHP_POLYGON);

                    for (int j = 0; j < 37; j++)
                    {
                        Point pnt = new Point();
                        pnt.x = xCenter + radius * Math.Cos(j * Math.PI / 18);
                        pnt.y = yCenter - radius * Math.Sin(j * Math.PI / 18);
                        shp.InsertPoint(pnt, ref j);
                    }
                    Debug.Print(shp.Extents.ToDebugString());
                    sf.EditInsertShape(shp, ref i);

                    sf.EditCellValue(fldX, i, xCenter.ToString());
                    sf.EditCellValue(fldY, i, yCenter.ToString());
                    sf.EditCellValue(fldArea, i, Math.PI * radius * radius);
                }

                int    handle  = axMap1.AddLayer(sf, true);
                string extents = sf.Extents.ToDebugString();
                axMap1.ZoomToLayer(handle);

                sf.Categories.Generate(fldArea, tkClassificationType.ctNaturalBreaks, 7);
                ColorScheme scheme = new ColorScheme();
                scheme.SetColors2(tkMapColor.Wheat, tkMapColor.Salmon);
                sf.Categories.ApplyColorScheme(tkColorSchemeType.ctSchemeGraduated, scheme);

                axMap1.Redraw();

                // save if needed
                //sf.SaveAs(@"c:\polygons.shp", null);
            }
        }