public void FeatureCollectionDbQueryTest()
        {
            string conn = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Projects\GeospatialServices\TestGeospatialServices\Input\Runtime\TestGeospatialServicesDatabase.mdf;Integrated Security=True;User Instance=True";

            GeospatialServices.Ogc.Wmc.Layer          data = new GeospatialServices.Ogc.Wmc.Layer("world_admin", conn, "world_admin", "shape", "fid");
            GeospatialServices.Runtime.FeatureDataSet fds  = new GeospatialServices.Runtime.FeatureDataSet();
            //UK POLYGON ((-7.5191669464111328 49.955268859863281, 1.7424999475479126 49.955268859863281, 1.7424999475479126 60.631099700927734, -7.5191669464111328 60.631099700927734, -7.5191669464111328 49.955268859863281))
            //US POLYGON ((-178.21420288085938 18.924720764160156, 179.40299987792969 18.924720764160156, 179.40299987792969 71.406646728515625, -178.21420288085938 71.406646728515625, -178.21420288085938 18.924720764160156))
            string      queryGeometryString = "POLYGON ((-176.84950256347656 -50.854450225830078, 178.5596923828125 -50.854450225830078, 178.5596923828125 -34.398349761962891, -176.84950256347656 -34.398349761962891, -176.84950256347656 -50.854450225830078))";
            SqlGeometry queryGeometry       = SqlGeometry.STGeomFromText(new System.Data.SqlTypes.SqlChars(new System.Data.SqlTypes.SqlString(queryGeometryString)), 4326);

            data.ExecuteSpatialQuery(queryGeometry, fds);
            Assert.IsTrue(fds.Tables[0].Count == 7);
        }
        public void FeatureCollectionActionsTest()
        {
            string conn = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Projects\GeospatialServices\TestGeospatialServices\Input\Runtime\TestGeospatialServicesDatabase.mdf;Integrated Security=True;User Instance=True";

            GeospatialServices.Ogc.Wmc.Layer          data = new GeospatialServices.Ogc.Wmc.Layer("world_admin", conn, "world_admin", "shape", "fid");
            GeospatialServices.Runtime.FeatureDataSet fds  = new GeospatialServices.Runtime.FeatureDataSet();
            string      queryGeometryString = "POLYGON ((-176.84950256347656 -50.854450225830078, 178.5596923828125 -50.854450225830078, 178.5596923828125 -34.398349761962891, -176.84950256347656 -34.398349761962891, -176.84950256347656 -50.854450225830078))";
            SqlGeometry queryGeometry       = SqlGeometry.STGeomFromText(new System.Data.SqlTypes.SqlChars(new System.Data.SqlTypes.SqlString(queryGeometryString)), 4326);

            data.ExecuteSpatialQuery(queryGeometry, fds);
            Assert.IsTrue(fds.Tables[0].Count == 7);
            fds.Tables[0].RemoveRow(fds.Tables[0][0]);
            Assert.IsTrue(fds.Tables[0].Count == 6);
            fds.Tables[0][0].Geometry = queryGeometry;
            Assert.IsTrue(fds.Tables[0][0].IsFeatureGeometryNull() == false);
            fds.Tables[0][0].SetFeatureGeometryNull();
            Assert.IsTrue(fds.Tables[0][0].IsFeatureGeometryNull() == true);
            fds.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
            string schema = fds.GetXmlSchema();
            string xml    = fds.GetXml();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the WMC Context associated with a WMS Request
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public ViewContext(StringDictionary parameters)
        {
            // Parse map size
            int width  = 0;
            int height = 0;

            int.TryParse(parameters[WmsParameters.Width], out width);
            int.TryParse(parameters[WmsParameters.Height], out height);

            this.General.Window.Width  = width;
            this.General.Window.Height = height;

            // Attach the Bounding Box if passed in, otherwise, it will be set to the
            // envelope of all layers
            string crs  = parameters[WmsParameters.Crs];
            int    srid = OgcUtilities.GetSridFromCrs(crs);

            if (parameters[WmsParameters.Bbox] != null)
            {
                this.General.BoundingBox     = new GeospatialServices.Ogc.Wmc.BoundingBox(parameters[WmsParameters.Bbox], srid);
                this.General.BoundingBox.SRS = crs;
            }

            SLD sldRead = null;

            // Get the SLD_BODY if specified
            if (!String.IsNullOrEmpty(parameters[WmsParameters.SldBody]))
            {
                // Namespaces
                XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();

                namespaces.Add(Declarations.WmsPrefix, Declarations.WmsNameSpace);
                namespaces.Add(Declarations.SldPrefix, Declarations.SldNameSpace);
                namespaces.Add(Declarations.SePrefix, Declarations.SeNameSpace);
                namespaces.Add(Declarations.OgcPrefix, Declarations.OgcNameSpace);
                namespaces.Add(Declarations.XlinkPrefix, Declarations.XlinkNameSpace);

                using (StringReader stringReader = new StringReader(parameters[WmsParameters.SldBody]))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(SLD));
                    sldRead = (SLD)serializer.Deserialize(stringReader);
                }
            }

            // Extract all layers from request
            string layers = "";

            if (parameters[OgcParameters.Service] == GeospatialServices.Ogc.Common.ServiceNames.WFS.ToString())
            {
                layers = parameters[WfsParameters.TypeName];
            }
            else
            {
                layers = parameters[WmsParameters.Layers];
            }

            if (!String.IsNullOrEmpty(layers))
            {
                string[] requestedLayers = layers.Split(new char[] { ',' });
                string[] requestedStyles = null;

                string styles = parameters[WmsParameters.Styles];
                if (string.IsNullOrEmpty(styles))
                {
                    requestedStyles = new string[0];
                }
                else
                {
                    requestedStyles = styles.Split(new char[] { ',' });
                }

                // get all know layers from the confguration view context document
                ViewContext configurationContext = OgcUtilities.GetViewContext();

                // build a custom WMC document from the layers and styles in the request
                for (int i = 0; i < requestedLayers.Count(); i++)
                {
                    // find the requested layers configuration
                    string layerName  = requestedLayers[i].Trim();
                    int    layerIndex = configurationContext.Layers.FindIndex(delegateLayer => delegateLayer.Name == layerName);

                    if (layerIndex != -1)
                    {
                        // find the style
                        GeospatialServices.Ogc.Wmc.UserStyle sldStyle = null;

                        string requestedStyle = string.Empty;
                        if (requestedStyles.Count() > i)
                        {
                            requestedStyle = requestedStyles[i].Trim();
                        }

                        if (sldRead != null)
                        {
                            foreach (var sldlayer in sldRead.StyledLayerDescriptor.UserLayers)
                            {
                                foreach (UserStyle style in sldlayer.UserStyles)
                                {
                                    if (style.Name == requestedStyle)
                                    {
                                        sldStyle       = style;
                                        requestedStyle = string.Empty;
                                        break;
                                    }
                                }
                                if (requestedStyle == string.Empty)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(requestedStyle))
                            {
                                requestedStyle = "default";
                            }
                            Style style = configurationContext.Layers[layerIndex].StyleList.Find(delegateStyle => delegateStyle.Name == requestedStyle);
                            if (style == null)
                            {
                                throw new InvalidDataException("Style not found");
                            }
                            sldStyle = style.SLD.StyledLayerDescriptor.UserLayers[0].UserStyles[0];
                        }

                        // get the layer and remove configured styles
                        GeospatialServices.Ogc.Wmc.Layer wmcLayer = configurationContext.Layers[layerIndex].Clone();
                        wmcLayer.StyleList.Clear();

                        // now add the style to be rendered
                        if (sldStyle != null)
                        {
                            wmcLayer.StyleList.Add(new GeospatialServices.Ogc.Wmc.Style());
                            wmcLayer.StyleList[0].Current = 1;
                            UserLayer ul = new UserLayer();
                            ul.UserStyles = new List <UserStyle>();
                            wmcLayer.StyleList[0].SLD.StyledLayerDescriptor.UserLayers.Add(ul);
                            wmcLayer.StyleList[0].SLD.StyledLayerDescriptor.UserLayers[0].UserStyles.Add(sldStyle);
                        }

                        if (parameters[WmsParameters.Format] != null)
                        {
                            wmcLayer.FormatList.Add(new Format(parameters[WmsParameters.Format], 1));
                        }

                        this.Layers.Add(wmcLayer);
                    }
                }

                //TODO: do this properly....
                // compute envelope if required
                if (this.General.BoundingBox.ToSqlGeometry == null)
                {
                    this.General.BoundingBox = new BoundingBox("-180,-85,180,85", 4326);
                }
            }
        }