Beispiel #1
0
        public static XElement AreaElement(XName elementName, SqlGeometry area, Guid localId)
        {
            var e = new NinXElement(elementName);

            if (area == null)
            {
                return(e);
            }

            var gmlXml = area.AsGml().Value;

            gmlXml = gmlXml.Replace(" xmlns=\"http://www.opengis.net/gml\"", "");

            var gmlElement = XElement.Parse(gmlXml);

            gmlElement.Add(new XAttribute((XNamespace)Config.Settings.Namespace.Gml + "id", "GEOMETRY_" + localId));
            gmlElement.Add(new XAttribute("srsName", "EPSG:" + area.STSrid));

            foreach (var gmlElementPart in gmlElement.DescendantsAndSelf())
            {
                gmlElementPart.Name = (XNamespace)Config.Settings.Namespace.Gml + gmlElementPart.Name.LocalName;
            }

            e.Add(gmlElement);

            return(e);
        }
        public static string AsGml3(this SqlGeometry geometry, bool writeSrid = false)
        {
            var gml = geometry?.AsGml();

            if (gml == null || gml.IsNull)
            {
                return(string.Empty);
            }

            var doc = XDocument.Parse(geometry.AsGml().Value);

            doc.Root.SetAttributeValue(XNamespace.Xmlns + "gml", "http://www.opengis.net/gml");
            doc.Root.SetAttributeValue("xmlns", null);

            if (writeSrid)
            {
                doc.Root.SetAttributeValue("srsName", $"http://www.opengis.net/gml/srs/epsg.xml#{geometry.STSrid.Value}");
            }

            //doc.Declaration = null;

            return(doc.ToString(SaveOptions.OmitDuplicateNamespaces));
        }