Example #1
0
 internal static Geometries.GeometryCollection ToSharpMapGeometryCollection(NTSGeometryCollection geom)
 {
     Geometries.GeometryCollection collection = new Geometries.GeometryCollection();
     foreach (NTSGeometry geometry in geom.Geometries)
     {
         collection.Collection.Add(ToSharpMapGeometry(geometry));
     }
     return(collection);
 }
Example #2
0
        internal static NTSGeometryCollection ToNTSGeometryCollection(Geometries.GeometryCollection geom,
                                                                      IGeometryFactory factory)
        {
            NTSGeometry[] geometries = new NTSGeometry[geom.Collection.Count];
            int           index      = 0;

            foreach (Geometries.Geometry geometry in geom.Collection)
            {
                geometries[index++] = ToNTSGeometry(geometry, factory);
            }
            return(factory.CreateGeometryCollection(geometries) as NTSGeometryCollection);
        }
Example #3
0
        public override void Render(System.Drawing.Graphics g, Map map)
        {
            if (this.Style.Enabled && this.Style.MaxVisible >= map.Zoom && this.Style.MinVisible < map.Zoom)
            {
                if (this.DataSource == null)
                {
                    throw (new ApplicationException("DataSource property not set on layer '" + this.LayerName + "'"));
                }
                g.TextRenderingHint = this.TextRenderingHint;
                g.SmoothingMode     = this.SmoothingMode;

                SharpMap.Geometries.BoundingBox envelope = map.Envelope; //View to render
                if (this.CoordinateTransformation != null)
                {
                    envelope = SharpMap.CoordinateSystems.Transformations.GeometryTransform.TransformBox(envelope, this.CoordinateTransformation.MathTransform.Inverse());
                }

                SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
                this.DataSource.Open();
                this.DataSource.ExecuteIntersectionQuery(envelope, ds);
                this.DataSource.Close();
                if (ds.Tables.Count == 0)
                {
                    base.Render(g, map);
                    return;
                }
                SharpMap.Data.FeatureDataTable features = (SharpMap.Data.FeatureDataTable)ds.Tables[0];

                //Initialize label collection
                List <Rendering.Label> labels = new List <SharpMap.Rendering.Label>();

                //List<System.Drawing.Rectangle> LabelBoxes; //Used for collision detection
                //Render labels
                for (int i = 0; i < features.Count; i++)
                {
                    SharpMap.Data.FeatureDataRow feature = features[i];
                    if (this.CoordinateTransformation != null)
                    {
                        features[i].Geometry = SharpMap.CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(features[i].Geometry, this.CoordinateTransformation.MathTransform);
                    }

                    SharpMap.Styles.LabelStyle style = null;
                    if (this.Theme != null) //If thematics is enabled, lets override the style
                    {
                        style = this.Theme.GetStyle(feature) as SharpMap.Styles.LabelStyle;
                    }
                    else
                    {
                        style = this.Style;
                    }

                    float rotation = 0;
                    if (!String.IsNullOrEmpty(this.RotationColumn))
                    {
                        float.TryParse(feature[this.RotationColumn].ToString(), System.Globalization.NumberStyles.Any, SharpMap.Map.numberFormat_EnUS, out rotation);
                    }

                    string text;
                    if (_getLabelMethod != null)
                    {
                        text = _getLabelMethod(feature);
                    }
                    else
                    {
                        text = feature[this.LabelColumn].ToString();
                    }

                    if (text != null && text != String.Empty)
                    {
                        if (feature.Geometry is SharpMap.Geometries.GeometryCollection)
                        {
                            if (this.MultipartGeometryBehaviour == MultipartGeometryBehaviourEnum.All)
                            {
                                foreach (SharpMap.Geometries.Geometry geom in (feature.Geometry as Geometries.GeometryCollection))
                                {
                                    SharpMap.Rendering.Label lbl = CreateLabel(geom, text, rotation, style, map, g);
                                    if (lbl != null)
                                    {
                                        labels.Add(lbl);
                                    }
                                }
                            }
                            else if (this.MultipartGeometryBehaviour == MultipartGeometryBehaviourEnum.CommonCenter)
                            {
                                SharpMap.Rendering.Label lbl = CreateLabel(feature.Geometry, text, rotation, style, map, g);
                                if (lbl != null)
                                {
                                    labels.Add(lbl);
                                }
                            }
                            else if (this.MultipartGeometryBehaviour == MultipartGeometryBehaviourEnum.First)
                            {
                                if ((feature.Geometry as Geometries.GeometryCollection).Collection.Count > 0)
                                {
                                    SharpMap.Rendering.Label lbl = CreateLabel((feature.Geometry as Geometries.GeometryCollection).Collection[0], text, rotation, style, map, g);
                                    if (lbl != null)
                                    {
                                        labels.Add(lbl);
                                    }
                                }
                            }
                            else if (this.MultipartGeometryBehaviour == MultipartGeometryBehaviourEnum.Largest)
                            {
                                Geometries.GeometryCollection coll = (feature.Geometry as Geometries.GeometryCollection);
                                if (coll.NumGeometries > 0)
                                {
                                    double largestVal   = 0;
                                    int    idxOfLargest = 0;
                                    for (int j = 0; j < coll.NumGeometries; j++)
                                    {
                                        SharpMap.Geometries.Geometry geom = coll.Geometry(j);
                                        if (geom is Geometries.LineString && ((Geometries.LineString)geom).Length > largestVal)
                                        {
                                            largestVal   = ((Geometries.LineString)geom).Length;
                                            idxOfLargest = j;
                                        }
                                        if (geom is Geometries.MultiLineString && ((Geometries.MultiLineString)geom).Length > largestVal)
                                        {
                                            largestVal   = ((Geometries.LineString)geom).Length;
                                            idxOfLargest = j;
                                        }
                                        if (geom is Geometries.Polygon && ((Geometries.Polygon)geom).Area > largestVal)
                                        {
                                            largestVal   = ((Geometries.Polygon)geom).Area;
                                            idxOfLargest = j;
                                        }
                                        if (geom is Geometries.MultiPolygon && ((Geometries.MultiPolygon)geom).Area > largestVal)
                                        {
                                            largestVal   = ((Geometries.MultiPolygon)geom).Area;
                                            idxOfLargest = j;
                                        }
                                    }

                                    SharpMap.Rendering.Label lbl = CreateLabel(coll.Geometry(idxOfLargest), text, rotation, style, map, g);
                                    if (lbl != null)
                                    {
                                        labels.Add(lbl);
                                    }
                                }
                            }
                        }
                        else
                        {
                            SharpMap.Rendering.Label lbl = CreateLabel(feature.Geometry, text, rotation, style, map, g);
                            if (lbl != null)
                            {
                                labels.Add(lbl);
                            }
                        }
                    }
                }
                if (labels.Count > 0) //We have labels to render...
                {
                    if (this.Style.CollisionDetection && this._LabelFilter != null)
                    {
                        this._LabelFilter(labels);
                    }
                    for (int i = 0; i < labels.Count; i++)
                    {
                        SharpMap.Rendering.VectorRenderer.DrawLabel(g, labels[i].LabelPoint, labels[i].Style.Offset, labels[i].Style.Font, labels[i].Style.ForeColor, labels[i].Style.BackColor, Style.Halo, labels[i].Rotation, labels[i].Text, map);
                    }
                }
                labels = null;
            }
            base.Render(g, map);
        }
Example #4
0
 internal static Geometries.GeometryCollection ToSharpMapGeometryCollection(NTSGeometryCollection geom)
 {
     Geometries.GeometryCollection collection = new Geometries.GeometryCollection();
     foreach (NTSGeometry geometry in geom.Geometries)
         collection.Collection.Add(ToSharpMapGeometry(geometry));
     return collection;
 }