Beispiel #1
0
        private string sql_CreateTable(MG_FieldSet fieldSet, MG_GeometryType gt)
        {// oid, field1, field2, field3, field4,...fieldN, geom
         //CREATE TABLE point2 ( oid SERIAL PRIMARY KEY, name1 VARCHAR, name2 VARCHAR); SELECT AddGeometryColumn('public','point2','geom',0,'POINT',2);
         // table name, column name must be lowercase, e.g.   pointTABLE --->pointtable

            string front = "CREATE TABLE {0} ( oid SERIAL PRIMARY KEY";
            string table = fieldSet.GetName().ToLower();

            front = String.Format(front, table);

            string m   = ", {0} {1}";
            string mid = "";

            for (int i = 0; i < fieldSet.Count(); i++)
            {
                MG_Field field = fieldSet.GetAt(i);
                mid += String.Format(m, field.Name.ToLower(), field.Type.ToString());
            }
            string end = "); SELECT AddGeometryColumn('public','{0}','geom',0,'{1}',2);";

            end = String.Format(end, table, gt.ToString());

            string strSQL = front + mid + end;

            return(strSQL);
        }
        protected MG_FeatureSet GetFeatureSet(MG_FieldSet fieldSet, string table)
        {
            NpgsqlDataReader reader = this.SelectAll(table);

            if (reader == null || !reader.HasRows)
            {
                return(null);
            }

            MG_FeatureSet featureSet = new MG_FeatureSet();
            int           fc         = reader.FieldCount; // 4

            while (reader.Read())
            {// oid f1,f2,f3... geom
                MG_Feature  f        = new MG_Feature(fieldSet);
                MG_ValueSet valueSet = new MG_ValueSet();
                string      oid      = reader["oid"].ToString();
                string      geom     = reader["geomtext"].ToString();

                for (int i = 1; i < fc - 1; i++)
                {
                    string   str   = reader[i].ToString();
                    MG_Value value = new MG_Value(i - 1, str);
                    valueSet.Add(value);
                }
                f.ValueSet = valueSet;
                f.Geometry = MG_ShapeFileOper.AsGeometry(geom);
                featureSet.Add(f);
            }
            reader.Close();
            reader.Dispose();
            return(featureSet);
        }
 public int CreateTable(MG_FieldSet fieldSet, MG_GeometryType gt)
 {
     if (this.IsTableExist(fieldSet.GetName()))
     {
         return(0);
     }
     this.sql_CreateTable(fieldSet, gt, out m_strSQL, out m_sqlParams);
     return(this.RunSQL(m_strConn, m_strSQL, m_sqlParams));
 }
Beispiel #4
0
        public int CreateTable(MG_FieldSet fieldSet, MG_GeometryType gt)
        {
            if (this.IsTableExist(fieldSet.GetName()))
            {
                return(0);
            }
            string strSQL = this.sql_CreateTable(fieldSet, gt);

            return(this.Run(strSQL));
        }
Beispiel #5
0
        public static MG_Feature AsFeature(Feature f)
        {
            FeatureDefn def       = f.GetDefnRef();
            MG_FieldSet fieldSet  = AsFieldSet(def);
            MG_Feature  mgFeature = new MG_Feature(fieldSet);//collect data

            // geometry
            Geometry    g        = f.GetGeometryRef();
            MG_Geometry geometry = AsGeometry(g);
            string      wkt      = geometry.AsWKT(); // Test

            mgFeature.SetGeometry(geometry);         //collect data

            // symbol
            string styleString = f.GetStyleString();
            //f.SetStyleString(styleString);

            // attribute value
            MG_ValueSet valueSet    = new MG_ValueSet();
            int         fid         = f.GetFID();
            int         nFieldCount = f.GetFieldCount();

            for (int iField = 0; iField < nFieldCount; iField++)
            {
                FieldDefn fdef      = def.GetFieldDefn(iField);
                FieldType fieldType = fdef.GetFieldType();//OFTInteger OFTString OFTString

                MG_Value mgValue = new MG_Value();
                mgValue.Index = iField;// collect data
                //collect data
                if (fieldType == FieldType.OFTString)
                {
                    mgValue.Value = f.GetFieldAsString(iField);
                }
                else if (fieldType == FieldType.OFTInteger)
                {
                    mgValue.Value = f.GetFieldAsInteger(iField);
                }
                else if (fieldType == FieldType.OFTReal)
                {
                    mgValue.Value = f.GetFieldAsDouble(iField);
                }
                else if (fieldType == FieldType.OFTDateTime)
                {
                    int year, month, day, hour, minute, second, flag;
                    f.GetFieldAsDateTime(iField, out year, out month, out day, out hour, out minute, out second, out flag);
                    mgValue.Value = new DateTime(year, month, day, hour, minute, second, flag);
                }
                valueSet.Add(mgValue);
            }
            mgFeature.ValueSet = valueSet;//collect data

            return(mgFeature);
        }
Beispiel #6
0
        public static FeatureDefn ToFeatureDefn(MG_FieldSet fieldSet)
        {
            FeatureDefn def = new FeatureDefn(null);

            for (int i = 0; i < fieldSet.Count(); i++)
            {
                MG_Field  field = fieldSet.GetAt(i);
                FieldDefn fdef  = ToFieldDefn(field);
                def.AddFieldDefn(fdef);
            }
            return(def);
        }
Beispiel #7
0
        public static MG_FieldSet AsFieldSet(FeatureDefn f)
        {
            MG_FieldSet fieldSet = new MG_FieldSet(f.GetName());// name
            int         count    = f.GetFieldCount();

            for (int i = 0; i < count; i++)
            {
                MG_Field field = AsField(f.GetFieldDefn(i));
                fieldSet.Add(field);
            }
            return(fieldSet);
        }
        public MG_Layer ExportLayer(string table)
        {
            MG_Layer mgLayer = new MG_Layer();

            mgLayer.SetLayerName(table);//

            // read ext
            mgLayer.Extent = this.GetExtent(table);
            MG_FieldSet fieldSet = this.GetFieldSet(table);

            mgLayer.FieldSet   = fieldSet;// collect data
            mgLayer.FeatureSet = this.GetFeatureSet(mgLayer.GetFieldSet(), table);
            mgLayer.Type       = mgLayer.FeatureSet.GetAt(0).Geometry.Type;
            return(mgLayer);
        }
        protected MG_FieldSet GetFieldSet(string table)
        {
            ArrayList columns = this.GetColumnNames(table);
            ArrayList types   = this.GetColumnTypes(table);

            if (columns == null || types == null)
            {
                return(null);
            }
            int columnCount = columns.Count;
            int typeCount   = types.Count;

            if (columnCount != typeCount)
            {
                return(null);
            }
            MG_FieldSet fieldSet = new MG_FieldSet(table);

            // oid .... geom
            for (int i = 0; i < columnCount; i++)
            {
                string column = columns[i].ToString();
                string type   = types[i].ToString();
                if (!column.Equals("oid") && !column.Equals("geom"))
                {
                    // oid      name                geom         no       length
                    // integer character varying  USER-DEFINED  integer double precision
                    MG_FieldDBType dbType = MG_FieldDBType.VARCHAR;
                    if (type.Equals("integer"))
                    {
                        dbType = MG_FieldDBType.INTEGER;
                    }
                    else if (type.Equals("character varying"))
                    {
                        dbType = MG_FieldDBType.VARCHAR;
                    }
                    else if (type.Equals("double precision"))
                    {
                        dbType = MG_FieldDBType.FLOAT8;
                    }

                    MG_Field field = new MG_Field(column, dbType);
                    fieldSet.Add(field);
                }
            }

            return(fieldSet);
        }