Ejemplo n.º 1
0
        public void TestFGFTAndRoundtrip()
        {
            FdoFgfGeometryFactory gf = FdoFgfGeometryFactory.GetInstance();

            FdoIGeometry pt   = gf.CreateGeometry("POINT (5 3)");
            FdoIGeometry ls   = gf.CreateGeometry("LINESTRING (0 1, 2 3, 4 5)");
            FdoIGeometry pg   = gf.CreateGeometry("POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0), (1 1, 2 1, 2 2, 1 1), (3 3, 4 3, 4 4, 3 3))");
            FdoIGeometry mpt  = gf.CreateGeometry("MULTIPOINT XYZ (1 2 3, 4 5 6, 7 8 9)");
            FdoIGeometry mls  = gf.CreateGeometry("MULTILINESTRING XYZ ((0 1 2, 3 4 5, 6 7 8), (9 10 11, 12 13 14, 15 16 17))");
            FdoIGeometry mpg  = gf.CreateGeometry("MULTIPOLYGON (((0 0, 5 0, 5 5, 0 5, 0 0), (1 1, 2 1, 2 2, 1 1), (3 3, 4 3, 4 4, 3 3)), ((0 0, 5 0, 5 5, 0 5, 0 0), (1 1, 2 1, 2 2, 1 1), (3 3, 4 3, 4 4, 3 3)))");
            FdoIGeometry mg   = gf.CreateGeometry("GEOMETRYCOLLECTION (CURVEPOLYGON ((100 100 (CIRCULARARCSEGMENT (100 101, 101 102), LINESTRINGSEGMENT (100 100))), (200 200 (CIRCULARARCSEGMENT (200 201, 201 202), LINESTRINGSEGMENT (200 200))), (300 300 (CIRCULARARCSEGMENT (300 301, 301 302), LINESTRINGSEGMENT (300 300)))), CURVESTRING (100 100 (CIRCULARARCSEGMENT (100 101, 101 102), LINESTRINGSEGMENT (103 100, 103 102))), LINESTRING (0 1, 2 3, 4 5), POINT XYZ (5 3 2), POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0), (1 1, 2 1, 2 2, 1 1), (3 3, 4 3, 4 4, 3 3)))");
            FdoIGeometry cs   = gf.CreateGeometry("CURVESTRING (0 0 (CIRCULARARCSEGMENT (0 1, 1 2), LINESTRINGSEGMENT (3 0, 3 2)))");
            FdoIGeometry cpg  = gf.CreateGeometry("CURVEPOLYGON ((200 200 (CIRCULARARCSEGMENT (200 201, 201 202), LINESTRINGSEGMENT (200 200))), (300 300 (CIRCULARARCSEGMENT (300 301, 301 302), LINESTRINGSEGMENT (300 300))), (400 400 (CIRCULARARCSEGMENT (400 401, 401 402), LINESTRINGSEGMENT (400 400))))");
            FdoIGeometry mcs  = gf.CreateGeometry("MULTICURVESTRING ((100 100 (CIRCULARARCSEGMENT (100 101, 101 102), LINESTRINGSEGMENT (103 100, 103 102))), (200 200 (CIRCULARARCSEGMENT (200 201, 201 202), LINESTRINGSEGMENT (203 200, 203 202))), (300 300 (CIRCULARARCSEGMENT (300 301, 301 302), LINESTRINGSEGMENT (303 300, 303 302))))");
            FdoIGeometry mcpg = gf.CreateGeometry("MULTICURVEPOLYGON (((200 200 (CIRCULARARCSEGMENT (200 201, 201 202), LINESTRINGSEGMENT (200 200))), (300 300 (CIRCULARARCSEGMENT (300 301, 301 302), LINESTRINGSEGMENT (300 300))), (400 400 (CIRCULARARCSEGMENT (400 401, 401 402), LINESTRINGSEGMENT (400 400)))), ((201 201 (CIRCULARARCSEGMENT (201 202, 202 203), LINESTRINGSEGMENT (201 201))), (301 301 (CIRCULARARCSEGMENT (301 302, 302 303), LINESTRINGSEGMENT (301 301))), (401 401 (CIRCULARARCSEGMENT (401 402, 402 403), LINESTRINGSEGMENT (401 401)))), ((202 202 (CIRCULARARCSEGMENT (202 203, 203 204), LINESTRINGSEGMENT (202 202))), (302 302 (CIRCULARARCSEGMENT (302 303, 303 304), LINESTRINGSEGMENT (302 302))), (402 402 (CIRCULARARCSEGMENT (402 403, 403 404), LINESTRINGSEGMENT (402 402)))))");

            Assert.IsAssignableFrom <FdoIPoint>(pt);
            Assert.IsAssignableFrom <FdoILineString>(ls);
            Assert.IsAssignableFrom <FdoIPolygon>(pg);
            Assert.IsAssignableFrom <FdoIMultiPoint>(mpt);
            Assert.IsAssignableFrom <FdoIMultiLineString>(mls);
            Assert.IsAssignableFrom <FdoIMultiPolygon>(mpg);
            Assert.IsAssignableFrom <FdoIMultiGeometry>(mg);
            Assert.IsAssignableFrom <FdoICurveString>(cs);
            Assert.IsAssignableFrom <FdoICurvePolygon>(cpg);
            Assert.IsAssignableFrom <FdoIMultiCurveString>(mcs);
            Assert.IsAssignableFrom <FdoIMultiCurvePolygon>(mcpg);

            FdoByteArrayHandle fgf_pt   = gf.GetFgfBytes(pt);
            FdoByteArrayHandle fgf_ls   = gf.GetFgfBytes(ls);
            FdoByteArrayHandle fgf_pg   = gf.GetFgfBytes(pg);
            FdoByteArrayHandle fgf_mpt  = gf.GetFgfBytes(mpt);
            FdoByteArrayHandle fgf_mls  = gf.GetFgfBytes(mls);
            FdoByteArrayHandle fgf_mpg  = gf.GetFgfBytes(mpg);
            FdoByteArrayHandle fgf_mg   = gf.GetFgfBytes(mg);
            FdoByteArrayHandle fgf_cs   = gf.GetFgfBytes(cs);
            FdoByteArrayHandle fgf_cpg  = gf.GetFgfBytes(cpg);
            FdoByteArrayHandle fgf_mcs  = gf.GetFgfBytes(mcs);
            FdoByteArrayHandle fgf_mcpg = gf.GetFgfBytes(mcpg);

            Assert.NotNull(fgf_pt);
            Assert.NotNull(fgf_ls);
            Assert.NotNull(fgf_pg);
            Assert.NotNull(fgf_mpt);
            Assert.NotNull(fgf_mls);
            Assert.NotNull(fgf_mpg);
            Assert.NotNull(fgf_mg);
            Assert.NotNull(fgf_cs);
            Assert.NotNull(fgf_cpg);
            Assert.NotNull(fgf_mcs);
            Assert.NotNull(fgf_mcpg);

            //Only test geometries we know are transferrable to WKB
            FdoByteArrayHandle wkb_pt = gf.GetWkbBytes(pt);
            FdoByteArrayHandle wkb_ls = gf.GetWkbBytes(ls);
            FdoByteArrayHandle wkb_pg = gf.GetWkbBytes(pg);
            //FdoByteArrayHandle wkb_mpt = gf.GetWkbBytes(mpt);
            //FdoByteArrayHandle wkb_mls = gf.GetWkbBytes(mls);
            FdoByteArrayHandle wkb_mpg = gf.GetWkbBytes(mpg);

            //FdoByteArrayHandle wkb_mg = gf.GetWkbBytes(mg);
            //FdoByteArrayHandle wkb_cs = gf.GetWkbBytes(cs);
            //FdoByteArrayHandle wkb_cpg = gf.GetWkbBytes(cpg);
            //FdoByteArrayHandle wkb_mcs = gf.GetWkbBytes(mcs);
            //FdoByteArrayHandle wkb_mcpg = gf.GetWkbBytes(mcpg);

            Assert.NotNull(wkb_pt);
            Assert.NotNull(wkb_ls);
            Assert.NotNull(wkb_pg);
            //Assert.NotNull(wkb_mpt);
            //Assert.NotNull(wkb_mls);
            Assert.NotNull(wkb_mpg);
            //Assert.NotNull(wkb_mg);
            //Assert.NotNull(wkb_cs);
            //Assert.NotNull(wkb_cpg);
            //Assert.NotNull(wkb_mcs);
            //Assert.NotNull(wkb_mcpg);

            pt   = gf.CreateGeometryFromFgf(fgf_pt);
            ls   = gf.CreateGeometryFromFgf(fgf_ls);
            pg   = gf.CreateGeometryFromFgf(fgf_pg);
            mpt  = gf.CreateGeometryFromFgf(fgf_mpt);
            mls  = gf.CreateGeometryFromFgf(fgf_mls);
            mpg  = gf.CreateGeometryFromFgf(fgf_mpg);
            mg   = gf.CreateGeometryFromFgf(fgf_mg);
            cs   = gf.CreateGeometryFromFgf(fgf_cs);
            cpg  = gf.CreateGeometryFromFgf(fgf_cpg);
            mcs  = gf.CreateGeometryFromFgf(fgf_mcs);
            mcpg = gf.CreateGeometryFromFgf(fgf_mcpg);

            Assert.IsAssignableFrom <FdoIPoint>(pt);
            Assert.IsAssignableFrom <FdoILineString>(ls);
            Assert.IsAssignableFrom <FdoIPolygon>(pg);
            Assert.IsAssignableFrom <FdoIMultiPoint>(mpt);
            Assert.IsAssignableFrom <FdoIMultiLineString>(mls);
            Assert.IsAssignableFrom <FdoIMultiPolygon>(mpg);
            Assert.IsAssignableFrom <FdoIMultiGeometry>(mg);
            Assert.IsAssignableFrom <FdoICurveString>(cs);
            Assert.IsAssignableFrom <FdoICurvePolygon>(cpg);
            Assert.IsAssignableFrom <FdoIMultiCurveString>(mcs);
            Assert.IsAssignableFrom <FdoIMultiCurvePolygon>(mcpg);

            pt = gf.CreateGeometryFromWkb(wkb_pt);
            ls = gf.CreateGeometryFromWkb(wkb_ls);
            pg = gf.CreateGeometryFromWkb(wkb_pg);
            //mpt = gf.CreateGeometryFromWkb(wkb_mpt);
            //mls = gf.CreateGeometryFromWkb(wkb_mls);
            mpg = gf.CreateGeometryFromWkb(wkb_mpg);
            //mg = gf.CreateGeometryFromWkb(wkb_mg);
            //cs = gf.CreateGeometryFromWkb(wkb_cs);
            //cpg = gf.CreateGeometryFromWkb(wkb_cpg);
            //mcs = gf.CreateGeometryFromWkb(wkb_mcs);
            //mcpg = gf.CreateGeometryFromWkb(wkb_mcpg);

            Assert.IsAssignableFrom <FdoIPoint>(pt);
            Assert.IsAssignableFrom <FdoILineString>(ls);
            Assert.IsAssignableFrom <FdoIPolygon>(pg);
            //Assert.IsAssignableFrom<FdoIMultiPoint>(mpt);
            //Assert.IsAssignableFrom<FdoIMultiLineString>(mls);
            Assert.IsAssignableFrom <FdoIMultiPolygon>(mpg);
            //Assert.IsAssignableFrom<FdoIMultiGeometry>(mg);
            //Assert.IsAssignableFrom<FdoICurveString>(cs);
            //Assert.IsAssignableFrom<FdoICurvePolygon>(cpg);
            //Assert.IsAssignableFrom<FdoIMultiCurveString>(mcs);
            //Assert.IsAssignableFrom<FdoIMultiCurvePolygon>(mcpg);
        }
Ejemplo n.º 2
0
        private void DoInsert(FdoIConnection conn)
        {
            string geomName = null;

            using (FdoIDescribeSchema desc = conn.CreateCommand((int)FdoCommandType.FdoCommandType_DescribeSchema) as FdoIDescribeSchema)
            {
                Assert.NotNull(desc);
                FdoFeatureSchemaCollection schemas = desc.Execute();
                Assert.NotNull(schemas);
                FdoFeatureClass clsDef = schemas.GetClassDefinition(null, "World_Countries") as FdoFeatureClass;
                Assert.NotNull(clsDef);
                FdoGeometricPropertyDefinition geomProp = clsDef.GetGeometryProperty();
                Assert.NotNull(geomProp);
                geomName = geomProp.Name;
            }
            using (FdoIInsert insertCmd = conn.CreateCommand((int)FdoCommandType.FdoCommandType_Insert) as FdoIInsert)
            {
                Assert.NotNull(insertCmd);

                insertCmd.SetFeatureClassName("World_Countries");

                FdoFgfGeometryFactory      geomFactory = FdoFgfGeometryFactory.GetInstance();
                FdoPropertyValueCollection propVals    = insertCmd.GetPropertyValues();

                FdoStringValue nameVal = FdoStringValue.Create();
                Assert.True(nameVal.IsNull());
                FdoStringValue keyVal = FdoStringValue.Create();
                Assert.True(keyVal.IsNull());
                FdoStringValue mapkeyVal = FdoStringValue.Create();
                Assert.True(mapkeyVal.IsNull());
                FdoGeometryValue geomVal = FdoGeometryValue.Create();
                Assert.True(geomVal.IsNull());

                FdoPropertyValue pName   = FdoPropertyValue.Create("NAME", nameVal);
                FdoPropertyValue pKey    = FdoPropertyValue.Create("KEY", keyVal);
                FdoPropertyValue pMapKey = FdoPropertyValue.Create("MAPKEY", mapkeyVal);
                FdoPropertyValue pGeom   = FdoPropertyValue.Create(geomName, geomVal);

                propVals.Add(pName);
                propVals.Add(pKey);
                propVals.Add(pMapKey);
                propVals.Add(pGeom);

                //Set the actual values
                nameVal.String   = "My Own Country";
                keyVal.String    = "MOC";
                mapkeyVal.String = "MOC123";
                FdoIGeometry       geom = geomFactory.CreateGeometry("POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))");
                FdoByteArrayHandle fgf  = geomFactory.GetFgfBytes(geom);
                geomVal.SetGeometryBytes(fgf);

                int inserted = GetInsertedFeatures(insertCmd);
                Assert.Equal(1, inserted);

                int count = GetFeatureCountForName(conn, "My Own Country");
                Assert.Equal(1, count);

                mapkeyVal.String = "MOC234";
                Assert.Equal(1, GetInsertedFeatures(insertCmd)); //, "Expected 1 feature inserted");
                Assert.Equal(2, GetFeatureCountForName(conn, "My Own Country"));
                Assert.Equal(1, GetFeatureCountForMapKey(conn, "MOC123"));
                Assert.Equal(1, GetFeatureCountForMapKey(conn, "MOC234"));
            }
            //Test sugar methods
            using (FdoIInsert insertCmd = conn.CreateCommand((int)FdoCommandType.FdoCommandType_Insert) as FdoIInsert)
            {
                Assert.NotNull(insertCmd);

                insertCmd.SetFeatureClassName("World_Countries");

                FdoFgfGeometryFactory      geomFactory = FdoFgfGeometryFactory.GetInstance();
                FdoPropertyValueCollection propVals    = insertCmd.GetPropertyValues();

                propVals.SetStringValue("KEY", "MOC");
                propVals.SetStringValue("MAPKEY", "MOC123");
                propVals.SetStringValue("NAME", "My Own Country");

                FdoIGeometry       geom = geomFactory.CreateGeometry("POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))");
                FdoByteArrayHandle fgf  = geomFactory.GetFgfBytes(geom);

                propVals.SetGeometryValue("Geometry", fgf);

                Assert.Equal(4, propVals.Count);
                FdoPropertyValue pKey    = propVals.FindItem("KEY");
                FdoPropertyValue pMapkey = propVals.FindItem("MAPKEY");
                FdoPropertyValue pName   = propVals.FindItem("NAME");
                FdoPropertyValue pGeom   = propVals.FindItem("Geometry");

                Assert.NotNull(pKey);
                Assert.NotNull(pMapkey);
                Assert.NotNull(pName);
                Assert.NotNull(pGeom);

                FdoStringValue   key     = pKey.GetValue() as FdoStringValue;
                FdoStringValue   mapkey  = pMapkey.GetValue() as FdoStringValue;
                FdoStringValue   name    = pName.GetValue() as FdoStringValue;
                FdoGeometryValue geomVal = pGeom.GetValue() as FdoGeometryValue;

                Assert.NotNull(key);
                Assert.NotNull(mapkey);
                Assert.NotNull(name);
                Assert.NotNull(geomVal);

                Assert.False(key.IsNull());
                Assert.False(mapkey.IsNull());
                Assert.False(name.IsNull());
                Assert.False(geomVal.IsNull());

                //Null values one by one
                propVals.SetValueNull("NAME");
                Assert.False(key.IsNull());
                Assert.False(mapkey.IsNull());
                Assert.True(name.IsNull());
                Assert.False(geomVal.IsNull());

                propVals.SetValueNull("KEY");
                Assert.True(key.IsNull());
                Assert.False(mapkey.IsNull());
                Assert.True(name.IsNull());
                Assert.False(geomVal.IsNull());

                propVals.SetValueNull("MAPKEY");
                Assert.True(key.IsNull());
                Assert.True(mapkey.IsNull());
                Assert.True(name.IsNull());
                Assert.False(geomVal.IsNull());

                propVals.SetValueNull("Geometry");
                Assert.True(key.IsNull());
                Assert.True(mapkey.IsNull());
                Assert.True(name.IsNull());
                Assert.True(geomVal.IsNull());

                //Re-set values
                propVals.SetStringValue("KEY", "MOC");
                propVals.SetStringValue("MAPKEY", "MOC123");
                propVals.SetStringValue("NAME", "My Own Country");
                propVals.SetGeometryValue("Geometry", fgf);

                //Re-fetch data values to query null status
                key     = pKey.GetValue() as FdoStringValue;
                mapkey  = pMapkey.GetValue() as FdoStringValue;
                name    = pName.GetValue() as FdoStringValue;
                geomVal = pGeom.GetValue() as FdoGeometryValue;

                Assert.NotNull(key);
                Assert.NotNull(mapkey);
                Assert.NotNull(name);
                Assert.NotNull(geomVal);

                Assert.False(key.IsNull());
                Assert.False(mapkey.IsNull());
                Assert.False(name.IsNull());
                Assert.False(geomVal.IsNull());
            }
        }