예제 #1
0
        void ExportGeometry(IGeometry g)
        {
            // c.f. FdoToolbox bulk copy? - FdoBatchedOutputOperation
            using (IInsert cmd = m_Connection.CreateCommand(CommandType.CommandType_Insert) as IInsert)
            {
                cmd.SetFeatureClassName("FC");

                PropertyValueCollection pvc = cmd.PropertyValues;

                //PropertyValue pvId = new PropertyValue();
                //pvId.SetName("ID");
                //pvId.Value = new Int32Value(id);
                //pvc.Add(pvId);

                GeometryValue gv     = new GeometryValue(m_Factory.GetFgf(g));
                PropertyValue pvGeom = new PropertyValue();
                pvGeom.SetName("Geometry");
                pvGeom.Value = gv;
                pvc.Add(pvGeom);

                try
                {
                    IFeatureReader reader = cmd.Execute();
                    reader.Dispose();
                    m_NumOk++;
                }

                catch
                {
                    m_NumFail++;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Adds a new coordinate system to the database
        /// </summary>
        /// <param name="cs"></param>
        public void AddProjection(CoordinateSystemDefinition cs)
        {
            using (var conn = CreateSqliteConnection())
            {
                conn.Open();
                using (IInsert cmd = (IInsert)conn.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_Insert))
                {
                    cmd.SetFeatureClassName("Projections");
                    cmd.PropertyValues.Add(new OSGeo.FDO.Commands.PropertyValue("Name", new StringValue(cs.Name)));
                    cmd.PropertyValues.Add(new OSGeo.FDO.Commands.PropertyValue("Description", new StringValue(cs.Description)));
                    cmd.PropertyValues.Add(new OSGeo.FDO.Commands.PropertyValue("WKT", new StringValue(cs.Wkt)));

                    int affected = 0;
                    using (var reader = cmd.Execute())
                    {
                        while (reader.ReadNext())
                        {
                            affected++;
                        }
                        reader.Close();
                    }

                    if (affected == 1)
                    {
                        _Projections.Add(cs);
                        LoggingService.InfoFormatted("Coordinate System {0} added to database", cs.Name);
                    }
                }
                conn.Close();
            }
        }
예제 #3
0
        /// <summary>
        /// Executes the operation
        /// </summary>
        /// <param name="rows"></param>
        /// <returns></returns>
        public override IEnumerable <FdoRow> Execute(IEnumerable <FdoRow> rows)
        {
            //We fetch the class def here instead of the ctor as the class in question
            //may have to be created by a pre-copy operation
            _clsDef = _service.GetClassByName(this.ClassName);

            IInsert insert = null;

            using (FdoFeatureService service = _conn.CreateFeatureService())
            {
                insert = service.CreateCommand <IInsert>(CommandType.CommandType_Insert);
            }
            this.Info("Set feature class to: {0}", this.ClassName);
            insert.SetFeatureClassName(this.ClassName);
            PropertyValueCollection propVals = insert.PropertyValues;

            Prepare(propVals);
            foreach (FdoRow row in rows)
            {
                Bind(row);
                insert.Prepare();
                try
                {
                    using (IFeatureReader reader = insert.Execute())
                    {
                        reader.Close();
                    }
                }
                catch (OSGeo.FDO.Common.Exception ex)
                {
                    ex.Data["Class/Table"] = this.ClassName;
                    RaiseFailedFeatureProcessed(row, ex);
                    RePrepare(propVals);
                }
                yield return(row);
            }
            insert.Dispose();
            //yield break;
        }
        /// <summary>
        /// Executes the operation
        /// </summary>
        /// <param name="rows"></param>
        /// <returns></returns>
        public override IEnumerable <FdoRow> Execute(IEnumerable <FdoRow> rows)
        {
            int    count  = 0;
            string prefix = "param";

            using (IInsert insertCmd = _service.CreateCommand <IInsert>(CommandType.CommandType_Insert))
            {
                //Prepare command for batch insert
                insertCmd.SetFeatureClassName(this.ClassName);
                foreach (FdoRow row in rows)
                {
                    //Prepare the parameter placeholders
                    if (insertCmd.PropertyValues.Count == 0)
                    {
                        foreach (string col in row.Columns)
                        {
                            //Exclude un-writeable properties
                            if (!_unWritableProperties.Contains(col))
                            {
                                string pName     = col;
                                string paramName = prefix + pName;
                                insertCmd.PropertyValues.Add(new PropertyValue(pName, new Parameter(paramName)));
                            }
                        }
                    }

                    //Load the batch parameter values
                    ParameterValueCollection pVals = CreateParameterValues(prefix, row);
                    insertCmd.BatchParameterValues.Add(pVals);
                    count++;

                    //Insert the batch when the number of features batched
                    //reaches the specified number
                    if (count == this.BatchSize)
                    {
                        using (IFeatureReader reader = insertCmd.Execute())
                        {
                            reader.Close();
                            this.BatchInserted(this, new BatchInsertEventArgs(count));
                            this.RaiseBatchProcessed(count);
                            _batchTotal += count;
                        }
                        count = 0;
                        insertCmd.BatchParameterValues.Clear();
                    }
                }

                //Insert the remaining batch
                if (count > 0)
                {
                    using (IFeatureReader reader = insertCmd.Execute())
                    {
                        reader.Close();
                        this.BatchInserted(this, new BatchInsertEventArgs(count));
                        this.RaiseBatchProcessed(count);
                        _batchTotal += count;
                    }
                    count = 0;
                    insertCmd.BatchParameterValues.Clear();
                }
            }
            yield break;
        }
예제 #5
0
        public static void Test_LargeDataVolumeInsert(string SDFFile, string tableName)
        {
            try
            {
                IConnection mConnection = SDFHelper.SDFConnection(SDFFile);
                mConnection.Open();
                IInsert insertCmd = (IInsert)mConnection.CreateCommand(CommandType.CommandType_Insert);

                insertCmd.SetFeatureClassName("Civil_schema:" + tableName);
                PropertyValueCollection propVals = insertCmd.PropertyValues;

                PropertyValue propVal1 = new PropertyValue();
                propVal1.Name = new Identifier("Name");
                PropertyValue propVal2 = new PropertyValue();
                propVal2.Name = new Identifier("NetworkName");
                PropertyValue propVal3 = new PropertyValue();
                propVal3.Name = new Identifier("PartSizeName");
                //PropertyValue propVal4 = new PropertyValue();
                //propVal4.Name = new Identifier("RimElevation");
                PropertyValue propVal5 = new PropertyValue();
                propVal5.Name = new Identifier("Geometry");

                Expression expr1 = Expression.Parse("'AB'");
                Expression expr2 = Expression.Parse("'Poor'");
                Expression expr4 = Expression.Parse("'Down'");
                Expression expr5 = Expression.Parse("GEOMFROMTEXT('LINESTRING XY (100000.0 100000.0, 200000.0 200000.0, 100000.0 300000.0)')");
                //Int32Value intVal = new Int32Value(0);

                propVals.Clear();
                propVals.Add(propVal1);
                propVals.Add(propVal2);
                propVals.Add(propVal3);
                //propVals.Add(propVal4);
                propVals.Add(propVal5);

                propVal1.Value = (ValueExpression)expr1;
                propVal2.Value = (ValueExpression)expr2;
                //propVal3.Value = (ValueExpression)intVal;
                //propVal4.Value = (ValueExpression)expr4;
                propVal5.Value = (ValueExpression)expr5;

                IFeatureReader reader;
                //reader.Dispose();

                for (Int32 counter = 0; counter < 1000; counter++)
                {
                    //intVal.Int32 = counter;
                    reader = insertCmd.Execute();
                    reader.Close();
                }

                mConnection.Close();
                Debug.Write("Test_LargeDataVolumeInsert runs successfully !");
            }
            catch (OSGeo.FDO.Common.Exception ge)
            {
                bool ok = ge.Message.Contains("read-only");
                Debug.Write(ge.ToString());
            }
            catch (SystemException ex)
            {
                bool ok = ex.Message.Contains("read-only");
                Debug.Write(ex.ToString());
            }
        }
예제 #6
0
        public static void Test_LargeDataVolumeInsert2(string SDFFile, string tableName, IndexedDictionary <string, string[]> data)
        {
            try
            {
                IConnection mConnection = SDFHelper.SDFConnection(SDFFile);
                mConnection.Open();
                IInsert insertCmd = (IInsert)mConnection.CreateCommand(CommandType.CommandType_Insert);

                insertCmd.SetFeatureClassName("Civil_schema:" + tableName);
                PropertyValueCollection propVals = insertCmd.PropertyValues;

                Debug.Write("\n================CHECK INSERT TO SDF ================= " + data.Count());
                Debug.Write("\n==========Dict===");
                foreach (var it in data)
                {
                    Debug.Write("\n== Key: " + "'" + it.Key + "'");
                    Debug.Write("\n== val: " + "'" + it.Value[0] + "'");
                    Debug.Write("\n== val: " + "'" + it.Value[1] + "'");
                }
                Debug.Write("\n==========Dict===");

                //Debug.Write("\n== name: " + "'" + data["Name"][1] + "'");
                //Debug.Write("\n== NetworkName: " + "'" + data["NetworkName"][1] + "'");
                //Debug.Write("\n== PartSizeName: " + "'" + data["PartSizeName"][1] + "'");
                //Debug.Write("\n== Geometry: " + "GEOMFROMTEXT('" + data["Geometry"][1] + "')");

                //Expression expr1 = Expression.Parse("'" + data["Name"][1] + "'");
                //Expression expr2 = Expression.Parse("'" + data["NetworkName"][1] + "'");
                //Expression expr3 = Expression.Parse("'" + data["PartSizeName"][1] + "'");
                //Expression expr5 = Expression.Parse("GEOMFROMTEXT('" + data["Geometry"][1] + "')");

                Debug.Write("\n================CHECK INSERT TO SDF =================");


                PropertyValue propVal1 = new PropertyValue();
                propVal1.Name = new Identifier("Name");
                PropertyValue propVal2 = new PropertyValue();
                propVal2.Name = new Identifier("NetworkName");
                PropertyValue propVal3 = new PropertyValue();
                propVal3.Name = new Identifier("PartSizeName");
                //PropertyValue propVal4 = new PropertyValue();
                //propVal4.Name = new Identifier("RimElevation");
                PropertyValue propVal5 = new PropertyValue();
                propVal5.Name = new Identifier("Geometry");

                Expression expr1 = Expression.Parse("'AB'");
                Expression expr2 = Expression.Parse("'Poor'");
                Expression expr4 = Expression.Parse("'Down'");
                Expression expr5 = Expression.Parse("GEOMFROMTEXT('LINESTRING XY (100000.0 100000.0, 200000.0 200000.0, 100000.0 300000.0)')");
                //Int32Value intVal = new Int32Value(0);

                propVals.Clear();
                propVals.Add(propVal1);
                propVals.Add(propVal2);
                propVals.Add(propVal3);
                //propVals.Add(propVal4);
                propVals.Add(propVal5);

                propVal1.Value = (ValueExpression)expr1;
                propVal2.Value = (ValueExpression)expr2;
                //propVal3.Value = (ValueExpression)intVal;
                //propVal4.Value = (ValueExpression)expr4;
                propVal5.Value = (ValueExpression)expr5;

                IFeatureReader reader;
                //reader.Dispose();
                reader = insertCmd.Execute();
                reader.Close();


                mConnection.Close();
                Debug.Write("Test_LargeDataVolumeInsert runs successfully !");
            }
            catch (OSGeo.FDO.Common.Exception ge)
            {
                bool ok = ge.Message.Contains("read-only");
                Debug.Write(ge.ToString());
            }
            catch (SystemException ex)
            {
                bool ok = ex.Message.Contains("read-only");
                Debug.Write(ex.ToString());
            }
        }
예제 #7
0
        public static void SDFInsert_bulk(string SDFFile, string tableName, IndexedDictionary <string, string[]> data)
        {
            try
            {
                IConnection mConnection = SDFHelper.SDFConnection(SDFFile);
                mConnection.Open();
                IInsert insertCmd = (IInsert)mConnection.CreateCommand(CommandType.CommandType_Insert);

                insertCmd.SetFeatureClassName("Civil_schema:" + tableName);

                PropertyValueCollection propValmain = insertCmd.PropertyValues;
                propValmain.Clear();
                //remove coordinates - which is not needed for sdf
                data.Remove("coordinates");
                foreach (var item in data)
                {
                    PropertyValue propVal = new PropertyValue();
                    propVal.Name = new Identifier(item.Key);
                    Expression expValue;
                    string     dataType = data[item.Key][0];
                    string     value    = data[item.Key][1];

                    Debug.Write("\nProperty: " + item.Key);
                    Debug.Write("\ndataType: " + dataType);
                    Debug.Write("\nvalue: " + value);

                    if (data[item.Key][0].Equals("geometry"))
                    {
                        expValue = Expression.Parse(value);
                    }
                    else if (data[item.Key][0].Equals("String"))
                    {
                        Debug.Write("\nInside String");
                        DataType dt = FDODataHelper.getDataType(dataType);
                        expValue = FDODataHelper.ParseByDataType("'" + value + "'", dt);
                    }
                    else
                    {
                        Debug.Write("\nInside Else");
                        DataType dt = FDODataHelper.getDataType(dataType);
                        expValue = FDODataHelper.ParseByDataType(value, dt);
                    }
                    propValmain.Add(propVal);
                    propVal.Value = (ValueExpression)expValue;
                }
                #region MyRegion

                /*
                 * PropertyValueCollection propVals = insertCmd.PropertyValues;
                 * PropertyValue propVal1 = new PropertyValue();
                 * propVal1.Name = new Identifier("Name");
                 * PropertyValue propVal2 = new PropertyValue();
                 * propVal2.Name = new Identifier("NetworkName");
                 * PropertyValue propVal3 = new PropertyValue();
                 * propVal3.Name = new Identifier("PartSizeName");
                 * //PropertyValue propVal4 = new PropertyValue();
                 * //propVal4.Name = new Identifier("RimElevation");
                 * PropertyValue propVal5 = new PropertyValue();
                 * propVal5.Name = new Identifier("Geometry");
                 *
                 * Expression expr1 = Expression.Parse("'AB'");
                 * Expression expr2 = Expression.Parse("'Poor'");
                 * Expression expr4 = Expression.Parse("'Down'");
                 * Expression expr5 = Expression.Parse("GEOMFROMTEXT('LINESTRING XY (100000.0 100000.0, 200000.0 200000.0, 100000.0 300000.0)')");
                 * //Int32Value intVal = new Int32Value(0);
                 *
                 * propVals.Clear();
                 * propVals.Add(propVal1);
                 * propVals.Add(propVal2);
                 * propVals.Add(propVal3);
                 * //propVals.Add(propVal4);
                 * propVals.Add(propVal5);
                 *
                 * propVal1.Value = (ValueExpression)expr1;
                 * propVal2.Value = (ValueExpression)expr2;
                 * //propVal3.Value = (ValueExpression)intVal;
                 * //propVal4.Value = (ValueExpression)expr4;
                 * propVal5.Value = (ValueExpression)expr5;
                 */

                #endregion

                IFeatureReader reader;
                //reader.Dispose();
                reader = insertCmd.Execute();
                reader.Close();

                mConnection.Close();
                Debug.Write("Test_LargeDataVolumeInsert runs successfully !");
            }
            catch (OSGeo.FDO.Common.Exception ge)
            {
                bool ok = ge.Message.Contains("read-only");
                Debug.Write(ge.ToString());
            }
            catch (SystemException ex)
            {
                bool ok = ex.Message.Contains("read-only");
                Debug.Write(ex.ToString());
            }
        }