예제 #1
0
        /// <summary>
        /// 创建面文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void createPloygonShapefileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //initialize polyline feature set
            map1.Cursor = Cursors.Cross;

            //set shape type
            shapeType = "polygon";

            //set projection
            polygonF.Projection = map1.Projection;

            //initialize the featureSet attribute table
            DataColumn column = new DataColumn("PolygonID");

            if (!polygonF.DataTable.Columns.Contains("PolygonID"))
            {
                polygonF.DataTable.Columns.Add(column);
            }

            //add the featureSet as map layer
            MapPolygonLayer polygonLayer = (MapPolygonLayer)map1.Layers.Add(polygonF);

            PolygonSymbolizer symbol = new PolygonSymbolizer(Color.Green);

            polygonLayer.Symbolizer = symbol;
            polygonLayer.LegendText = "polygon";

            firstClick = true;

            polygonmouseClick = true;
        }
예제 #2
0
 /// <summary>
 /// Draws a preview of a polygon symbolizer inside of the specified rectangle.
 /// </summary>
 /// <param name="sym">The polygon symbolizer.</param>
 /// <param name="g">The graphics object used for drawing.</param>
 /// <param name="rect">The rectangle.</param>
 private static void DrawPolygonSymbolizer(PolygonSymbolizer sym, Graphics g, Rectangle rect)
 {
     if (sym != null)
     {
         g.Clear(Color.White);
         Rectangle rect2 = new Rectangle(5, 5, rect.Width - 10, rect.Height - 10);
         sym.Draw(g, rect2);
     }
 }
        public void RenderViewContextTest()
        {
            StringDictionary parameters = new StringDictionary();

            parameters.Add("styles", "default");
            parameters.Add("width", "512");
            parameters.Add("height", "512");
            parameters.Add("crs", "EPSG:4326");
            parameters.Add("layers", "world_admin");
            parameters.Add("bgcolor", "0x0000FF");
            parameters.Add("version", "1.3.0");
            parameters.Add("format", "image/png");
            parameters.Add("request", "GetMap");
            parameters.Add("bbox", "-180,-85,180,85");

            ViewContext context = new ViewContext();

            // add context details inline for test, this is normally done by ViewContext(parameters)
            // which applies details from configuration files etc.
            context.General.Window.Width  = 512;
            context.General.Window.Height = 512;

            Layer layer = new Layer();

            layer.Title            = "World Administration Boundaries";
            layer.Table            = "world_admin";
            layer.Name             = "world_admin";
            layer.GeometryColumn   = "shape";
            layer.FeatureIdColumn  = "fid";
            layer.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Projects\\GeospatialServices\\TestGeospatialServices\\Input\\Runtime\\TestGeospatialServicesDatabase.mdf;Integrated Security=True;User Instance=True";

            Style     style     = new Style();
            UserLayer userLayer = new UserLayer();

            userLayer.UserStyles = new List <UserStyle>();
            UserStyle         userStyle        = new UserStyle();
            FeatureTypeStyle  featureTypeStyle = new FeatureTypeStyle();
            Rule              rule             = new Rule();
            PolygonSymbolizer polygon          = new PolygonSymbolizer();

            style.Name     = "default";
            userLayer.Name = "World in green";
            polygon.Fill.SvgParameters.Add(new SvgParameter("fill", "#2E8C7C"));

            BaseSymbolizer[] symbolizers = new BaseSymbolizer[] { polygon };
            rule.Symbolizers = symbolizers;
            featureTypeStyle.Rules.Add(rule);
            userStyle.FeatureTypeStyles.Add(featureTypeStyle);
            userLayer.UserStyles.Add(userStyle);
            style.SLD.StyledLayerDescriptor.UserLayers.Add(userLayer);
            layer.StyleList.Add(style);
            context.Layers.Add(layer);

            System.Drawing.Image mapImage = context.Render(parameters);
        }
예제 #4
0
        private void CreateMap()
        {
            string basePath = Server.MapPath(@"~\Shape");

            WebMap1.Projection     = KnownCoordinateSystems.Projected.World.WebMercator;
            WebMap1.MapViewExtents = new Extent(-20037508.342789, -20037508.342789, 20037508.342789, 20037508.342789);


            WebMapClient client = new WebMapClient();


            WMTClient wmt1 = new WMTClient();

            wmt1.Create(WebServiceType.BingHybrid);


            string    WMSServerWMS0 = "http://maps.ngdc.noaa.gov/soap/web_mercator/marine_geology/MapServer/WMSServer";
            WMSClient wms0          = new WMSClient();

            wms0.ReadCapabilities(WMSServerWMS0);
            wms0.CRS        = "EPSG:3857";
            wms0.Projection = KnownCoordinateSystems.Projected.World.WebMercator;


            string WMSServerWMS1 = "http://maps.ngdc.noaa.gov/soap/web_mercator/graticule/MapServer/WMSServer";

            WMSClient wms1 = new WMSClient();

            wms1.ReadCapabilities(WMSServerWMS1);
            wms1.CRS        = "EPSG:3857";
            wms1.Projection = KnownCoordinateSystems.Projected.World.WebMercator;


            client.AddService(wmt1);
            client.AddService(wms0);
            client.AddService(wms1);

            WebMap1.Back = client;


            IMapFeatureLayer  countriesLayer = (IMapFeatureLayer)WebMap1.AddLayer(basePath + @"\10m_admin_0_countries.shp");
            PolygonSymbolizer symbCountries  = new PolygonSymbolizer(Color.FromArgb(0, 191, 0));

            symbCountries.SetFillColor(Color.Transparent);
            symbCountries.OutlineSymbolizer = new LineSymbolizer(Color.Magenta, 1);
            countriesLayer.Symbolizer       = symbCountries;


            IMapFeatureLayer graticules30Layer = (IMapFeatureLayer)WebMap1.AddLayer(basePath + @"\10m_graticules_30.shp");
            LineSymbolizer   symbGratitules30  = new LineSymbolizer(Color.Red, 1);

            graticules30Layer.Symbolizer = symbGratitules30;

            graticules30Layer.IsVisible = false;
        }
예제 #5
0
        private void LbxItemsDrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index == -1)
            {
                return;
            }

            // prepare to draw the rectangle for symbol display and selection
            Rectangle outer = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                e.Graphics.FillRectangle(SystemBrushes.Highlight, outer);
            }
            else
            {
                Brush b = new SolidBrush(BackColor);
                e.Graphics.FillRectangle(b, outer);
                b.Dispose();
            }

            Rectangle inner = new Rectangle(e.Bounds.X + 5, e.Bounds.Y + 1, e.Bounds.Width - 10, e.Bounds.Height - 3);

            e.Graphics.FillRectangle(Brushes.White, inner);
            e.Graphics.DrawRectangle(Pens.Black, inner);

            // draw the symbolizer itself
            PointSymbolizer pointSym = lbxItems.Items[e.Index] as PointSymbolizer;

            if (pointSym != null)
            {
                DrawPointSymbolizer(pointSym, e.Graphics, inner);
                return;
            }

            LineSymbolizer lineSym = lbxItems.Items[e.Index] as LineSymbolizer;

            if (lineSym != null)
            {
                DrawLineSymbolizer(lineSym, e.Graphics, inner);
                return;
            }

            PolygonSymbolizer polySym = lbxItems.Items[e.Index] as PolygonSymbolizer;

            if (polySym != null)
            {
                DrawPolygonSymbolizer(polySym, e.Graphics, inner);
            }
        }
예제 #6
0
        public void createPolygonShape()
        {
            //initialize polyline feature set
            //map.Cursor = Cursors.Cross;
            polygonF = new FeatureSet(FeatureType.Polygon);
            //set shape type
            shapeType = "Polygon";
            //set projection
            polygonF.Projection = map.Projection;
            //initialize the featureSet attribute table
            DataColumn column = new DataColumn("ID");

            polygonF.DataTable.Columns.Add(column);
            //add the featureSet as map layer
            MapPolygonLayer   polygonLayer = (MapPolygonLayer)map.Layers.Add(polygonF);
            PolygonSymbolizer symbol       = new PolygonSymbolizer(Color.Green);

            polygonLayer.Symbolizer = symbol;
            polygonLayer.LegendText = "polygon";
            firstClick = true;
        }
예제 #7
0
        private static void DeserializeLayerAlternateVersion(dynamic shapefileProperties, MapPolygonLayer polyLayer)
        {
            var polySymbolizer = new PolygonSymbolizer();
            var outlineColor   = LegacyDeserializer.GetColor(shapefileProperties.DefaultDrawingOptions["LineColor"]);
            var outlineWidth   = Convert.ToDouble(shapefileProperties.DefaultDrawingOptions["LineWidth"]);

            polySymbolizer.SetOutline(outlineColor, outlineWidth);
            if (Convert.ToBoolean(shapefileProperties.DefaultDrawingOptions["FillVisible"]))
            {
                Color color        = LegacyDeserializer.GetColor(shapefileProperties.DefaultDrawingOptions["FillBgColor"]);
                float transparency = Convert.ToInt32(shapefileProperties.DefaultDrawingOptions["FillTransparency"]) / 255f;
                color = color.ToTransparent(transparency);
                polySymbolizer.SetFillColor(color);
            }
            else
            {
                polySymbolizer.SetFillColor(Color.Transparent);
            }

            polyLayer.Symbolizer = polySymbolizer;
        }
예제 #8
0
        public void GivenMapLayerWithScheme_WhenConvertingLayerFeatures_ThenClearsAppliedSchemeAndAppliesDefaultCategory()
        {
            // Given
            const string metadataAttribute = "Meta";

            var mocks       = new MockRepository();
            var categoryOne = mocks.Stub <IPolygonCategory>();
            var categoryTwo = mocks.Stub <IPolygonCategory>();

            mocks.ReplayAll();

            var mapPolygonLayer = new MapPolygonLayer
            {
                Symbology = new PolygonScheme
                {
                    Categories =
                    {
                        categoryOne,
                        categoryTwo
                    }
                }
            };

            var converter = new MapPolygonDataConverter();

            var random       = new Random(21);
            var polygonStyle = new PolygonStyle
            {
                FillColor       = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                StrokeThickness = random.Next(1, 48)
            };
            var theme = new MapTheme <PolygonCategoryTheme>(metadataAttribute, new[]
            {
                new PolygonCategoryTheme(ValueCriterionTestFactory.CreateValueCriterion(),
                                         new PolygonStyle
                {
                    FillColor       = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeThickness = random.Next(1, 48)
                })
            });
            var mapPolygonData = new MapPolygonData("test", polygonStyle, theme)
            {
                Features = new[]
                {
                    CreateMapFeatureWithMetaData(metadataAttribute)
                }
            };

            // When
            converter.ConvertLayerFeatures(mapPolygonData, mapPolygonLayer);

            // Then
            PolygonCategoryCollection categoryCollection = mapPolygonLayer.Symbology.Categories;

            Assert.AreEqual(1, categoryCollection.Count);

            PolygonSymbolizer expectedSymbolizer = CreateExpectedSymbolizer(polygonStyle);

            AssertAreEqual(expectedSymbolizer, categoryCollection.Single().Symbolizer);

            mocks.VerifyAll();
        }
        public void RenderSLDInParametersTest()
        {
            StringBuilder sld = new StringBuilder();

            sld.Append("<SLD>");
            sld.Append("<sld:StyledLayerDescriptor>");
            sld.Append("<sld:UserLayer>");
            sld.Append("<sld:Name>World</sld:Name>");
            sld.Append("<sld:UserStyles>");
            sld.Append("<sld:UserStyle>");
            sld.Append("<se:FeatureTypeStyle>");
            sld.Append("<se:Rule>");
            sld.Append("<se:PointSymbolizer>");
            sld.Append("<se:Graphic>");
            sld.Append("<se:Opacity>255</se:Opacity>");
            sld.Append("<se:Mark>");
            sld.Append("<se:WellKnownName>font://Webdings?CharIndex=114</se:WellKnownName>");
            sld.Append("<se:Fill>");
            sld.Append("<se:SvgParameter name=\"fill\">#000000</se:SvgParameter>");
            sld.Append("</se:Fill>");
            sld.Append("</se:Mark>");
            sld.Append("<se:Size>12</se:Size>");
            sld.Append("</se:Graphic>");
            sld.Append("</se:PointSymbolizer>");
            sld.Append("<se:PolygonSymbolizer>");
            sld.Append("<se:Fill>");
            sld.Append("<se:SvgParameter name=\"fill\">#2E8C7C</se:SvgParameter>");
            sld.Append("<se:SvgParameter name=\"fill-opacity\">255</se:SvgParameter>");
            sld.Append("</se:Fill>");
            sld.Append("<se:Stroke>");
            sld.Append("<se:SvgParameter name=\"stroke\">#206055</se:SvgParameter>");
            sld.Append("<se:SvgParameter name=\"stroke-opacity\">255</se:SvgParameter>");
            sld.Append("<se:SvgParameter name=\"stroke-width\">1</se:SvgParameter>");
            sld.Append("</se:Stroke>");
            sld.Append("</se:PolygonSymbolizer>");
            sld.Append("<se:LineSymbolizer>");
            sld.Append("<se:Stroke>");
            sld.Append("<se:SvgParameter name=\"stroke\">#000000</se:SvgParameter>");
            sld.Append("<se:SvgParameter name=\"stroke-width\">1</se:SvgParameter>");
            sld.Append("<se:SvgParameter name=\"stroke-opacity\">255</se:SvgParameter>");
            sld.Append("<se:SvgParameter name=\"stroke-dasharray\">Solid</se:SvgParameter>");
            sld.Append("<se:SvgParameter name=\"stroke-linecap\">Flat</se:SvgParameter>");
            sld.Append("<se:SvgParameter name=\"stroke-linejoin\">Miter</se:SvgParameter>");
            sld.Append("</se:Stroke>");
            sld.Append("</se:LineSymbolizer>");
            sld.Append("</se:Rule>");
            sld.Append("</se:FeatureTypeStyle>");
            sld.Append("</sld:UserStyle>");
            sld.Append("</sld:UserStyles>");
            sld.Append("</sld:UserLayer>");
            sld.Append("</sld:StyledLayerDescriptor>");
            sld.Append("</SLD>");

            StringDictionary parameters = new StringDictionary();

            parameters.Add(WmsParameters.Styles, "default");
            parameters.Add(WmsParameters.Width, "512");
            parameters.Add(WmsParameters.Height, "512");
            parameters.Add(WmsParameters.Crs, "EPSG:4326");
            parameters.Add(WmsParameters.Layers, "world_admin");
            parameters.Add(WmsParameters.BgColor, "0x0000FF");
            parameters.Add("version", "1.3.0");
            parameters.Add(WmsParameters.Format, "image/png");
            parameters.Add("request", "GetMap");
            parameters.Add(WmsParameters.Bbox, "-180,-85,180,85");
            parameters.Add(WmsParameters.SldBody, sld.ToString());

            ViewContext context = new ViewContext();

            // add context details inline for test, this is normally done by ViewContext(parameters)
            // which applies details from configuration files etc.
            context.General.Window.Width  = 512;
            context.General.Window.Height = 512;

            Layer layer = new Layer();

            layer.Title            = "World Administration Boundaries";
            layer.Table            = "world_admin";
            layer.Name             = "world_admin";
            layer.GeometryColumn   = "shape";
            layer.FeatureIdColumn  = "fid";
            layer.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Projects\\GeospatialServices\\TestGeospatialServices\\Input\\Runtime\\TestGeospatialServicesDatabase.mdf;Integrated Security=True;User Instance=True";

            Style     style     = new Style();
            UserLayer userLayer = new UserLayer();

            userLayer.UserStyles = new List <UserStyle>();
            UserStyle         userStyle        = new UserStyle();
            FeatureTypeStyle  featureTypeStyle = new FeatureTypeStyle();
            Rule              rule             = new Rule();
            PolygonSymbolizer polygon          = new PolygonSymbolizer();

            style.Name     = "default";
            userLayer.Name = "World in green";
            polygon.Fill.SvgParameters.Add(new SvgParameter("fill", "#2E8C7C"));

            BaseSymbolizer[] symbolizers = new BaseSymbolizer[] { polygon };
            rule.Symbolizers = symbolizers;
            featureTypeStyle.Rules.Add(rule);
            userStyle.FeatureTypeStyles.Add(featureTypeStyle);
            userLayer.UserStyles.Add(userStyle);
            style.SLD.StyledLayerDescriptor.UserLayers.Add(userLayer);
            layer.StyleList.Add(style);
            context.Layers.Add(layer);

            System.Drawing.Image mapImage = context.Render(parameters);
        }
예제 #10
0
        private void lbxItems_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index == -1)
            {
                return;
            }

            //prepare to draw the rectangle for symbol display and selection
            Rectangle outer = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                e.Graphics.FillRectangle(SystemBrushes.Highlight, outer);
            }
            else
            {
                Brush b = new SolidBrush(BackColor);
                e.Graphics.FillRectangle(b, outer);
                b.Dispose();
            }
            Rectangle inner = new Rectangle(e.Bounds.X + 5, e.Bounds.Y + 1, e.Bounds.Width - 10, e.Bounds.Height - 3);

            e.Graphics.FillRectangle(Brushes.White, inner);
            e.Graphics.DrawRectangle(Pens.Black, inner);

            //draw the symbolizer itself
            PointSymbolizer pointSym = lbxItems.Items[e.Index] as PointSymbolizer;

            if (pointSym != null)
            {
                DrawPointSymbolizer(pointSym, e.Graphics, inner);
                return;
            }

            LineSymbolizer lineSym = lbxItems.Items[e.Index] as LineSymbolizer;

            if (lineSym != null)
            {
                DrawLineSymbolizer(lineSym, e.Graphics, inner);
                return;
            }

            PolygonSymbolizer polySym = lbxItems.Items[e.Index] as PolygonSymbolizer;

            if (polySym != null)
            {
                DrawPolygonSymbolizer(polySym, e.Graphics, inner);
                return;
            }

            //IFeatureSymbolizer sym = lbxItems.Items[e.Index] as IFeatureSymbolizer;
            //if (sym == null) return;
            //Matrix old = e.Graphics.Transform;
            //Matrix shift = e.Graphics.Transform;
            //Size2D size = _symbolizers.GetBoundingSize();
            //double scaleSize = 1;
            //if (_scaleMode == ScaleModes.Geographic || size.Height > 14)
            //{
            //    scaleSize = (ItemHeight - 6) / size.Height;
            //}
            //shift.Translate(e.Bounds.Left + e.Bounds.Width / 2, e.Bounds.Top + e.Bounds.Height / 2);
            ////shift.Translate(-(float)(size.Width * scaleSize / 2), -(float)(size.Height * scaleSize / 2));
            //e.Graphics.Transform = shift;
            //sym.Draw(e.Graphics, scaleSize);
            //e.Graphics.Transform = old;
        }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LayoutRectangle"/> class.
 /// </summary>
 public LayoutRectangle()
 {
     Name        = "Rectangle";
     Background  = new PolygonSymbolizer(Color.Transparent, Color.Black, 2.0);
     ResizeStyle = ResizeStyle.HandledInternally;
 }
예제 #12
0
        /// <summary>
        /// Load base maps for World template project. The base shapefiles
        /// are loaded from the [Program Files]\[Cuahsi HIS]\HydroDesktop\maps\BaseData folder.
        /// </summary>
        public static Boolean LoadBaseMaps(AppManager applicationManager1, Map mainMap)
        {
            //set the projection of main map
            mainMap.Projection = projWorld.WebMercator;

            Extent defaultMapExtent = new Extent(-170, -50, 170, 50);

            string baseMapFolder = Settings.Instance.DefaultBaseMapDirectory;

            //MapGroup baseGroup = new MapGroup(mainMap.Layers, mainMap.MapFrame, mainMap.ProgressHandler);
            //baseGroup.LegendText = "Base Map Data";
            //baseGroup.ParentMapFrame = mainMap.MapFrame;
            //baseGroup.MapFrame = mainMap.MapFrame;
            //baseGroup.IsVisible = true;

            //load the 'Countries of the world' layer
            try
            {
                mainMap.BackColor = Color.LightBlue;

                string fileName = Path.Combine(baseMapFolder, "world_countries.shp");
                if (File.Exists(fileName))
                {
                    IFeatureSet     fsCountries  = FeatureSet.OpenFile(fileName);
                    MapPolygonLayer layCountries = new MapPolygonLayer(fsCountries);
                    layCountries.LegendText = "Countries";
                    layCountries.Symbolizer = new PolygonSymbolizer(Color.FromArgb(255, 239, 213), Color.LightGray);
                    //PolygonScheme schmCountries = new PolygonScheme();
                    //schmCountries.EditorSettings.StartColor = Color.Orange;
                    //schmCountries.EditorSettings.EndColor = Color.Silver;
                    //schmCountries.EditorSettings.ClassificationType =
                    //    ClassificationType.UniqueValues;
                    //schmCountries.EditorSettings.FieldName = "NAME";
                    //schmCountries.EditorSettings.UseGradient = true;
                    //schmCountries.CreateCategories(layCountries.DataSet.DataTable);
                    //layCountries.Symbology = schmCountries;
                    //baseGroup.Layers.Add(layCountries);
                    mainMap.Layers.Add(layCountries);
                    layCountries.MapFrame = mainMap.MapFrame;
                    layCountries.ProgressReportingEnabled = false;
                }
            }
            catch { }


            //load a rivers layer
            try
            {
                var fileName = Path.Combine(baseMapFolder, "world_rivers.shp");
                if (File.Exists(fileName))
                {
                    IFeatureSet fsRivers = FeatureSet.OpenFile(fileName);
                    //fsRivers.Reproject(mainMap.Projection);
                    MapLineLayer layRivers = new MapLineLayer(fsRivers);
                    layRivers.LegendText = "rivers";
                    LineSymbolizer symRivers = new LineSymbolizer(Color.Blue, 1.0);
                    layRivers.Symbolizer = symRivers;
                    mainMap.Layers.Add(layRivers);
                    layRivers.MapFrame = mainMap.MapFrame;
                }
            }
            catch { }

            //load a lakes layer
            try
            {
                var fileName = Path.Combine(baseMapFolder, "world_lakes.shp");
                if (File.Exists(fileName))
                {
                    IFeatureSet fsLakes = FeatureSet.OpenFile(fileName);
                    //fsLakes.Reproject(mainMap.Projection);
                    MapPolygonLayer layLakes = new MapPolygonLayer(fsLakes);
                    layLakes.LegendText = "lakes";
                    PolygonSymbolizer symLakes = new PolygonSymbolizer(Color.Blue,
                                                                       Color.Blue);
                    layLakes.Symbolizer = symLakes;
                    mainMap.Layers.Add(layLakes);
                    layLakes.MapFrame = mainMap.MapFrame;
                    layLakes.ProgressReportingEnabled = false;
                }
            }
            catch { }



            double[] xy = new double[4];
            xy[0] = defaultMapExtent.MinX;
            xy[1] = defaultMapExtent.MinY;
            xy[2] = defaultMapExtent.MaxX;
            xy[3] = defaultMapExtent.MaxY;
            double[] z     = new double[] { 0, 0 };
            var      wgs84 = ProjectionInfo.FromEsriString(Properties.Resources.wgs_84_esri_string);

            Reproject.ReprojectPoints(xy, z, wgs84, mainMap.Projection, 0, 2);

            mainMap.ViewExtents = new Extent(xy);

            return(true);
        }
    private PolygonSymbolizer CreatePolygonSymbolizer(NodePropertyValue[] properties)
    {
      PolygonSymbolizer symPolygon = new PolygonSymbolizer();
      symPolygon.Fill.Color = Color.Gray;
      symPolygon.Fill.Outlined = false;
      symPolygon.Clip = true;

      GraphicFill gFill = properties[0].Name.StartsWith("polygon-pattern-") ? new GraphicFill() : null;
      if (gFill != null)
      {
        symPolygon.Fill.GraphicFill = gFill;
        symPolygon.Fill.Opacity = 0.0F;
      }

      GeometryTransformInfo geomTrans = new GeometryTransformInfo();

      NodePropertyValue pv = null;

      try
      {
        int nProps = properties.Length;

        for (int i = 0; i < nProps; i++)
        {
          pv = properties[i];

          if (gFill != null)
          {
            switch (pv.Name)
            {
              case "polygon-pattern-file":
                ExternalGraphicSymbol egs = new ExternalGraphicSymbol();
                egs.Path = ToPath(pv.Value);
                gFill.GraphicSymbols.Add(egs);
                break;
              case "polygon-pattern-opacity":
                gFill.Opacity = Convert.ToSingle(pv.Value);
                break;
              case "polygon-pattern-comp-op":
                AddProperty(symPolygon, "comp-op", pv.Value);
                break;
            }
          }
          else
          {
            switch (pv.Name)
            {
              case "polygon-fill":
                Color clr = ColorUtility.FromHtml(pv.Value);
                symPolygon.Fill.Color = clr;
                if (clr.A != 255)
                  symPolygon.Fill.Opacity = clr.A / 255.0F;
                break;
              case "polygon-opacity":
                symPolygon.Fill.Opacity = Convert.ToSingle(pv.Value);
                break;
              case "polygon-gamma":
                UnsupportedProperty(pv);
                break;
              case "polygon-gamma-method":
                UnsupportedProperty(pv);
                break;
              case "polygon-clip":
                symPolygon.Clip = Convert.ToBoolean(pv.Value);
                break;
              case "polygon-comp-op":
                UnsupportedProperty(pv);
                AddProperty(symPolygon, "comp-op", pv.Value);
                break;
              case "polygon-simplify":
                geomTrans.Simplify = pv.Value;
                break;
              case "polygon-simplify-algorithm":
                geomTrans.SimplifyAlgorithm = pv.Value;
                break;
              case "polygon-smooth":
                geomTrans.Smooth = pv.Value;
                break;
              case "polygon-offset":
                geomTrans.Offset = pv.Value;
                break;
              case "polygon-geometry-transform":
                geomTrans.GeometryTransform = pv.Value;
                break;
            }
          }
        }
      }
      catch (Exception ex)
      {
        ThrowParsingException(ex, pv);
      }

      symPolygon.GeometryExpression = ToGeometryExpression(geomTrans);

      return symPolygon;
    }
예제 #14
0
        private void btnDrawPolygon_Click(object sender, EventArgs e)
        {
            if (polygonLayer != null)
            {
                mapMain.Layers.Remove(polygonLayer);
                polygonLayer = null;

                //reset everything
                polygonF    = new FeatureSet(FeatureType.Polygon);
                polygonFNew = new FeatureSet(FeatureType.Polygon);

                //the id of the polygon
                polygonID = 0;

                //the x coordinates
                xCoordinates = new List <double>();
                //the y coordinates
                yCoordinates = new List <double>();
            }


            //change the mouse cursor
            mapMain.Cursor = Cursors.Cross;

            //set shape type
            shapeType = "polygon";

            //set the polygon projection to the maps
            polygonF.Projection = mapMain.Projection;

            //initialize attribute table
            DataColumn column = new DataColumn("PolygonID");
            DataColumn volume = new DataColumn("Volume");

            if (!polygonF.DataTable.Columns.Contains("PolygonID"))
            {
                polygonF.DataTable.Columns.Add(column);
            }

            if (!polygonF.DataTable.Columns.Contains("Volume"))
            {
                polygonF.DataTable.Columns.Add(volume);
            }

            //add the polygon to the map layer
            polygonLayer = (MapPolygonLayer)mapMain.Layers.Add(polygonF);

            //polygon symbology
            PolygonSymbolizer symbol = new PolygonSymbolizer(Color.Peru);

            polygonLayer.Symbolizer = symbol;

            polygonLayer.LegendText = "Polygon";

            MessageBox.Show("Click on the map to draw a ploygon. Double click to stop drawing.");

            //intializes drawing polygon mode
            firstClick = true;

            polygonmouseClick = true;
        }
        public void ExerciseWmcFromCodeTest()
        {
            ViewContext context = new ViewContext();

            // Context -> General
            context.General.Window.Width     = 500;
            context.General.Window.Height    = 300;
            context.General.BoundingBox.SRS  = "EPSG:4326";
            context.General.BoundingBox.MinX = -180;
            context.General.BoundingBox.MinY = -90;
            context.General.BoundingBox.MaxX = 180;
            context.General.BoundingBox.MaxY = 90;
            context.General.Title            = "EOS Data Gateways";
            context.General.KeywordList.Add("EOS");
            context.General.KeywordList.Add("EOSDIS");
            context.General.KeywordList.Add("NASA");
            context.General.KeywordList.Add("CCRS");
            context.General.KeywordList.Add("CEOS");
            context.General.KeywordList.Add("OGC");
            context.General.Abstract       = "Map View of EOSDIS partners locations";
            context.General.LogoURL.Width  = 130;
            context.General.LogoURL.Height = 74;
            context.General.LogoURL.Format = "image/gif";
            context.General.LogoURL.OnlineResource.Type        = "simple";
            context.General.LogoURL.OnlineResource.Href        = "http://redhook.gsfc.nasa.gov/~imswww/pub/icons/logo.gif";
            context.General.DescriptionURL.Format              = "text/html";
            context.General.DescriptionURL.OnlineResource.Type = "simple";
            context.General.DescriptionURL.OnlineResource.Href = "http://eos.nasa.gov/imswelcome";
            context.General.ContactInformation.ContactPersonPrimary.ContactPerson       = "Tom Kralidis";
            context.General.ContactInformation.ContactPersonPrimary.ContactOrganisation = "Canada Centre for Remote Sensing";
            context.General.ContactInformation.ContactPosition                = "Systems Scientist";
            context.General.ContactInformation.ContactAddress.AddressType     = "postal";
            context.General.ContactInformation.ContactAddress.Address         = "615 Booth Street, room 650";
            context.General.ContactInformation.ContactAddress.City            = "Ottawa";
            context.General.ContactInformation.ContactAddress.StateOrProvince = "Ontario";
            context.General.ContactInformation.ContactAddress.Country         = "Canada";
            context.General.ContactInformation.ContactVoiceTelephone          = "+01 613 947 1828";
            context.General.ContactInformation.ContactFacsimileTelephone      = "+01 613 947 2410";
            context.General.ContactInformation.ContactElectronicMailAddress   = "*****@*****.**";

            context.Version = "1.0";
            context.Id      = "TEST";

            // Context -> Layer
            Layer layer = new Layer();

            layer.Queryable                  = 1;
            layer.Hidden                     = 0;
            layer.Server.Service             = GeospatialServices.Ogc.Common.ServiceNames.WMS;
            layer.Server.Version             = "1.0.7";
            layer.Title                      = "The GLOBE Program Visualization Server";
            layer.Server.OnlineResource.Type = "simple";
            layer.Server.OnlineResource.Href = "http://globe.digitalearth.gov/viz-bin/wmt.cgi";
            layer.Name     = "NATIONAL";
            layer.Title    = "National Boundaries";
            layer.Abstract = "Context layer: National Boundaries";
            layer.SRS      = "EPSG:4326";

            // Context -> Layer -> Format
            layer.FormatList.Add(new Format("GIF", 1));

            // Context -> Layer -> Style
            Style style1 = new Style();

            style1.Current          = 1;
            style1.Name             = "default";
            style1.LegendURL.Width  = 16;
            style1.LegendURL.Height = 16;
            style1.LegendURL.Format = "image/gif";
            style1.LegendURL.OnlineResource.Type = "simple";
            style1.LegendURL.OnlineResource.Href = "http://mapserv2.esrin.esa.it/cubestor/cubeserv.cgi?VERSION=1.1.0&REQUEST=GetLegendIcon&LAYER=WORLD_MODIS_1KM:MapAdmin&SPATIAL_TYPE=RASTER&STYLE=default&FORMAT=image//gif";


            // Context  -> Layer -> Style -> Named Layer
            NamedLayer namedLayer = new NamedLayer();

            namedLayer.Name = "Roads";

            //  Context  -> Layer -> Style -> Named Layer ->  Named Styles
            namedLayer.NamedStyles.Add(new NamedStyle("Casing"));
            namedLayer.NamedStyles.Add(new NamedStyle("Centerline"));

            //  Context  -> Layer -> Style -> Named Layer ->  User Style
            UserStyle userStyle1 = new UserStyle();

            //  Context  -> Layer -> Style -> Named Layer ->  User Style -> FeatureTypeStyle
            FeatureTypeStyle featureTypeStyle1 = new FeatureTypeStyle();
            Rule             rule1             = new Rule();

            // Context  -> Layer -> Style -> Named Layer ->  User Style -> FeatureTypeStyle -> Rule -> Symbolizers
            BaseSymbolizer[]  symbolizers          = new BaseSymbolizer[6];
            SymbolizerTypes[] symbolizerSelections = new SymbolizerTypes[6];

            // Line Symbolizer
            LineSymbolizer lineSymbolizer = new LineSymbolizer();

            lineSymbolizer.Geometry.PropertyName = "center-line";
            lineSymbolizer.Stroke.SvgParameters.Add(new SvgParameter("stroke", "#0000ff"));
            lineSymbolizer.Stroke.SvgParameters.Add(new SvgParameter("stroke-width", "2"));

            symbolizers[0]          = lineSymbolizer;
            symbolizerSelections[0] = SymbolizerTypes.LineSymbolizer;


            // Polygon Symbolizer
            PolygonSymbolizer polygonSymbolizer = new PolygonSymbolizer();

            polygonSymbolizer.Geometry.PropertyName = "the_area";
            polygonSymbolizer.Fill.SvgParameters.Add(new SvgParameter("fill", "#aaaaff"));
            polygonSymbolizer.Stroke.SvgParameters.Add(new SvgParameter("stroke", "#0000aa"));

            symbolizers[1]          = polygonSymbolizer;
            symbolizerSelections[1] = SymbolizerTypes.PolygonSymbolizer;


            // Point Symbolizer
            PointSymbolizer pointSymbolizer = new PointSymbolizer();

            // Point Symbolizer - > External Graphic 1
            ExternalGraphic externalGraphic1 = new ExternalGraphic();

            externalGraphic1.OnlineResource.Type = "simple";
            externalGraphic1.OnlineResource.Href = "http://www.vendor.com/geosym/2267.svg";
            externalGraphic1.Format = "image/svg+xml";
            pointSymbolizer.Graphic.ExternalGraphics.Add(externalGraphic1);

            // Point Symbolizer - > External Graphic 2
            ExternalGraphic externalGraphic2 = new ExternalGraphic();

            externalGraphic2.OnlineResource.Type = "simple";
            externalGraphic2.OnlineResource.Href = "http://www.vendor.com/geosym/2267.png";
            externalGraphic2.Format = "image/png";

            pointSymbolizer.Graphic.ExternalGraphics.Add(externalGraphic2);
            pointSymbolizer.Graphic.Size = 15.0;

            symbolizers[2]          = pointSymbolizer;
            symbolizerSelections[2] = SymbolizerTypes.PointSymbolizer;

            // Text Symbolizer
            TextSymbolizer textSymbolizer = new TextSymbolizer();

            textSymbolizer.Geometry.PropertyName = "locatedAt";
            textSymbolizer.Label = @"ogc:PropertyName[hospitalName]";
            textSymbolizer.Font.SvgParameters.Add(new SvgParameter("font-family", "Arial"));
            textSymbolizer.Font.SvgParameters.Add(new SvgParameter("font-family", "Sans-Serif"));
            textSymbolizer.Font.SvgParameters.Add(new SvgParameter("font-style", "italic"));
            textSymbolizer.Font.SvgParameters.Add(new SvgParameter("font-size", "10"));
            textSymbolizer.Fill.SvgParameters.Add(new SvgParameter("fill", "#000000"));
            textSymbolizer.LabelPlacement.PointPlacement = new PointPlacement();
            textSymbolizer.LabelPlacement.PointPlacement.AnchorPoint.AnchorPointX = 456;
            textSymbolizer.LabelPlacement.PointPlacement.AnchorPoint.AnchorPointY = 123;
            textSymbolizer.LabelPlacement.PointPlacement.Rotation = 180;
            textSymbolizer.LabelPlacement.PointPlacement.Displacement.DisplacementX = 111;
            textSymbolizer.LabelPlacement.PointPlacement.Displacement.DisplacementY = 222;
            textSymbolizer.LabelPlacement.LinePlacement                     = new LinePlacement();
            textSymbolizer.LabelPlacement.LinePlacement.Gap                 = 12;
            textSymbolizer.LabelPlacement.LinePlacement.GeneraliseLine      = 3;
            textSymbolizer.LabelPlacement.LinePlacement.InitialGap          = 3;
            textSymbolizer.LabelPlacement.LinePlacement.IsAligned           = 0;
            textSymbolizer.LabelPlacement.LinePlacement.IsRepeated          = 1;
            textSymbolizer.LabelPlacement.LinePlacement.PerpendicularOffset = 5;
            textSymbolizer.Halo.Fill = new Fill();
            textSymbolizer.Halo.Fill.SvgParameters.Add(new SvgParameter("fill", "#000000"));
            textSymbolizer.Halo.Radius = 3;

            symbolizers[3]          = textSymbolizer;
            symbolizerSelections[3] = SymbolizerTypes.TextSymbolizer;

            // Raster Symbolizer 1
            RasterSymbolizer rasterSymbolizer1 = new RasterSymbolizer();

            rasterSymbolizer1.Opacity          = 1.0;
            rasterSymbolizer1.OverlapBehaviour = OverlapBehaviourTypes.Average;
            rasterSymbolizer1.ColourMap.Categorize.LookupValue = "Rasterdata";
            rasterSymbolizer1.ColourMap.Categorize.Values.Add("#00ff00");
            rasterSymbolizer1.ColourMap.Categorize.Thresholds.Add(-417);
            rasterSymbolizer1.ColourMap.Categorize.Values.Add("#00fa00");
            rasterSymbolizer1.ColourMap.Categorize.Thresholds.Add(-333);

            symbolizers[4]          = rasterSymbolizer1;
            symbolizerSelections[4] = SymbolizerTypes.RasterSymbolizer;

            // Raster Symbolizer 2
            RasterSymbolizer rasterSymbolizer2 = new RasterSymbolizer();

            rasterSymbolizer2.Opacity          = 1.0;
            rasterSymbolizer2.OverlapBehaviour = OverlapBehaviourTypes.LatestOnTop;
            rasterSymbolizer2.ChannelSelection.RedChannel.SourceChannelName   = "1";
            rasterSymbolizer2.ChannelSelection.GreenChannel.SourceChannelName = "2";
            rasterSymbolizer2.ChannelSelection.GreenChannel.ContrastEnhancement.GammaValue = 2.5;
            rasterSymbolizer2.ChannelSelection.BlueChannel.SourceChannelName = "3";
            rasterSymbolizer2.ColourMap.Interpolate.FallBackValue            = "#dddddd";
            rasterSymbolizer2.ColourMap.Interpolate.LookupValue = "Rasterdata";
            rasterSymbolizer2.ColourMap.Interpolate.InterpolationPoints.Add(new InterpolationPoint(0, "#000000"));
            rasterSymbolizer2.ColourMap.Interpolate.InterpolationPoints.Add(new InterpolationPoint(255, "#ffffff"));
            rasterSymbolizer2.ContrastEnhancement.GammaValue = 1;
            rasterSymbolizer2.Geometry.PropertyName          = "Coastlines";

            symbolizers[5]          = rasterSymbolizer2;
            symbolizerSelections[5] = SymbolizerTypes.RasterSymbolizer;

            rule1.SymbolizerSelections = symbolizerSelections;
            rule1.Symbolizers          = symbolizers;

            featureTypeStyle1.Rules.Add(rule1);

            Rule rule2 = new Rule();

            rule2.ElseFilter = new ElseFilter();
            featureTypeStyle1.Rules.Add(rule2);


            Rule rule3 = new Rule();

            GeospatialServices.Ogc.Wmc.PropertyIsEqualTo propEqualTo = new PropertyIsEqualTo();
            propEqualTo.Literal.Value = "NEW YORK";
            propEqualTo.PropertyName  = "SALES_AREA";

            //BaseComparisonOps ComparisonOps[] = new BaseComparisonOps[2];

            rule3.Filter.FilterExpression = propEqualTo;
            featureTypeStyle1.Rules.Add(rule3);

            userStyle1.FeatureTypeStyles.Add(featureTypeStyle1);
            namedLayer.UserStyles.Add(userStyle1);

            // Context - > Layer -> Style -> User Layer
            UserLayer userLayer = new UserLayer();

            userLayer.Name = "Lakes and Rivers";

            UserStyle userStyle = new UserStyle("Default");

            userStyle.FeatureTypeStyles.Add(featureTypeStyle1);
            userLayer.UserStyles = new List <UserStyle>();
            userLayer.UserStyles.Add(userStyle);

            style1.SLD.StyledLayerDescriptor.NamedLayers.Add(namedLayer);
            style1.SLD.StyledLayerDescriptor.UserLayers.Add(userLayer);

            layer.StyleList.Add(style1);
            context.Layers.Add(layer);
        }
예제 #16
0
        /// <summary>
        /// Deserializes the layer.
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <param name="polyLayer">The poly layer.</param>
        internal static void DeserializeLayer(dynamic layer, MapPolygonLayer polyLayer)
        {
            if (UseAlternateParser(layer))
            {
                DeserializeLayerAlternateVersion(layer.ShapefileProperties, polyLayer);
                return;
            }
            var polySymbolizer = new PolygonSymbolizer();
            var outlineColor   = LegacyDeserializer.GetColor(layer.ShapeFileProperties["OutLineColor"]);
            var outlineWidth   = Convert.ToDouble(layer.ShapeFileProperties["LineOrPointSize"]);

            polySymbolizer.SetOutline(outlineColor, outlineWidth);
            if (Convert.ToBoolean(layer.ShapeFileProperties["DrawFill"]))
            {
                Color color        = LegacyDeserializer.GetColor(layer.ShapeFileProperties["Color"]);
                float transparency = Convert.ToSingle(layer.ShapeFileProperties["TransparencyPercent"]);
                color = color.ToTransparent(transparency);
                polySymbolizer.SetFillColor(color);
            }
            else
            {
                polySymbolizer.SetFillColor(Color.Transparent);
            }

            polyLayer.Symbolizer = polySymbolizer;
            try
            {
                int fieldIndex = Convert.ToInt32(layer.ShapeFileProperties.Legend["FieldIndex"]);

                // we have to clear the categories or the collection ends up with a default item
                polyLayer.Symbology.Categories.Clear();

                foreach (var colorBreak in layer.ShapeFileProperties.Legend.ColorBreaks.Elements())
                {
                    PolygonCategory category;

                    string startValue = colorBreak["StartValue"];
                    string endValue   = colorBreak["EndValue"];

                    if (startValue == endValue)
                    {
                        category = new PolygonCategory(LegacyDeserializer.GetColor(colorBreak["StartColor"]), LegacyDeserializer.GetColor(colorBreak["StartColor"]), 0);
                        category.FilterExpression = String.Format("[{0}] = '{1}'", polyLayer.DataSet.DataTable.Columns[fieldIndex].ColumnName, startValue);
                        category.LegendText       = startValue;
                    }
                    else
                    {
                        category = new PolygonCategory(LegacyDeserializer.GetColor(colorBreak["StartColor"]), LegacyDeserializer.GetColor(colorBreak["EndColor"]), 0, GradientType.Linear, outlineColor, outlineWidth);
                        category.FilterExpression = String.Format("'{2}' >= [{0}] >= '{1}'", polyLayer.DataSet.DataTable.Columns[fieldIndex].ColumnName, startValue, endValue);
                        category.LegendText       = String.Format("{0} - {1}", startValue, endValue);
                    }
                    category.LegendText        = startValue;
                    category.LegendItemVisible = Convert.ToBoolean(colorBreak["Visible"]);
                    polyLayer.Symbology.AddCategory(category);
                }

                // it took too a lot of work to figure out that we would need to do this...
                polyLayer.ApplyScheme(polyLayer.Symbology);
            }
            catch (RuntimeBinderException)
            {
                // ignore and continue.
                // this means the legend is not available.
            }
        }
예제 #17
0
        private bool DrawMonitorMap()
        {
            try
            {
                IFeatureSet fsPoints = new FeatureSet();
                fsPoints.DataTable.Columns.Add("Name");
                fsPoints.DataTable.Columns.Add("Description");
                fsPoints.DataTable.Columns.Add("Longitude");
                fsPoints.DataTable.Columns.Add("Latitude");
                string[] tmps = new string[_lstMonitorPoints[0].dicMetricValues.Count];
                _lstMonitorPoints[0].dicMetricValues.Keys.CopyTo(tmps, 0);
                for (int i = 0; i < tmps.Length; i++)
                {
                    fsPoints.DataTable.Columns.Add(tmps[i]);
                }
                MonitorValue      mv            = null;
                Feature           feature       = null;
                List <Coordinate> lstCoordinate = new List <Coordinate>();
                List <double>     fsInter       = new List <double>();
                mainMap.Layers.Clear();
                mainMap.ProjectionModeReproject = ActionMode.Never;
                mainMap.ProjectionModeDefine    = ActionMode.Never;
                mainMap.Layers.Clear();
                if (File.Exists(this._gridShapeFile))
                {
                    mainMap.Layers.Add(this._gridShapeFile);
                }
                if (this._lstMonitorPoints != null && this.LstMonitorPoints.Count > 0)
                {
                    PolygonScheme   myScheme = new PolygonScheme();
                    PolygonCategory pcin     = new PolygonCategory();
                    pcin.Symbolizer.SetFillColor(Color.Red);
                    myScheme.Categories.Add(pcin);
                    DotSpatial.Topology.Point point;
                    for (int i = 0; i < LstMonitorPoints.Count; i++)
                    {
                        mv      = LstMonitorPoints[i];
                        point   = new DotSpatial.Topology.Point(mv.Longitude, mv.Latitude);
                        feature = new Feature(point);

                        fsPoints.AddFeature(feature);

                        fsPoints.DataTable.Rows[i]["Name"]      = mv.MonitorName;
                        fsPoints.DataTable.Rows[i]["Latitude"]  = mv.Latitude;
                        fsPoints.DataTable.Rows[i]["Longitude"] = mv.Longitude;
                        for (int col = 0; col < tmps.Length; col++)
                        {
                            fsPoints.DataTable.Rows[i][tmps[col]] = mv.dicMetricValues[tmps[col]];
                        }
                    }
                    mainMap.Layers.Add(fsPoints);
                    mainMap.Layers[0].LegendText = "Air quality grid";
                    mainMap.Layers[1].LegendText = "Monitors";
                }
                PolygonLayer      player      = mainMap.Layers[0] as PolygonLayer;
                float             f           = 0.9f;
                Color             c           = Color.Transparent;
                PolygonSymbolizer Transparent = new PolygonSymbolizer(c);
                Transparent.OutlineSymbolizer = new LineSymbolizer(Color.DarkBlue, 1); player.Symbolizer = Transparent;
                LayerObject = null;
                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                return(false);
            }
        }
예제 #18
0
        public void ConvertLayerProperties_MapPolygonDataWithThemeAndMetaDataNameInFeatures_ConvertDataToMapPolygonLayer()
        {
            // Setup
            const string metadataAttribute = "Meta";
            var          random            = new Random(21);

            var unequalCriterion = new ValueCriterion(ValueCriterionOperator.UnequalValue,
                                                      "unequal value");
            var equalCriterion = new ValueCriterion(ValueCriterionOperator.EqualValue,
                                                    "equal value");
            var theme = new MapTheme <PolygonCategoryTheme>(metadataAttribute, new[]
            {
                new PolygonCategoryTheme(equalCriterion, new PolygonStyle
                {
                    FillColor       = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeThickness = random.Next(1, 48)
                }),
                new PolygonCategoryTheme(unequalCriterion, new PolygonStyle
                {
                    FillColor       = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeThickness = random.Next(1, 48)
                })
            });

            var polygonStyle = new PolygonStyle
            {
                FillColor       = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                StrokeThickness = random.Next(1, 48)
            };
            var mapPolygonData = new MapPolygonData("test", polygonStyle, theme)
            {
                Features = new[]
                {
                    CreateMapFeatureWithMetaData(metadataAttribute)
                }
            };

            var mapPolygonLayer = new MapPolygonLayer();

            var converter = new MapPolygonDataConverter();

            // Call
            converter.ConvertLayerProperties(mapPolygonData, mapPolygonLayer);

            // Assert
            PolygonSymbolizer expectedSymbolizer = CreateExpectedSymbolizer(polygonStyle);

            IPolygonScheme appliedScheme = mapPolygonLayer.Symbology;

            Assert.AreEqual(3, appliedScheme.Categories.Count);

            IPolygonCategory baseCategory = appliedScheme.Categories[0];

            AssertAreEqual(expectedSymbolizer, baseCategory.Symbolizer);
            Assert.IsNull(baseCategory.FilterExpression);

            IPolygonCategory equalSchemeCategory = appliedScheme.Categories[1];
            string           expectedFilter      = $"[1] = '{equalCriterion.Value}'";

            Assert.AreEqual(expectedFilter, equalSchemeCategory.FilterExpression);
            PolygonStyle expectedCategoryStyle = theme.CategoryThemes.ElementAt(0).Style;

            expectedSymbolizer = CreateExpectedSymbolizer(expectedCategoryStyle);
            AssertAreEqual(expectedSymbolizer, equalSchemeCategory.Symbolizer);

            IPolygonCategory unEqualSchemeCategory = appliedScheme.Categories[2];

            expectedFilter = $"NOT [1] = '{unequalCriterion.Value}'";
            Assert.AreEqual(expectedFilter, unEqualSchemeCategory.FilterExpression);
            expectedCategoryStyle = theme.CategoryThemes.ElementAt(1).Style;
            expectedSymbolizer    = CreateExpectedSymbolizer(expectedCategoryStyle);
            AssertAreEqual(expectedSymbolizer, unEqualSchemeCategory.Symbolizer);
        }
예제 #19
0
 private void DrawPolygonSymbolizer(PolygonSymbolizer sym, Graphics g, Rectangle rect)
 {
     if (sym != null)
     {
         g.Clear(Color.White);
         Rectangle rect2 = new Rectangle(5, 5, rect.Width - 10, rect.Height - 10);
         sym.Draw(g, rect2);
     }
 }
예제 #20
0
        private void MonitorRollbackSettings2_Load(object sender, EventArgs e)
        {
            try
            {
                if (CommonClass.GBenMAPGrid == null)
                {
                    return;
                }
                mainMap.ProjectionModeReproject = ActionMode.Never;
                mainMap.ProjectionModeDefine    = ActionMode.Never;
                if (_monitorRollbackLine.RollbackGrid is ShapefileGrid)
                {
                    if (File.Exists(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.MainSetup.SetupName + "\\" + (_monitorRollbackLine.RollbackGrid as ShapefileGrid).ShapefileName + ".shp"))
                    {
                        mainMap.Layers.Add(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.MainSetup.SetupName + "\\" + (_monitorRollbackLine.RollbackGrid as ShapefileGrid).ShapefileName + ".shp");
                    }
                }
                else if (_monitorRollbackLine.RollbackGrid is RegularGrid)
                {
                    if (File.Exists(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.MainSetup.SetupName + "\\" + (_monitorRollbackLine.RollbackGrid as RegularGrid).ShapefileName + ".shp"))
                    {
                        mainMap.Layers.Add(CommonClass.DataFilePath + @"\Data\Shapefiles\" + CommonClass.MainSetup.SetupName + "\\" + (_monitorRollbackLine.RollbackGrid as RegularGrid).ShapefileName + ".shp");
                    }
                }
                PolygonLayer playerRegion = mainMap.Layers[mainMap.Layers.Count - 1] as PolygonLayer;
                playerRegion.DataSet.DataTable.Columns.Add("MyColorIndex", typeof(int));
                for (int i = 0; i < playerRegion.DataSet.DataTable.Rows.Count; i++)
                {
                    playerRegion.DataSet.DataTable.Rows[i]["MyColorIndex"] = i;
                    dicMyColorIndex.Add(Convert.ToInt32(playerRegion.DataSet.DataTable.Rows[i]["COL"]).ToString() + "," + Convert.ToInt32(playerRegion.DataSet.DataTable.Rows[i]["ROW"]).ToString(), i);
                }
                Color             cRegion           = Color.Transparent;
                PolygonSymbolizer TransparentRegion = new PolygonSymbolizer(cRegion);

                TransparentRegion.OutlineSymbolizer = new LineSymbolizer(Color.Black, 1); playerRegion.Symbolizer = TransparentRegion;

                lstMonitorValues = DataSourceCommonClass.GetMonitorData(_monitorRollbackLine.GridType, _monitorRollbackLine.Pollutant, _monitorRollbackLine);
                IFeatureSet  fsPoints = new FeatureSet();
                MonitorValue mv       = null;
                Feature      feature  = null;
                List <DotSpatial.Topology.Coordinate> lstCoordinate = new List <DotSpatial.Topology.Coordinate>();
                List <double> fsInter = new List <double>();
                if (lstMonitorValues != null && lstMonitorValues.Count > 0)
                {
                    PolygonScheme   myScheme = new PolygonScheme();
                    PolygonCategory pcin     = new PolygonCategory();
                    pcin.Symbolizer.SetFillColor(Color.Red);
                    myScheme.Categories.Add(pcin);
                    DotSpatial.Topology.Point point;
                    for (int i = 0; i < lstMonitorValues.Count; i++)
                    {
                        mv      = lstMonitorValues[i];
                        point   = new DotSpatial.Topology.Point(mv.Longitude, mv.Latitude);
                        feature = new Feature(point);
                        fsPoints.AddFeature(feature);
                    }
                    mainMap.Layers.Add(fsPoints);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
        }
예제 #21
0
        private void associateLayer(IFeatureSet aLayer, IFeatureSet bLayer)
        {
            if (featureLayerConflict != null)
            {
                #region 加载一个临时内存图层,为空间范围划定服务
                //IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
                //IWorkspaceName workspaceName = workspaceFactory.Create("", "tempWorkspace", null, 0);
                //IName name = (IName)workspaceName;
                //IWorkspace inmemWor = (IWorkspace)name.Open();

                //IField oField = new FieldClass();
                //IFields oFields = new FieldsClass();
                //IFieldsEdit oFieldsEdit = null;
                //IFieldEdit oFieldEdit = null;

                //oFieldsEdit = oFields as IFieldsEdit;
                //oFieldEdit = oField as IFieldEdit;

                //IGeometryDef geometryDef = new GeometryDefClass();
                //IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
                //geometryDefEdit.AvgNumPoints_2 = 5;
                //geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                //geometryDefEdit.GridCount_2 = 1;
                //geometryDefEdit.HasM_2 = false;
                //geometryDefEdit.HasZ_2 = false;
                //geometryDefEdit.SpatialReference_2 = (featureLayerConflict.FeatureClass as IGeoDataset).SpatialReference;

                //oFieldEdit.Name_2 = "SHAPE";
                //oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                //oFieldEdit.GeometryDef_2 = geometryDef;
                //oFieldEdit.IsNullable_2 = true;
                //oFieldEdit.Required_2 = true;
                //oFieldsEdit.AddField(oField);

                //IFeatureClass featureClass = (inmemWor as IFeatureWorkspace).CreateFeatureClass("tempLayer", oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                //IFeatureLayer featurelayer = new FeatureLayerClass();
                //featurelayer.Name = "临时图层";
                //featurelayer.FeatureClass = featureClass;

                //ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
                //simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSNull;
                //ILineSymbol lineSymbol = new SimpleLineSymbolClass();
                //RgbColorClass rgbcolor = new RgbColorClass();
                //rgbcolor.Red = 255;
                //rgbcolor.Green = 0;
                //rgbcolor.Blue = 0;
                //lineSymbol.Color = rgbcolor as IColor;
                //lineSymbol.Width = 1;
                //simpleFillSymbol.Outline = lineSymbol;

                //ISimpleRenderer simpleRender = new SimpleRendererClass();
                //simpleRender.Symbol = simpleFillSymbol as ISymbol;

                //IGeoFeatureLayer geoFeatureLayer = featurelayer as IGeoFeatureLayer;
                //geoFeatureLayer.Renderer = simpleRender as IFeatureRenderer;

                //axMapControlConflict.AddLayer(featurelayer as ILayer, 0);
                #endregion
                IMapPolygonLayer   polyLayer1      = new MapPolygonLayer(featureLayerA);
                IPolygonSymbolizer polySymbolizer1 = new PolygonSymbolizer(Color.FromArgb(0, Color.Yellow), Color.Red, 1);
                polyLayer1.Symbolizer = polySymbolizer1;
                this.mapConflict.MapFrame.DrawingLayers.Add(polyLayer1);

                IMapPolygonLayer   polyLayer2      = new MapPolygonLayer(featureLayerB);
                IPolygonSymbolizer polySymbolizer2 = new PolygonSymbolizer(Color.FromArgb(0, Color.Yellow), Color.Purple, 1);
                polyLayer2.Symbolizer = polySymbolizer2;
                this.mapConflict.MapFrame.DrawingLayers.Add(polyLayer2);

                this.mapConflict.Refresh();
            }
            this.mapConflict.ClearLayers();
            this.mapConflict.Layers.Add(featureLayerConflict);

            this.mapA.ClearLayers();
            this.mapA.Layers.Add(aLayer);

            this.mapB.ClearLayers();
            this.mapB.Layers.Add(bLayer);

            if (featureLayerConflict != null)
            {
                //LoadAttributeTable(featureLayerConflict.FeatureClass);
            }
        }