Ejemplo n.º 1
0
        public static AbstractGeometryType Deserialize(XmlReader reader)
        {
            var node = XElement.Load(reader);

            reader = node.CreateReader();

            if (node.Name.NamespaceName != "http://www.opengis.net/gml")
            {
                throw new FormatException("The xml is not GML");
            }

            if (node.Name.LocalName == "MultiPolygon")
            {
                return((MultiPolygonType)MultiPolygonSerializer.Deserialize(reader));
            }

            if (node.Name.LocalName == "MultiCurve")
            {
                return((MultiCurveType)MultiCurveSerializer.Deserialize(reader));
            }

            if (node.Name.LocalName == "MultiLineString")
            {
                return((MultiLineStringType)MultiLineStringSerializer.Deserialize(reader));
            }

            if (node.Name.LocalName == "MultiSurface")
            {
                return((MultiSurfaceType)MultiSurfaceSerializer.Deserialize(reader));
            }

            if (node.Name.LocalName == "MultiPoint")
            {
                return((MultiPointType)MultiPointSerializer.Deserialize(reader));
            }

            if (node.Name.LocalName == "LinearRing")
            {
                return((LinearRingType)LinearRingSerializer.Deserialize(reader));
            }

            if (node.Name.LocalName == "Polygon")
            {
                return((PolygonType)PolygonSerializer.Deserialize(reader));
            }

            if (node.Name.LocalName == "LineString")
            {
                return((LineStringType)LineStringSerializer.Deserialize(reader));
            }

            if (node.Name.LocalName == "Point")
            {
                return((PointType)PointSerializer.Deserialize(reader));
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 2
0
 public void TypeSerializer_Test()
 {
     var typeSerializer = new LineStringSerializer();
     foreach (var item in Values)
     {
         var serialized = typeSerializer.Serialize(1, item);
         var deserialized = typeSerializer.Deserialize(1, serialized, 0, serialized.Length, null);
         Assert.AreEqual(item, deserialized);
         //starting from offset
         serialized = new byte[] { 1, 2, 3 }.Concat(serialized).ToArray();
         deserialized = typeSerializer.Deserialize(1, serialized, 3, serialized.Length - 3, null);
         Assert.AreEqual(item, deserialized);
     }
 }
Ejemplo n.º 3
0
        public void TypeSerializer_Test()
        {
            var typeSerializer = new LineStringSerializer();

            foreach (var item in Values)
            {
                var serialized   = typeSerializer.Serialize(1, item);
                var deserialized = typeSerializer.Deserialize(1, serialized, 0, serialized.Length, null);
                Assert.AreEqual(item, deserialized);
                //starting from offset
                serialized   = new byte[] { 1, 2, 3 }.Concat(serialized).ToArray();
                deserialized = typeSerializer.Deserialize(1, serialized, 3, serialized.Length - 3, null);
                Assert.AreEqual(item, deserialized);
            }
        }
Ejemplo n.º 4
0
        public static void Serialize(XmlWriter writer, AbstractGeometryType gmlObject)
        {
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
            namespaces.Add(string.Empty, string.Empty);
            namespaces.Add("gml", "http://www.opengis.net/gml/3.2");

            if (gmlObject is MultiCurveType) {
                MultiCurveSerializer.Serialize(writer, gmlObject, namespaces);
                return;
            }

            if (gmlObject is MultiSurfaceType) {
                MultiSurfaceSerializer.Serialize(writer, gmlObject, namespaces);
                return;
            }

            if (gmlObject is MultiPointType) {
                MultiPointSerializer.Serialize(writer, gmlObject, namespaces);
                return;
            }

            if (gmlObject is LineStringType)
            {
                LineStringSerializer.Serialize(writer, gmlObject, namespaces);
                return;
            }

            if (gmlObject is PolygonType)
            {
                PolygonSerializer.Serialize(writer, gmlObject, namespaces);
                return;
            }

            if (gmlObject is PointType)
            {
                PointSerializer.Serialize(writer, gmlObject, namespaces);
                return;
            }

            throw new NotImplementedException(gmlObject.GetType().ToString());
        }