示例#1
0
 /// <summary>
 /// Creates a new FeatureDataSet for the layer with all features that intersect the supplied query feature geometry
 /// </summary>
 /// <param name="queryFeature"></param>
 /// <param name="fds"></param>
 public void ExecuteSpatialQuery(SqlGeometry queryFeature, GeospatialServices.Runtime.FeatureDataSet fds)
 {
     using (SqlConnection conn = new SqlConnection(ConnectionString))
     {
         string strSQL = String.Format("SELECT * FROM {0} WHERE {1}.STIntersects(Geometry::STGeomFromText('{2}',4326)) = 1", this.Table, this.GeometryColumn, queryFeature.ToString());
         using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn))
         {
             conn.Open();
             System.Data.DataSet ds = new System.Data.DataSet();
             adapter.Fill(ds);
             conn.Close();
             if (ds.Tables.Count > 0)
             {
                 FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]);
                 foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                 {
                     if (col.ColumnName != this.GeometryColumn && col.ColumnName != this.GeometryColumn)
                     {
                         fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                     }
                 }
                 foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                 {
                     GeospatialServices.Runtime.FeatureDataRow fdr = fdt.NewRow();
                     foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                     {
                         if (col.ColumnName != this.GeometryColumn && col.ColumnName != this.GeometryColumn)
                         {
                             fdr[col.ColumnName] = dr[col];
                         }
                     }
                     fdr.Geometry = (SqlGeometry)dr[this.GeometryColumn];
                     fdt.AddRow(fdr);
                 }
                 fds.Tables.Add(fdt);
             }
         }
     }
 }
示例#2
0
        /// <summary>
        /// Renders a map image of the ViewContext
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public System.Drawing.Image Render(StringDictionary parameters)
        {
            // create sized bitmap image
            Bitmap bitmap = new System.Drawing.Bitmap(this.General.Window.Width, this.General.Window.Height);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage((Image)bitmap);

            // Set background color of image
            if (String.Compare(parameters[WmsParameters.Transparent], "true", true) == 0)
            {
                g.Clear(System.Drawing.Color.Transparent);
            }
            else if (parameters[WmsParameters.BgColor] != null)
            {
                g.Clear(System.Drawing.ColorTranslator.FromHtml(parameters[WmsParameters.BgColor]));
            }
            else
            {
                g.Clear(System.Drawing.Color.White);
            }

            BoundingBox bbox = new BoundingBox(parameters[WmsParameters.Bbox], 4326);

            Zoom             = bbox.Width;
            CenterX          = bbox.CenterX;
            CenterY          = bbox.CenterY;
            PixelAspectRatio = ((double)this.General.Window.Width / (double)this.General.Window.Height) / (bbox.Width / bbox.Height);
            PixelWidth       = Zoom / (double)this.General.Window.Width;
            PixelHeight      = (Zoom / (double)this.General.Window.Width) * PixelAspectRatio;

            foreach (Layer layer in this.Layers)
            {
                GeospatialServices.Runtime.FeatureDataSet featureDataSet = new GeospatialServices.Runtime.FeatureDataSet();
                layer.ExecuteSpatialQuery(bbox.ToSqlGeometry, featureDataSet);
                layer.Render(g, featureDataSet, this);
            }
            return((Image)bitmap);
        }
示例#3
0
        public void Render(System.Drawing.Graphics g, GeospatialServices.Runtime.FeatureDataSet featureDataSet, ViewContext context)
        {
            int totalFeatures = featureDataSet.Tables[0].Count;

            for (int i = 0; i < totalFeatures; i++)
            {
                FeatureDataRow featureDataRow = featureDataSet.Tables[0][i];
                string         geomType       = (string)featureDataRow.Geometry.STGeometryType();
                switch (geomType)
                {
                case "Point":
                {
                    //         GeospatialServices.Ogc.Wms.GmlSf.Point gmlPoint = GetGmlSfPoint(geometry);
                    //         gmlGeometry = gmlPoint;
                }
                break;

                case "LineString":
                {
                    //         GeospatialServices.Ogc.Wms.GmlSf.Curve gmlCurve = GetGmlSfCurve(geometry);
                    //         gmlGeometry = gmlCurve;
                }
                break;

                case "Polygon":
                {
                    System.Drawing.Pen   pen;
                    System.Drawing.Brush brush;
                    EvaluatePolygonStyle(featureDataRow, context, out brush, out pen);
                    DrawPolygon(g, featureDataRow.Geometry, context, brush, pen);
                }
                break;

                case "MultiPoint":
                {
                    //         GeospatialServices.Ogc.Wms.GmlSf.MultiPoint gmlMultiPoint = GetGmlSfMultiPoint(geometry);
                    //         gmlGeometry = gmlMultiPoint;
                }
                break;

                case "MultiLineString":
                {
                    //         GeospatialServices.Ogc.Wms.GmlSf.MultiCurve gmlMultiCurve = GetGmlSfMultiCurve(geometry);
                    //         gmlGeometry = gmlMultiCurve;
                }
                break;

                case "MultiPolygon":
                {
                    for (int j = 1; j <= (int)featureDataRow.Geometry.STNumGeometries(); j++)
                    {
                        System.Drawing.Pen   pen;
                        System.Drawing.Brush brush;
                        EvaluatePolygonStyle(featureDataRow, context, out brush, out pen);
                        DrawPolygon(g, featureDataRow.Geometry.STGeometryN(j), context, brush, pen);
                    }
                }
                break;

                case "GeometryCollection":
                {
                    //           gmlGeometry = gmlMultiGeometry;
                }
                break;
                }
            }
        }
示例#4
0
        /// <summary>
        ///  Creates a FeatureCollection from a list of OGC layers within a ViewContext
        /// </summary>
        public FeatureCollection(ViewContext context, StringDictionary parameters)
        {
            string srs = string.Empty;

            GeospatialServices.Ogc.Wmc.BoundingBox mapBbox = null;
            double mapScale     = 0;
            int    featureCount = int.MaxValue;

            if (parameters[OgcParameters.Service] == GeospatialServices.Ogc.Common.ServiceNames.WFS.ToString())
            {
                if (parameters[WfsParameters.SrsName] != null)
                {
                    srs = parameters[WfsParameters.SrsName];
                }

                if (parameters[WmsParameters.Bbox] != null)
                {
                    mapBbox = new GeospatialServices.Ogc.Wmc.BoundingBox(parameters[WmsParameters.Bbox], OgcUtilities.GetSridFromCrs(srs));
                }

                if (parameters[WfsParameters.MaxFeatures] != null)
                {
                    featureCount = int.Parse(parameters[WfsParameters.MaxFeatures]);
                }
            }
            else // WMS
            {
                //if (parameters[WmsParameters.Crs] != null)
                //{
                //    srs = parameters[WmsParameters.Crs];
                //}

                //if (parameters[WmsParameters.I] != null && parameters[WmsParameters.J] != null)
                //{
                //    float x = float.Parse(parameters[WmsParameters.I]);
                //    float y = float.Parse(parameters[WmsParameters.J]);

                //    SharpMapLib.Map map = new SharpMapLib.Map(new System.Drawing.Size(int.Parse(parameters[WmsParameters.Width]), int.Parse(parameters[WmsParameters.Height])));
                //    SharpMapGeometries.BoundingBox tempBbox = SharpMapWeb.Wms.WmsServer.ParseBBOX(parameters[WmsParameters.Bbox]);
                //    map.ZoomToBox(tempBbox);

                //    // Calculate the Map Scale for filtering out layers that are not visible
                //    // in the current map scale
                //    mapScale = map.Zoom * (6378137 * 2 * Math.PI) / (map.Size.Width * 0.00028 * 360);

                //    // Keep a dictionary of queried layer groups and associated bounding boxes
                //    // after adjusting for the layer group buffers passed in
                //    if (parameters[Sdi.Ogc.Common.OgcExtendedParameters.Buffers] != null)
                //    {
                //        int buffer = 0;
                //        layerGroupBboxs = new Dictionary<string, SharpMapGeometries.BoundingBox>();
                //        string[] queryLayerGroups = parameters[WmsParameters.QueryLayers].Split(new char[] { ',' });
                //        string[] buffers = parameters[OgcExtendedParameters.Buffers].Split(new char[] { ',' });

                //        for (int i = 0; i < queryLayerGroups.Length; i++)
                //        {
                //            if (int.TryParse(buffers[i], out buffer))
                //            {
                //                tempBbox = new global::SharpMap.Geometries.BoundingBox(map.ImageToWorld(new System.Drawing.PointF(x - buffer, y + buffer)), map.ImageToWorld(new System.Drawing.PointF(x + buffer, y - buffer)));
                //                layerGroupBboxs.Add(queryLayerGroups[i], tempBbox);
                //            }
                //        }
                //    }
                //}

                if (parameters[WmsParameters.FeatureCount] != null)
                {
                    featureCount = int.Parse(parameters[WmsParameters.FeatureCount]);
                }
            }

            if (mapBbox == null)
            {
                if (context.General.BoundingBox != null)
                {
                    mapBbox = context.General.BoundingBox;
                }
                else
                {
                    throw new WmsFault(WmsExceptionCode.InvalidFormat, "Bounding box not found");
                }
            }

            //bool excludeGmlFeatures = (!String.IsNullOrEmpty(parameters[OgcExtendedParameters.ExcludeGmlFeatures]) &&
            //                            parameters[OgcExtendedParameters.ExcludeGmlFeatures].ToLowerInvariant() == "true") ? true : false;
            bool excludeGmlFeatures = false;

            foreach (GeospatialServices.Ogc.Wmc.Layer wmcLayer in context.Layers)
            {
                if (mapScale != 0)
                {
                    // The layer is not visible at this map scale
                    //      if (wmsLayer.MinScaleDenominatorSpecified && mapScale < wmsLayer.MinScaleDenominator)
                    //                                   continue;
                    //      if (wmsLayer.MaxScaleDenominatorSpecified && mapScale >= wmsLayer.MaxScaleDenominator)
                    //              continue;
                }

                Feature        feature        = null;
                XmlDocument    document       = new XmlDocument();
                XmlElement     element        = null;
                XmlNode        node           = null;
                XmlAttribute   attribute      = null;
                FeatureDataRow featureDataRow = null;

                GeospatialServices.Runtime.FeatureDataSet featureDataSet = new GeospatialServices.Runtime.FeatureDataSet();
                wmcLayer.ExecuteSpatialQuery(mapBbox.ToSqlGeometry, featureDataSet);

                if (featureDataSet != null)
                {
                    XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();

                    namespaces.Add(Declarations.Wfs110Prefix, Declarations.Wfs110NameSpace);
                    namespaces.Add(Declarations.DefaultPrefix, Declarations.DefaultNameSpace);
                    namespaces.Add(Declarations.WmsPrefix, Declarations.WmsNameSpace);
                    namespaces.Add(Declarations.OgcPrefix, Declarations.OgcNameSpace);
                    namespaces.Add(Declarations.GmlPrefix, Declarations.GmlNameSpace);
                    namespaces.Add(Declarations.GmlSfPrefix, Declarations.GmlSfNameSpace);
                    namespaces.Add(Declarations.XlinkPrefix, Declarations.XlinkNameSpace);

                    XmlSerializer serializer = new XmlSerializer(typeof(SfGeometry), Declarations.GmlSfNameSpace);

                    SfGeometry   sfGeometry         = null;
                    AbstractGML  gml                = null;
                    MemoryStream stream             = null;
                    XmlDocument  featueDocument     = null;
                    string       featureNameElement = wmcLayer.Name;

                    int totalFeatures = 0;
                    if (featureDataSet.Tables.Count > 0)
                    {
                        totalFeatures = Math.Min(featureDataSet.Tables[0].Count, featureCount);
                    }

                    for (int i = 0; i < totalFeatures; i++)
                    {
                        featureDataRow = featureDataSet.Tables[0][i];

                        feature = new Feature();
                        this.FeatureMemberList.Add(feature);

                        element = document.CreateElement(Declarations.GmlSfPrefix, featureNameElement, Declarations.GmlSfNameSpace);
                        feature.ElementList.Add(element);

                        attribute = document.CreateAttribute(Declarations.GmlPrefix, "id", Declarations.GmlNameSpace);
                        element.Attributes.Append(attribute);

                        attribute.Value = "id" + Guid.NewGuid().ToString();     //TODO: not correct, guids should be 'static'

                        // add the attributes
                        foreach (DataColumn featureDataColumn in featureDataSet.Tables[0].Columns)
                        {
                            node = document.CreateNode(XmlNodeType.Element, Declarations.GmlSfPrefix, featureDataColumn.ColumnName, Declarations.GmlSfNameSpace);
                            element.AppendChild(node);
                            node.InnerText = featureDataRow[featureDataColumn.ColumnName].ToString().Trim();
                        }

                        // add the layer Title
                        node = document.CreateNode(XmlNodeType.Element, Declarations.GmlSfPrefix, "LayerTitle", Declarations.GmlSfNameSpace);
                        element.AppendChild(node);
                        node.InnerText = wmcLayer.Title;

                        // only include the gml features if requested
                        if (!excludeGmlFeatures)
                        {
                            node = document.CreateNode(XmlNodeType.Element, Declarations.GmlSfPrefix, "sfElement", Declarations.GmlSfNameSpace);
                            element.AppendChild(node);
                            gml        = AbstractGML.GetFromSqlGeometry(featureDataRow.Geometry);
                            sfGeometry = new SfGeometry(gml);
                            stream     = new MemoryStream();
                            serializer.Serialize(stream, sfGeometry, namespaces);
                            stream.Position = 0;
                            featueDocument  = new XmlDocument();
                            featueDocument.Load(stream);
                            node.InnerXml = featueDocument.DocumentElement.InnerXml;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Copies the structure of the FeatureDataSet, including all FeatureDataTable schemas, relations, and constraints. Does not copy any data.
        /// </summary>
        /// <returns></returns>
        public new FeatureDataSet Clone()
        {
            FeatureDataSet cln = ((FeatureDataSet)(base.Clone()));

            return(cln);
        }