コード例 #1
0
        public void ImportLayer(MG_Layer layer)
        {
            if (layer == null)
            {
                return;
            }
            // stop multi same data
            if (this.IsTableExist(layer.GetLayerName()))
            {
                return;
            }

            this.CreateTable(layer.FieldSet, layer.Type);
            string layerName = layer.FieldSet.GetName();
            int    fc        = layer.GetFeatureCount();

            // save ext
            this.CreateTableExt();
            this.InsertExtent(layerName, layer.Extent);
            for (int i = 0; i < fc; i++)
            {
                MG_Feature f = layer.GetFeature(i);
                if (f.Geometry.Type == layer.Type)
                {
                    this.Insert(layerName, f.ValueSet, f.Geometry);
                }
            }
        }
コード例 #2
0
        public static void CreateMap(MG_Map map, string mapPath)
        {//  c:\\data\\hello.map    c:\\data\\layer.shp
            if (map == null)
            {
                return;
            }
            // set MapPath
            map.SetMapPath(mapPath);

            // save map  (layerCount  n * layerPath)
            int count = map.GetLayerCount();

            StreamWriter sw = new StreamWriter(mapPath); // stream writer

            sw.WriteLine(count);                         // layerCount

            for (int i = 0; i < count; i++)
            {
                string   mapFolder = Path.GetDirectoryName(mapPath);
                MG_Layer layer     = map.GetLayer(i);

                string layerPath = mapFolder + "\\" + layer.GetLayerName() + ".shp";
                CreateShapeFile(layer, layerPath); //save layer

                sw.WriteLine(layerPath);           // layerPath
            }
            sw.Close();
        }
コード例 #3
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);
        }