コード例 #1
0
        public void TestSerialize()
        {
            // This needs to be in this order
            const string TestKml =
                "<LatLonAltBox xmlns=\"http://www.opengis.net/kml/2.2\">" +
                "<north>2.5</north>" +
                "<west>0</west>" +
                "<minAltitude>101.101</minAltitude>" +
                "<altitudeMode>absolute</altitudeMode>" +
                "</LatLonAltBox>";

            Parser parser = new Parser();

            parser.ParseString(TestKml, true);
            Assert.That(parser.Root, Is.Not.Null);

            LatLonAltBox box = parser.Root as LatLonAltBox;

            Assert.That(box, Is.Not.Null);

            // Check it was parsed ok
            Assert.That(box.North, Is.EqualTo(2.5));
            Assert.That(box.South, Is.Null);
            Assert.That(box.East, Is.Null);
            Assert.That(box.West, Is.EqualTo(0));
            Assert.That(box.MinimumAltitude, Is.EqualTo(101.101));
            Assert.That(box.MaximumAltitude, Is.Null);
            Assert.That(box.GXAltitudeMode, Is.Null);
            Assert.That(box.AltitudeMode, Is.EqualTo(AltitudeMode.Absolute));

            Serializer serializer = new Serializer();

            serializer.SerializeRaw(box);
            Assert.That(serializer.Xml, Is.EqualTo(TestKml));
        }
コード例 #2
0
        private static Region CreateRegion()
        {
            var box = new LatLonAltBox();

            box.North = 1;
            box.South = 2;
            box.East  = 3;
            box.West  = 4;

            var lod = new Lod();

            lod.MinimumPixels = 100;

            var region = new Region();

            region.LatLonAltBox  = box;
            region.LevelOfDetail = lod;
            return(region);
        }
コード例 #3
0
ファイル: ParserTest.cs プロジェクト: thescruba/sharpkml
        public void TestNamespaces()
        {
            const string withNs = @"
<LatLonAltBox xmlns=""http://www.opengis.net/kml/2.2"">
  <gx:altitudeMode xmlns:gx=""http://www.google.com/kml/ext/2.2"">
    relativeToSeaFloor
  </gx:altitudeMode>
</LatLonAltBox>";

            const string withoutNs = @"
<LatLonAltBox>
  <gx:altitudeMode>
    relativeToSeaFloor
  </gx:altitudeMode>
</LatLonAltBox>";

            // Test ParseString with a namespace but without namespace checking
            Parser parser = new Parser();

            parser.ParseString(withNs, false);

            LatLonAltBox box = parser.Root as LatLonAltBox;

            Assert.That(box, Is.Not.Null);
            Assert.That(box.GXAltitudeMode, Is.EqualTo(SharpKml.Dom.GX.AltitudeMode.RelativeToSeafloor));

            // Now without
            parser.ParseString(withoutNs, false);
            box = (LatLonAltBox)parser.Root;
            Assert.That(box.GXAltitudeMode, Is.EqualTo(SharpKml.Dom.GX.AltitudeMode.RelativeToSeafloor));

            // Test ParseString with a namespace and with namespace checking
            parser.ParseString(withNs, true);
            box = parser.Root as LatLonAltBox;

            Assert.That(box, Is.Not.Null);
            Assert.That(box.GXAltitudeMode, Is.EqualTo(SharpKml.Dom.GX.AltitudeMode.RelativeToSeafloor));

            // Now without, which shouldn't work as gx is unknown
            Assert.That(() => parser.ParseString(withoutNs, true),
                        Throws.TypeOf <XmlException>());
        }
コード例 #4
0
    /// <summary>
    /// This method stores the given box into the database
    /// </summary>
    /// <param name="box">Box to be saved</param>
    /// <param name="insertedKmlId">The KmlId to connect this object to</param>
    /// <param name="con">Sql connection</param>
    /// <param name="tran">Sql transaction</param>
    /// <returns>The database id which is assigned to the given box</returns>
    protected static int?SaveLatLonBox(Geography box, int insertedKmlId, SqlConnection con, SqlTransaction tran)
    {
        #region Insert Geography

        int?insertedGeographyId = null;

        if (box != null)
        {
            SqlCommand saveGeographyCmd =
                new SqlCommand(
                    " insert into Geographies(Geography, KmlId) " +
                    " values(geography::Parse('" + box.ToString() + "'), @KmlId);select scope_identity()", con, tran);

            AddParameter(saveGeographyCmd, "KmlId", insertedKmlId, DbType.Int32);

            insertedGeographyId = (int)((decimal)saveGeographyCmd.ExecuteScalar());
            box.DbId            = insertedGeographyId;
        }

        #endregion

        #region Insert Lat Lon Box

        SqlCommand saveLatLonBox =
            new SqlCommand(
                " insert into LatLonBoxes(BoxType, GeographyId, rotation, MinAlt, MaxAlt, AltitudeMode) " +
                " values(@BoxType, @GeographyId, @rotation, @MinAlt, @MaxAlt, @AltitudeMode);select scope_identity()",
                con, tran);

        AddParameter(saveLatLonBox, "GeographyId", insertedGeographyId, DbType.Int32);

        LatLonBox    latLonBox    = box as LatLonBox;
        LatLonAltBox latLonAltBox = box as LatLonAltBox;
        LatLonQuad   latLonQuad   = box as LatLonQuad;

        string BoxType = "";

        if (latLonBox != null)
        {
            BoxType = "LatLonBox";
            AddParameter(saveLatLonBox, "rotation", latLonBox.Rotation, DbType.Double);
        }
        else
        {
            AddParameter(saveLatLonBox, "rotation", null, DbType.Double);
        }

        if (latLonAltBox != null)
        {
            BoxType = "LatLonAltBox";

            AddParameter(saveLatLonBox, "MinAlt", latLonAltBox.MinAltitude, DbType.Double);
            AddParameter(saveLatLonBox, "MaxAlt", latLonAltBox.MaxAltitude, DbType.Double);
            AddParameter(saveLatLonBox, "AltitudeMode", latLonAltBox.AltitudeMode.ToString(), DbType.String);
        }
        else
        {
            AddParameter(saveLatLonBox, "MinAlt", null, DbType.Double);
            AddParameter(saveLatLonBox, "MaxAlt", null, DbType.Double);
            AddParameter(saveLatLonBox, "AltitudeMode", null, DbType.Double);
        }

        if (latLonQuad != null)
        {
            BoxType = "LatLonQuad";
        }

        AddParameter(saveLatLonBox, "BoxType", BoxType, DbType.String);

        int?insertedLatLonBox = (int)((decimal)saveLatLonBox.ExecuteScalar());

        #endregion

        return(insertedLatLonBox);
    }
コード例 #5
0
        public void TestParseAltitudeMode()
        {
            const string LatLonAltBoxAbsolute =
                "<LatLonAltBox>" +
                "<north>2.5</north>" +
                "<south>1.25</south>" +
                "<east>1.25</east>" +
                "<west>0</west>" +
                "<minAltitude>101.101</minAltitude>" +
                "<maxAltitude>202.202</maxAltitude>" +
                "<altitudeMode>absolute</altitudeMode>" +
                "</LatLonAltBox>";

            Parser parser = new Parser();

            parser.ParseString(LatLonAltBoxAbsolute, false);
            Assert.That(parser.Root, Is.Not.Null);

            LatLonAltBox box = parser.Root as LatLonAltBox;

            Assert.That(box, Is.Not.Null);

            // Verify the proper values in the object model:
            Assert.That(box.MinimumAltitude, Is.EqualTo(101.101));
            Assert.That(box.MaximumAltitude, Is.EqualTo(202.202));
            Assert.That(box.AltitudeMode, Is.EqualTo(AltitudeMode.Absolute));
            Assert.That(box.North, Is.EqualTo(2.5));
            Assert.That(box.South, Is.EqualTo(1.25));
            Assert.That(box.East, Is.EqualTo(1.25));
            Assert.That(box.West, Is.EqualTo(0));

            const string LatLonAltBoxClampToGround =
                "<LatLonAltBox>" +
                "<altitudeMode>clampToGround</altitudeMode>" +
                "</LatLonAltBox>";

            parser.ParseString(LatLonAltBoxClampToGround, false);
            Assert.That(parser.Root, Is.Not.Null);

            box = parser.Root as LatLonAltBox;
            Assert.That(box, Is.Not.Null);
            Assert.That(box.North, Is.Null);
            Assert.That(box.South, Is.Null);
            Assert.That(box.East, Is.Null);
            Assert.That(box.West, Is.Null);
            Assert.That(box.MinimumAltitude, Is.Null);
            Assert.That(box.MaximumAltitude, Is.Null);
            Assert.That(box.GXAltitudeMode, Is.Null);
            Assert.That(box.AltitudeMode, Is.EqualTo(AltitudeMode.ClampToGround));

            const string LatLonAltBoxRelativeToGround =
                "<LatLonAltBox>" +
                "<altitudeMode>relativeToGround</altitudeMode>" +
                "</LatLonAltBox>";

            parser.ParseString(LatLonAltBoxRelativeToGround, false);
            box = (LatLonAltBox)parser.Root;
            Assert.That(box.AltitudeMode, Is.EqualTo(AltitudeMode.RelativeToGround));

            const string LatLonAltBoxRelativeToSeaFloor =
                "<LatLonAltBox>" +
                "<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>" +
                "</LatLonAltBox>";

            parser.ParseString(LatLonAltBoxRelativeToSeaFloor, false);
            box = (LatLonAltBox)parser.Root;
            Assert.That(box.GXAltitudeMode, Is.EqualTo(SharpKml.Dom.GX.AltitudeMode.RelativeToSeafloor));
        }