public LocalNativeSqlReader(MgSqlDataReader reader)
 {
     _reader   = reader;
     _mgReader = new FixedWKTReader();
     _agfRw    = new MgAgfReaderWriter();
     _wktRw    = new MgWktReaderWriter();
 }
Пример #2
0
        private void InitCommon(Stream stream)
        {
            _reader    = new XmlTextReader(stream);
            _wktReader = new FixedWKTReader();
            _reader.WhitespaceHandling = WhitespaceHandling.Significant;
            _propertyMap = new Dictionary <string, XmlProperty>();

            InitProperties();
        }
Пример #3
0
        public void TestParseXyzmWkt()
        {
            var wkt1 = "POINT XYZM (1 2 3 4)";

            var reader = new FixedWKTReader();
            var geom   = reader.Read(wkt1);

            Assert.NotNull(geom);
        }
Пример #4
0
 public LocalNativeFeatureReader(MgFeatureReader reader)
 {
     _reader              = reader;
     _mgReader            = new FixedWKTReader();
     _agfRw               = new MgAgfReaderWriter();
     _wktRw               = new MgWktReaderWriter();
     base.ClassDefinition = Utility.ConvertClassDefinition(reader.GetClassDefinition());
     base.FieldCount      = reader.GetPropertyCount();
 }
Пример #5
0
        public void TestParse3dWkt()
        {
            var wkt1 = "LINESTRING XYZ (218941.59990888927 173858.42946731683 0, 218931.73921854934 173868.56834443274 0)";
            var wkt2 = "POINT XYZ (1 2 3)";

            var reader = new FixedWKTReader();
            var geom1  = reader.Read(wkt1);

            Assert.NotNull(geom1);
            var geom2 = reader.Read(wkt2);

            Assert.NotNull(geom2);
        }
        protected void PopulateTestDataStore(IServerConnection conn, string fsId, ref FeatureSchema schema, ref ClassDefinition cls)
        {
            CreateTestDataStore(conn, fsId, ref schema, ref cls);

            IInsertFeatures insert = (IInsertFeatures)conn.CreateCommand((int)CommandType.InsertFeature);

            insert.ClassName       = cls.Name;
            insert.FeatureSourceId = fsId;
            var feat = new MutableRecord();

            var reader = new FixedWKTReader();

            //Initialize this record
            feat.PutValue("GEOM", new GeometryValue(reader.Read("POINT (0 0)")));
            feat.PutValue("NAME", new StringValue("Test1"));

            //Attach to command.
            insert.RecordToInsert = feat;

            var res = insert.Execute();

            feat.SetGeometry("GEOM", reader.Read("POINT (0 1)"));
            feat.SetString("NAME", "Test2");

            res = insert.Execute();

            feat.SetGeometry("GEOM", reader.Read("POINT (1 1)"));
            feat.SetString("NAME", "Test3");

            res = insert.Execute();

            feat.SetGeometry("GEOM", reader.Read("POINT (1 0)"));
            feat.SetString("NAME", "Test4");

            res = insert.Execute();
        }
Пример #7
0
 static GeomConverter()
 {
     _agfRw  = new MgAgfReaderWriter();
     _wktRw  = new MgWktReaderWriter();
     _reader = new FixedWKTReader();
 }
        public LocalNativeRecord(MgReader reader, FixedWKTReader mgReader, MgAgfReaderWriter agfRw, MgWktReaderWriter wktRw)
        {
            for (int i = 0; i < reader.GetPropertyCount(); i++)
            {
                string name = reader.GetPropertyName(i);

                _ordinalMap[i] = name;

                var pt = (PropertyValueType)reader.GetPropertyType(name);
                switch (pt)
                {
                    case PropertyValueType.Blob:
                        _values[name] = new BlobValue();
                        break;

                    case PropertyValueType.Boolean:
                        _values[name] = new BooleanValue();
                        break;

                    case PropertyValueType.Byte:
                        _values[name] = new ByteValue();
                        break;

                    case PropertyValueType.Clob:
                        _values[name] = new ClobValue();
                        break;

                    case PropertyValueType.DateTime:
                        _values[name] = new DateTimeValue();
                        break;

                    case PropertyValueType.Double:
                        _values[name] = new DoubleValue();
                        break;

                    case PropertyValueType.Feature:
                        _values[name] = new FeatureValue();
                        break;

                    case PropertyValueType.Geometry:
                        _values[name] = new GeometryValue();
                        break;

                    case PropertyValueType.Int16:
                        _values[name] = new Int16Value();
                        break;

                    case PropertyValueType.Int32:
                        _values[name] = new Int32Value();
                        break;

                    case PropertyValueType.Int64:
                        _values[name] = new Int64Value();
                        break;

                    case PropertyValueType.Raster:
                        _values[name] = new RasterValue();
                        break;

                    case PropertyValueType.Single:
                        _values[name] = new SingleValue();
                        break;

                    case PropertyValueType.String:
                        _values[name] = new StringValue();
                        break;
                }
            }

            for (int i = 0; i < reader.GetPropertyCount(); i++)
            {
                string name = _ordinalMap[i];
                GetByteReaderMethod getblob = () => { return reader.GetBLOB(name); };
                GetByteReaderMethod getclob = () => { return reader.GetCLOB(name); };
                GetByteReaderMethod getgeom = () => { return reader.GetGeometry(name); };
                if (!reader.IsNull(name))
                {
                    var pt = (PropertyValueType)reader.GetPropertyType(name);
                    switch (pt)
                    {
                        case PropertyValueType.Blob:
                            ((BlobValue)_values[name]).Value = Utility.StreamAsArray(new MgReadOnlyStream(getblob));
                            break;

                        case PropertyValueType.Boolean:
                            ((BooleanValue)_values[name]).Value = reader.GetBoolean(name);
                            break;

                        case PropertyValueType.Byte:
                            ((ByteValue)_values[name]).Value = reader.GetByte(name);
                            break;

                        case PropertyValueType.Clob:
                            byte[] b = Utility.StreamAsArray(new MgReadOnlyStream(getclob));
                            ((ClobValue)_values[name]).Value = Encoding.UTF8.GetChars(b);
                            break;

                        case PropertyValueType.DateTime:
                            ((DateTimeValue)_values[name]).Value = Utility.ConvertMgDateTime(reader.GetDateTime(name));
                            break;

                        case PropertyValueType.Double:
                            ((DoubleValue)_values[name]).Value = reader.GetDouble(name);
                            break;
                        //case PropertyValueType.Feature:
                        case PropertyValueType.Geometry:
                            try
                            {
                                //TODO: See if SWIG issues come into play here
                                var geom = agfRw.Read(reader.GetGeometry(name));
                                var wkt = wktRw.Write(geom);
                                ((GeometryValue)_values[name]).Value = mgReader.Read(wkt);
                            }
                            catch //Invalid geometry fail!
                            {
                                ((GeometryValue)_values[name]).SetNull();
                            }
                            break;

                        case PropertyValueType.Int16:
                            ((Int16Value)_values[name]).Value = reader.GetInt16(name);
                            break;

                        case PropertyValueType.Int32:
                            ((Int32Value)_values[name]).Value = reader.GetInt32(name);
                            break;

                        case PropertyValueType.Int64:
                            ((Int64Value)_values[name]).Value = reader.GetInt64(name);
                            break;

                        case PropertyValueType.Single:
                            ((SingleValue)_values[name]).Value = reader.GetSingle(name);
                            break;

                        case PropertyValueType.String:
                            ((StringValue)_values[name]).Value = reader.GetString(name);
                            break;
                    }
                }
            }
        }
Пример #9
0
        public XmlRecord(XmlProperty[] properties, FixedWKTReader wktReader, XmlNodeList propertyNodes, string nameElement, string valueElement)
        {
            for (int i = 0; i < properties.Length; i++)
            {
                string name = properties[i].Name;
                _ordinalMap[i] = name;

                switch (properties[i].Type)
                {
                case PropertyValueType.Blob:
                    _values[name] = new BlobValue();
                    break;

                case PropertyValueType.Boolean:
                    _values[name] = new BooleanValue();
                    break;

                case PropertyValueType.Byte:
                    _values[name] = new ByteValue();
                    break;

                case PropertyValueType.Clob:
                    _values[name] = new ClobValue();
                    break;

                case PropertyValueType.DateTime:
                    _values[name] = new DateTimeValue();
                    break;

                case PropertyValueType.Double:
                    _values[name] = new DoubleValue();
                    break;

                case PropertyValueType.Feature:
                    _values[name] = new FeatureValue();
                    break;

                case PropertyValueType.Geometry:
                    _values[name] = new GeometryValue();
                    break;

                case PropertyValueType.Int16:
                    _values[name] = new Int16Value();
                    break;

                case PropertyValueType.Int32:
                    _values[name] = new Int32Value();
                    break;

                case PropertyValueType.Int64:
                    _values[name] = new Int64Value();
                    break;

                case PropertyValueType.Raster:
                    _values[name] = new RasterValue();
                    break;

                case PropertyValueType.Single:
                    _values[name] = new SingleValue();
                    break;

                case PropertyValueType.String:
                    _values[name] = new StringValue();
                    break;
                }
            }

            foreach (XmlNode propNode in propertyNodes)
            {
                var name      = propNode[nameElement].InnerText;
                var valueNode = propNode[valueElement];
                if (valueNode != null)
                {
                    var value = valueNode.InnerText;
                    switch (_values[name].Type)
                    {
                    case PropertyValueType.Blob:
                        ((BlobValue)_values[name]).Value = Encoding.UTF8.GetBytes(value);
                        break;

                    case PropertyValueType.Boolean:
                        ((BooleanValue)_values[name]).Value = XmlConvert.ToBoolean(value);
                        break;

                    case PropertyValueType.Byte:
                        ((ByteValue)_values[name]).Value = XmlConvert.ToByte(value);
                        break;

                    case PropertyValueType.Clob:
                        ((ClobValue)_values[name]).Value = value.ToCharArray();
                        break;

                    case PropertyValueType.DateTime:
                        var dt = ConvertToDateTime(value);
                        if (dt.HasValue)
                        {
                            ((DateTimeValue)_values[name]).Value = dt.Value;
                        }
                        break;

                    case PropertyValueType.Double:
                        ((DoubleValue)_values[name]).Value = XmlConvert.ToDouble(value);
                        break;

                    case PropertyValueType.Feature:
                        ((FeatureValue)_values[name]).Value = ConvertToFeatures(value);
                        break;

                    case PropertyValueType.Geometry:
                        ((GeometryValue)_values[name]).Value = wktReader.Read(value);
                        break;

                    case PropertyValueType.Int16:
                        ((Int16Value)_values[name]).Value = XmlConvert.ToInt16(value);
                        break;

                    case PropertyValueType.Int32:
                        ((Int32Value)_values[name]).Value = XmlConvert.ToInt32(value);
                        break;

                    case PropertyValueType.Int64:
                        ((Int64Value)_values[name]).Value = XmlConvert.ToInt64(value);
                        break;

                    case PropertyValueType.Raster:
                        ((RasterValue)_values[name]).Value = ConvertToRaster(value);
                        break;

                    case PropertyValueType.Single:
                        ((SingleValue)_values[name]).Value = XmlConvert.ToSingle(value);
                        break;

                    case PropertyValueType.String:
                        ((StringValue)_values[name]).Value = value;
                        break;
                    }
                }
            }
        }
        public virtual void TestInsertFeatures()
        {
            Skip.If(_fixture.Skip, _fixture.SkipReason);

            var             conn   = _fixture.CreateTestConnection();
            var             fsId   = "Library://UnitTests/Data/Test" + GetTestPrefix() + "InsertFeatures.FeatureSource";
            ClassDefinition cls    = null;
            FeatureSchema   schema = null;

            CreateTestDataStore(conn, fsId, ref schema, ref cls);

            IInsertFeatures insert = (IInsertFeatures)conn.CreateCommand((int)CommandType.InsertFeature);

            insert.ClassName       = cls.Name;
            insert.FeatureSourceId = fsId;
            var feat = new MutableRecord();

            var reader = new FixedWKTReader();

            //Initialize this record
            feat.PutValue("GEOM", new GeometryValue(reader.Read("POINT (0 0)")));
            feat.PutValue("NAME", new StringValue("Test1"));

            Assert.True(feat.PropertyExists("GEOM"));
            Assert.True(feat.PropertyExists("NAME"));

            //Attach to command.
            insert.RecordToInsert = feat;

            var res = insert.Execute();

            Assert.Null(res.Error);

            feat.SetGeometry("GEOM", reader.Read("POINT (0 1)"));
            feat.SetString("NAME", "Test2");

            res = insert.Execute();
            Assert.Null(res.Error);

            feat.SetGeometry("GEOM", reader.Read("POINT (1 1)"));
            feat.SetString("NAME", "Test3");

            res = insert.Execute();
            Assert.Null(res.Error);

            feat.SetGeometry("GEOM", reader.Read("POINT (1 0)"));
            feat.SetString("NAME", "Test4");

            res = insert.Execute();
            Assert.Null(res.Error);

            int count = 0;

            using (var rdr = conn.FeatureService.QueryFeatureSource(fsId, cls.Name))
            {
                while (rdr.ReadNext())
                {
                    count++;
                }
                rdr.Close();
            }

            Assert.Equal(4, count);
        }