Exemplo n.º 1
0
        private MG_FieldSet FieldSet; // same as Layer.FieldSet

        #endregion Fields

        #region Constructors

        public MG_Feature(MG_FieldSet fs)
        {
            this.FieldSet = fs;
            this.ValueSet = new MG_ValueSet();
            this.Geometry = new MG_Geometry();
            this.Symbol = new MG_Symbol();
        }
Exemplo n.º 2
0
        public MG_Feature(MG_Feature f)
        {
            this.FieldSet = new MG_FieldSet();
            this.ValueSet = new MG_ValueSet();
            this.Geometry = new MG_Geometry();
            this.Symbol = new MG_Symbol();

            for (int i = 0; i < f.GetFieldCount();i++ )
            {
                MG_Field field = f.GetFieldSet().GetAt(i);
                MG_Field newField = new MG_Field(field);
                this.FieldSet.Add(newField);

                MG_Value value = f.GetValue(i);
                MG_Value newValue = new MG_Value(value);
                this.ValueSet.Add(newValue);
            }
            MG_Geometry g = f.GetGeometry();
            MG_Geometry newGeom = new MG_Geometry();
            switch (g.Type)
            {
                case MG_GeometryType.NONE:
                    break;
                case MG_GeometryType.POINT:
                    newGeom = new MG_Point(g as MG_Point);
                    break;
                case MG_GeometryType.MULTIPOINT:
                    newGeom = new MG_MultiPoint(g as MG_MultiPoint);
                    break;
                case MG_GeometryType.LINESTRING:
                    newGeom = new MG_LineString(g as MG_LineString);
                    break;
                case MG_GeometryType.MULTILINESTRING:
                    newGeom = new MG_MultiLineString(g as MG_MultiLineString);
                    break;
                case MG_GeometryType.POLYGON:
                    newGeom = new MG_Polygon(g as MG_Polygon);
                    break;
                case MG_GeometryType.MULTIPOLYGON:
                    newGeom = new MG_MultiPolygon(g as MG_MultiPolygon);
                    break;
            }
            this.Geometry = newGeom;
            MG_Symbol newSymbol = new MG_Symbol(f.GetSymbol());
            this.Symbol = newSymbol;
        }
 public int Insert(string table, MG_ValueSet valueSet, MG_Geometry geometry)
 {
     this.sql_Insert(table, valueSet, geometry, out m_strSQL, out m_sqlParams);
     return this.RunSQL(m_strConn, m_strSQL, m_sqlParams);
 }
        private void sql_Insert(string table, MG_ValueSet valueSet, MG_Geometry geometry, out string strSQL, out NpgsqlParameter[] sqlParams)
        {
            // oid, field1, field2, field3, field4,...fieldN, geom
            //  INSERT INTO point(f1, f2, f3, geom) VALUES('v1', 'v2', 'v3', ST_GeometryFromText('POINT (100 200)',0));
            string str1 = "INSERT INTO {0}(";
            str1 = String.Format(str1, table);

            // oid name geom cityno length
            // name cityno length
            ArrayList columns = this.GetTableColumnNames(table);
            string str2 = "";
            string str4 = "";
            if (columns!= null && valueSet!=null)
            {
                string temp1 = "{0}, ";
                string temp2 = "'{0}', ";
                int countField = columns.Count; //5
                int countValue = valueSet.Count(); // 3
                if (countField-2 == countValue) // oid geom
                {
                    for (int i = 0; i < countField; i++)
                    {
                        string column = columns[i].ToString();
                        if (!column.Equals("oid") && !column.Equals("geom"))
                        {
                            str2 += String.Format(temp1, column);
                        }
                    }
                    for (int j = 0; j < countValue;j++ )
                    {
                        str4 += String.Format(temp2, valueSet.GetAt(j).Value);
                    }
                }
            }
            string str3 = "geom) VALUES(";
            string str5 = "ST_GeometryFromText('{0}',0));";
            str5 = String.Format(str5, geometry.AsWKT());

            strSQL = str1+str2+str3+str4+str5;
            sqlParams = null;
        }
Exemplo n.º 5
0
        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;
        }