Esempio n. 1
0
        public static Feature ToFeature(MG_Feature mgFeature)
        {
            // field set
            FeatureDefn def = ToFeatureDefn(mgFeature.GetFieldSet());
            Feature     f   = new Feature(def);

            // field value
            int fieldCount = mgFeature.GetFieldCount();

            for (int i = 0; i < fieldCount; i++)
            {
                object    value     = mgFeature.GetValue(i).Value;
                FieldType fieldType = f.GetFieldType(i);
                if (fieldType == FieldType.OFTString)
                {
                    if (value != null)
                    {
                        f.SetField(i, value.ToString());
                    }
                }
                else if (fieldType == FieldType.OFTInteger)
                {// id name url
                    if (value != null)
                    {
                        f.SetField(i, Int32.Parse(value.ToString()));
                    }
                }
                else if (fieldType == FieldType.OFTReal)
                {
                    if (value != null)
                    {
                        f.SetField(i, Double.Parse(value.ToString()));
                    }
                }
                else if (fieldType == FieldType.OFTDateTime)
                {
                    if (value != null)
                    {
                        DateTime dt = (DateTime)value;
                        f.SetField(i, dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, dt.Millisecond);
                    }
                }
            }
            //geometry
            string   wkt = mgFeature.GetGeometry().AsWKT();
            Geometry g   = Geometry.CreateFromWkt(wkt);
            // test
            Envelope env = new Envelope();

            g.GetEnvelope(env);

            f.SetGeometry(g);

            //f.SetStyleString(null);

            return(f);
        }
Esempio n. 2
0
        private DataTable GetDataTable(MG_Layer layer)
        {
            // Create a new DataTable.
            DataTable table = new DataTable(layer.GetLayerName());

            // add oid
            DataColumn oid_Column = new DataColumn("OID", Type.GetType("System.Int32"));

            table.Columns.Add(oid_Column);

            int i, j;

            // Add the column
            for (i = 0; i < layer.GetFieldSet().Count(); i++)
            {
                MG_Field   field  = layer.GetFieldSet().GetAt(i);
                DataColumn column = new DataColumn(field.Name);
                column.DataType = Type.GetType("System.String");
                // Add the Column to the DataColumnCollection.
                table.Columns.Add(column);
            }

            // Add the row
            for (i = 0; i < layer.GetFeatureCount(); i++)
            {
                MG_Feature f   = layer.GetFeature(i);
                DataRow    row = table.NewRow();
                // add oid
                row[0] = i + 1;

                for (j = 0; j < f.GetFieldCount(); j++)
                {
                    object value = f.GetValue(j).Value;
                    if (value != null)
                    {
                        row[j + 1] = value.ToString();
                    }
                }

                // Add the row to the DataRowCollection.
                table.Rows.Add(row);
            }

            return(table);
        }