sanjay.matela

Point collection to polyline apparently is too slow please suggest

Discussion created by sanjay.matela on Mar 29, 2011
Hi *
* * * * * * * *
My ReadSHPToEdgeShapeList. function reads all the edge shape points from the table shp of the oracle schema to memeory list public List<ShpRec> EdgeShapeList, whcih is declared in my defined class say, SHP

public struct ShpRec
    {
        public int EDGEID_NUMBER;
         public int XCOORDINATE;
        public int YCOORDINATE;
        public int SEQNR;

        public ShpRec(int SR_EDGEID_NUMBER,
                      int SR_XCOORDINATE,
                      int SR_YCOORDINATE,
                      int SR_SEQNR)
        {
            EDGEID_NUMBER = SR_EDGEID_NUMBER;
             XCOORDINATE = SR_XCOORDINATE;
            YCOORDINATE = SR_YCOORDINATE;
            SEQNR = SR_SEQNR;
        }

    }


public List<ShpRec> EdgeShapeList;

So *some thing to load data from oracle table into the EdgeShapeList memory :* * * * * * * * *

* * * * * * * * SHP MyDbSHP = new SHP();
* * * * * * * * MyDbSHP.ReadSHPToEdgeShapeList();

This is OK an runs fast to load points for each edge in the list EdgeShapeList
* * * * * *

Then follwing function creates the shape file as polyline feature.

* * * * * * * * MyDbSHP.EdgeShapeListToESRI(strFolder, strName,this);

My problem is, the process runs slow : takes around 2-3 hours to convert some 2000 edges  and would take two days to convert normal sized database of 50,000 edges

Is it due to that it  posts to fc by pFeature.Store(), for each polyline(PointCollection) ?
Please suggest. Thanks in advance.

Details of my function EdgeShapeListToESRI is as follows :

public void EdgeShapeListToESRI(String ESLTE_Workspace, String ESLTE_FileName, Form ESLTEfrm)
            {
                try
                {
                    //init Shape Field Name
                    String strShapeFieldName = "Shape";


                    //Open the folder to contain the shapefile as a workspace
                    IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
                    IFeatureWorkspace pFWS = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(ESLTE_Workspace, 0);

                    //declare feature class interface
                    IFeatureClass pFeatClass;

                    // if_shape_file_present
                    if (File.Exists(ESLTE_Workspace + "\\" + ESLTE_FileName + ".shp"))
                    {
                        pFeatClass = pFWS.OpenFeatureClass(ESLTE_FileName);
                    }// end if_shape_file_already_present

                    //else_shape_file_present
                    else
                    {
                        //Set up a simple fields collection
                        IFields pFields;
                        IFieldsEdit pFieldsEdit;

                        //Create Field collection
                        pFields = new FieldsClass();
                        //QI to IFieldsEdit from Fields object
                        pFieldsEdit = (IFieldsEdit)pFields;

                        //delcare IField and IFieldEdit
                        IField pfield;
                        IFieldEdit pFieldEdit;

                        //Make the shape field
                        //it will need to give Name,tyep and geometry definition(with a spatial reference) of the Field
                        pfield = new FieldClass();
                        //QI to IFieldEdit from Field Object
                        pFieldEdit = (IFieldEdit)pfield;

                        //init IfieldEdit Interface of Field Object
                        //define Name and Type of the Field
                        pFieldEdit.Name_2 = strShapeFieldName;
                        pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;


                        //Define Geometry Type to Add Refernece
                        IGeometryDef pGeomDef;
                        IGeometryDefEdit pGeomDefEdit;

                        //create GeometryDef
                        pGeomDef = new GeometryDef();
                        //QI to IGeometryDefEdit from GeometryDef object
                        pGeomDefEdit = (IGeometryDefEdit)pGeomDef; //see the type casting

                        pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
                        //pGeomDefEdit.SpatialReference_2 = new UnknownCoordinateSystem();
                        pGeomDefEdit.SpatialReference_2 = new UnknownCoordinateSystem() as ISpatialReference;

                        //Define
                        pFieldEdit.GeometryDef_2 = pGeomDef;

                        //Add above defined field to
                        pFieldsEdit.AddField(pfield);

                        //Add another miscellaneous text field
                        pfield = new FieldClass();
                        pFieldEdit = (IFieldEdit)pfield;

                        pFieldEdit.Name_2 = "MiscText";
                        pFieldEdit.Length_2 = 30;
                        pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;


                        pFieldsEdit.AddField(pfield);

                        /*
                         * USING FIELDS CREAT A SHAPE FILE IN THE OBTAINED WORKSPACE(FOLDER)
                         * some parameters apply to geodatabase options and can be defaulted as Nothing
                         * FeatureWorkspaces's CreateFeatureClass() returns a FeatureClass
                         */

                        //IFeatureClass pFeatClass;
                        pFeatClass = pFWS.CreateFeatureClass(ESLTE_FileName, pFields, null, null, esriFeatureType.esriFTSimple, strShapeFieldName, "");


                    }// end else_shape_file_present
                  

                    //Create point by x,y cordinate. and collect it into pointcollection
                   
                

                    if (EdgeShapeList==null)
                    {
                        MessageBox.Show("No Shape Available");
                        return;
                    }
                   
                   
                    IPointCollection pPointCollection;
                    IPolyline pPolyline;

                    //create PointCollection for polyline
                    pPointCollection = new Polyline();

                    IPoint pPoint;
                    pPoint = new ESRI.ArcGIS.Geometry.PointClass();
                    //add shape points to to form geometry collection (polyline)
                    object o = Type.Missing;
                   
                   
                    int ctr = 0;
                    int CurrentEdgeid = EdgeShapeList[0].EDGEID_NUMBER;
                    for (int i = 0; i < EdgeShapeList.Count; i++)
                    {
                        if (CurrentEdgeid == EdgeShapeList[i].EDGEID_NUMBER)
                        {
                            pPoint.X = EdgeShapeList[i].XCOORDINATE;
                            pPoint.Y = EdgeShapeList[i].YCOORDINATE;

                            pPointCollection.AddPoint(pPoint, ref o, ref o);
                            CurrentEdgeid = EdgeShapeList[i].EDGEID_NUMBER;
                        }
                        else //if edge id changes first save existing PointCollection to a Polyline and create new point collection
                        {
                            // Type casting of IPolyline from Point collection                    
                            pPolyline = (IPolyline)pPointCollection;


                            /*==========================================
                             * Create Edge record (Feature) From Shape List
                             *===========================================
                             */


                            IFeature pFeature;


                            if (pFeatClass == null)
                            {
                                MessageBox.Show("Feature Class can not be accessed");
                                return;

                            }

                            // Store Polyline as a current feature record

                            //create a new feature(record) from the feature class
                            pFeature = pFeatClass.CreateFeature();

                            //add geometry to the feature
                            pFeature.Shape = pPolyline;

                            //add feature(record) to the shape file
                            pFeature.Store();

                           
                            //Free the previous polyline object
                            pPolyline.SetEmpty();
                                                       
                            pPoint.X = EdgeShapeList[i].XCOORDINATE;
                            pPoint.Y = EdgeShapeList[i].YCOORDINATE;

                            pPointCollection.AddPoint(pPoint, ref o, ref o);
                            CurrentEdgeid = EdgeShapeList[i].EDGEID_NUMBER;
                       
                        }

                        ctr = ctr + 1;

                         if (ctr == 100)
                        {
                            //RSTESLfrm.Invalidate();
                            Application.DoEvents();
                            ESLTEfrm.Refresh();

                            ctr = 0;

                        }

                    }//end for

           
                }//End of Try_1
                catch (Exception e1)
                {
                    MessageBox.Show(e1.Message.ToString());

                }//Ent of Catch_1

               

            }//End of EdgeShapeListToESRI

Outcomes