예제 #1
0
 //绘制Polygon要素
 private void DrawPolygon(Graphics g, Geometry geom, int index)
 {
     if (geom != null)
     {
         //提取坐标信息
         string GeomWkt;
         geom.ExportToWkt(out GeomWkt);
         string[] str = GeomWkt.Split(new char[4] {
             ' ', '(', ')', ','
         });
         List <PointF> ScreenPoints = new List <PointF>();
         for (int k = 3; k < str.Count() - 3; k += 2)
         {
             PointF point       = new PointF(Convert.ToSingle(str[k]), Convert.ToSingle(str[k + 1]));
             PointF screenPoint = FromMapPoint(point);
             if ((int)screenPoint.X == -2147483648)
             {
                 return;
             }
             ScreenPoints.Add(screenPoint);
         }
         if (MapLayers[index].Style.Styles.Count == 0)
         {
             //绘制
             g.FillPolygon(new SolidBrush(Color.Orange), ScreenPoints.ToArray());
             g.DrawPolygon(new Pen(Color.Black), ScreenPoints.ToArray());
         }
         else // 按Style绘制
         {
             // 遍历规则
             List <LayerStyle.FeatureTypeStyle.Rule> Rules = MapLayers[index].Style.Styles[0].Rules;
             for (int i = 0; i < Rules.Count; ++i)
             {
                 if (Rules[i].PolygonSymbol.Stroke.Enabled)
                 {
                     SolidBrush brush;
                     Pen        pen;
                     if (Rules[i].PolygonSymbol.Fill.Enabled)
                     {
                         brush = new SolidBrush(Color.FromArgb(Convert.ToInt32(255 * Rules[i].PolygonSymbol.Fill.Opacity),
                                                               ColorTranslator.FromHtml(Rules[i].PolygonSymbol.Fill.Color)));
                         g.FillPolygon(brush, ScreenPoints.ToArray());
                     }
                     pen = new Pen(Color.FromArgb(Convert.ToInt32(255 * Rules[i].PolygonSymbol.Stroke.Opacity),
                                                  ColorTranslator.FromHtml(Rules[i].PolygonSymbol.Stroke.Color)), (float)Rules[i].PolygonSymbol.Stroke.Width);
                     g.DrawPolygon(pen, ScreenPoints.ToArray());
                 }
             }
         }
     }
 }
예제 #2
0
        //绘制Point要素
        private void DrawPoint(Graphics g, Geometry geom, int index, int fid)
        {
            if (geom != null)
            {
                //提取坐标信息
                string GeomWkt;
                geom.ExportToWkt(out GeomWkt);
                string[] str = GeomWkt.Split(new char[3] {
                    ' ', '(', ')'
                });
                PointF point = new PointF();
                point.X = Convert.ToSingle(str[2]);
                point.Y = Convert.ToSingle(str[3]);
                //计算屏幕坐标
                PointF ScreenPoint = FromMapPoint(point);
                if ((int)ScreenPoint.X == -2147483648)
                {
                    return;
                }

                if (MapLayers[index].Style.Styles.Count == 0)
                {
                    g.FillEllipse(new SolidBrush(Color.Blue), new RectangleF((float)(ScreenPoint.X - 2), (float)(ScreenPoint.Y - 2), 4, 4));
                }

                else
                {
                    SolidBrush brush;
                    RectangleF rect;
                    Pen        pen;
                    // 按照Style绘制
                    // 遍历规则
                    List <LayerStyle.FeatureTypeStyle.Rule> Rules = MapLayers[index].Style.Styles[0].Rules;
                    for (int i = 0; i < Rules.Count; ++i)
                    {
                        if (Rules[i].FiltersAnd.Count != 0)
                        {
                            bool RuleEnabled = true;
                            // 判断条件
                            for (int j = 0; j < Rules[i].FiltersAnd.Count; ++j)
                            {
                                string filter = "FID = " + Convert.ToString(fid);
                                double value  = Convert.ToDouble(MapLayers[index].DT.Rows[fid][
                                                                     Rules[i].FiltersAnd[j].PropertyName]);
                                if (Rules[i].FiltersAnd[j].Criterion == "ge")
                                {
                                    if (value < Rules[i].FiltersAnd[j].Literal)
                                    {
                                        RuleEnabled = false;
                                        break;
                                    }
                                }
                                else if (Rules[i].FiltersAnd[j].Criterion == "le")
                                {
                                    if (value > Rules[i].FiltersAnd[j].Literal)
                                    {
                                        RuleEnabled = false;
                                        break;
                                    }
                                }
                            }
                            if (RuleEnabled)
                            {
                                // 画点
                                if (Rules[i].PointSymbol.Fill.Enabled)
                                {
                                    brush = new SolidBrush(Color.FromArgb(Convert.ToInt32(255 * Rules[i].PointSymbol.Fill.Opacity),
                                                                          ColorTranslator.FromHtml(Rules[i].PointSymbol.Fill.Color)));
                                    string sizestr = Convert.ToString(MapLayers[index].DT.Rows[fid][
                                                                          Rules[i].PointSymbol.SizePropertyName]);
                                    if (sizestr == "Infinity")
                                    {
                                        sizestr = "100";
                                    }
                                    float size = Convert.ToSingle(sizestr);
                                    rect = new RectangleF((float)(ScreenPoint.X - size * 0.5), (float)(ScreenPoint.Y - size * 0.5), size, size);
                                    g.FillEllipse(brush, rect);
                                    if (Rules[i].PointSymbol.Stroke.Enabled)
                                    {
                                        pen = new Pen(Color.FromArgb(Convert.ToInt32(255 * Rules[i].PointSymbol.Stroke.Opacity),
                                                                     ColorTranslator.FromHtml(Rules[i].PointSymbol.Stroke.Color)), (float)Rules[i].PointSymbol.Stroke.Width);
                                        g.DrawEllipse(pen, rect);
                                    }
                                }
                            }
                        }
                        if (Rules[i].FiltersOr.Count != 0)
                        {
                            // 示例数据里没有
                        }
                    }
                }
            }
        }