AnsweredAssumed Answered

How to Create Polygon Using ArcGis

Question asked by harssh1021 on Aug 12, 2014
Latest reply on Oct 23, 2015 by SEria-esristaff

Hello,

 

i am creating shape file using arcGis SDK. I want to create polygon in that shape file. i have Geomatryfield like this

" POLYGON ((-97.091258814999946 21.153612301000067, -97.090160336999929 21.154729485000075, -97.08989693399991 21.155753729000082, -97.089844970999934 21.157099041000038, -97.090019709999922 21.158772747000057, -97.090426326999932 21.16077292600005, -97.091026447999923 21.163059955000051, -97.091771189999918 21.165583844000082, -97.092611663999946 21.168294229000082, -97.093498981999915 21.171141495000086, -97.094383851999908 21.174076028000059, -97.095217359999936 21.177047463000065, -97.09595059499992 21.180006181000067, -97.096547076999911 21.182908041000076, -97.097018125999909 21.185733827000035, -97.097388293999927 21.18846904500009, -97.0976825439999 21.19109994300004, -97.097923843999922 21.193612415000075, -97.09813756199992 21.195992703000059, -97.098347477999937 21.198227440000039, -97.0985777549999 21.200301757000091, -97.098852614999942 21.20220527500004, -97.0991956069999 21.203937732000043, -97.099629536999942 21.205502989000081, -97.100177594999934 21.20690378200004, -97.1008633809999 21.208143590000077, -97.101709686999925 21.209225151000055, -97.102740111999935 21.210151942000039, -97.103977052999937 21.210927077000065, -97.1054337789999 21.211558263000086, -97.1070798589999 21.212070158000074, -97.108874545999925 21.212492780000048, -97.110776676999933 21.212854653000079, -97.11274590599993 21.213185796000062, -97.1147414809999 21.213515484000084, -97.1167222549999 21.213873001000081, -97.1186474779999 21.214287630000058, -97.120483450999927 21.214777722000065, -97.122221417999924 21.21531380600004, -97.123861665999925 21.215855825000062, -97.125402478999945 21.216363372000046, -97.126842535999913 21.216796035000073, -97.1281809159999 21.21711339400008, -97.129417092999915 21.217275027000085, -97.130549341999938 21.217240525000079, -97.131578087999912 21.216981434000047, -97.1325087649999 21.216517164000038, -97.133348948999924 21.215878331000056, -97.134105432999945 21.21509668300007, -97.134784993999915 21.214202472000068, -97.1353944299999 21.213227443000051, -97.1359409289999 21.212202590000061, -97.136431678999941 21.211158904000058, -97.136864979999928 21.210119244000055, -97.137205593999909 21.209075024000072, -97.137410569999929 21.208008018000044, -97.137435395999944 21.20690225900006, -97.137237530999926 21.205739890000075, -97.136772845999928 21.204503443000078, -97.135998025999925 21.203176186000064, -97.1348693459999 21.201740269000084, -97.133363107999912 21.200182847000065, -97.131534812999917 21.198502904000065, -97.129460772999948 21.19670405700009, -97.1272157009999 21.194789942000057, -97.124875489999908 21.192763442000057, -97.122515638999914 21.190628199000059, -97.120212029999948 21.18838710600005, -97.118039351999926 21.186044204000041, -97.1160555589999 21.183606343000065, -97.114247401999933 21.18109951200006, -97.112582907999922 21.17855252600009, -97.111030519999929 21.17599531500008, -97.109558666999931 21.173456680000072, -97.108136187999946 21.170966165000038, -97.1067307369999 21.168554072000063, -97.10531153699992 21.166248434000067, -97.10385539899994 21.164077576000068, -97.102374124999926 21.162060451000059, -97.100887873999909 21.160214047000068, -97.099417603999939 21.158556094000062, -97.09798345899992 21.157102836000035, -97.096605994999948 21.155872009000063, -97.095304964999912 21.15488098700007, -97.094101707999926 21.154146377000075, -97.093015557999934 21.153684061000035, -97.091258814999946 21.153612301000067)) "

 

I want to create shape file using this polygon field. i am done with finding the X,Y coordinate and then make a polygon. but it is very slow and time consumeing. my code is

 

public IGeometry CreatePolygon(DataSet ds, string ColumnName)

        {

            IPolygon polygon = null;

            IPolygon polygon2;

            ITopologicalOperator2 topologicalOperator2 = null;

 

            IPointCollection pPoly = new PolygonClass();

            IPointCollection pPoly2 = new PolygonClass();

            // IPolygon polygonCombined=null;

            int i = 0;

            foreach (DataRow row in ds.Tables[0].Rows)

            {

 

                string st = row[ColumnName].ToString();

                string[] arr = null;

                if (st.StartsWith("POLY"))

                {

                    string d = st.Substring(10);

                    d = d.Substring(0, d.Length - 2);

                    arr = d.Split(',');

                }

                else if (st.StartsWith("MULTI"))

                {

                    string d = st.Substring(16);

                    d = d.Substring(0, d.Length - 3);

                    arr = d.Split(',');

                }

 

                if (i == 0)

                {

                    IPoint[] pntArrayTemp = new IPoint[arr.Length];

                    int k = 0;

                    foreach (string st1 in arr)

                    {

                        pntArrayTemp[k] = new PointClass();

                        string[] temp1 = st1.Trim().Split(' ');

                        pntArrayTemp[k].X = Convert.ToDouble(temp1[0].Replace(")", "").Replace("(", "").Trim());

                        pntArrayTemp[k].Y = Convert.ToDouble(temp1[1].Replace(")", "").Replace("(", "").Trim());

                        object obj1 = Type.Missing;

                        pPoly.AddPoint(pntArrayTemp[k], ref obj1, ref obj1);

                        k++;

                    }

                    polygon = pPoly as IPolygon;

 

                }

 

                if (i > 0)

                {

 

                    pPoly2 = new PolygonClass();

 

                    IPoint[] pntArrayTemp1 = new IPoint[arr.Length];

                    int k = 0;

                    foreach (string st1 in arr)

                    {

                        pntArrayTemp1[k] = new PointClass();

                        string[] temp1 = st1.Trim().Split(' ');

                        pntArrayTemp1[k].X = Convert.ToDouble(temp1[0].Replace(")", "").Replace("(", "").Trim());

                        pntArrayTemp1[k].Y = Convert.ToDouble(temp1[1].Replace(")", "").Replace("(", "").Trim());

                        object obj1 = Type.Missing;

                        pPoly2.AddPoint(pntArrayTemp1[k], ref obj1, ref obj1);

                        k++;

                    }

                    topologicalOperator2 = (ITopologicalOperator2)polygon;

                    //Simplify.

                    topologicalOperator2.IsKnownSimple_2 = false;

                    topologicalOperator2.Simplify();

                    polygon2 = pPoly2 as IPolygon;

                    ITopologicalOperator2 topologicalOperator3 = (ITopologicalOperator2)polygon2;

                    //Simplify.

                    topologicalOperator3.IsKnownSimple_2 = false;

                    topologicalOperator3.Simplify();

                    IGeometry geometry = topologicalOperator2.Union(topologicalOperator3 as IPolygon);

                    polygon = (IPolygon)geometry;

                }

                i++;

            }

            return polygon;

        }

 

any other way to create shapefile for polygon using arcGis.

Outcomes