Select to view content in your preferred language

Table.Extent value is wrong when geometry type is polygon

4209
8
Jump to solution
02-24-2013 10:45 PM
MaoEdgar
Emerging Contributor
Hi,

I can't get the right extent of a table after inserting row into it, attached is the sample, I'm using the 1.2.0.136 version, can anyone tell me where goes wrong?

Thanks,
Edgar
0 Kudos
1 Solution

Accepted Solutions
VinceAngelo
Esri Esteemed Contributor
The C++ sample code shows a step you did not perform -- invoking CalculateExtent()
before SetGeometry.  That seems to correlate to improper envelope maintenance.

- V

View solution in original post

0 Kudos
8 Replies
VinceAngelo
Esri Esteemed Contributor
Please download and use the 1.3 API.

Please provide your code in a CODE block.

- V
0 Kudos
MaoEdgar
Emerging Contributor
Here is my code, still the same result with 1.3 API

            Geodatabase geodatabase = Geodatabase.Create("b.gdb");
            string template = File.ReadAllText("../../template.xml");
            string tableDef = template.Replace("%Name%", "myTable").Replace("%ShapeType%", "esriGeometryPolygon");

            Table table = geodatabase.CreateTable(tableDef);
            string fieldTemplate = File.ReadAllText("../../fieldTemplate.xml");
            table.AddField(fieldTemplate.Replace("%Name%", "polygonField"));

            MultiPartShapeBuffer polygonShapeBuffer = new MultiPartShapeBuffer();
            int polygonPartCount = 1;
            int polygonPointCount = 5;
            int[] parts = new int[polygonPartCount];
            parts[0] = 0;

            List<Point> points = new List<Point>();
            points.Add(new Point(0, 0));
            points.Add(new Point(10, 0));
            points.Add(new Point(10, 10));
            points.Add(new Point(0, 10));
            points.Add(new Point(0, 0));

            polygonShapeBuffer.Setup(ShapeType.Polygon, polygonPartCount, polygonPointCount);
            polygonShapeBuffer.Parts = parts;
            polygonShapeBuffer.Points = points.ToArray();

            Row row = table.CreateRowObject();
            row.SetGeometry(polygonShapeBuffer);
            //NaN
            Console.WriteLine(string.Format("xMax:{0} yMax:{1} xMin:{2} yMin:{3}", table.Extent.xMax, table.Extent.yMax, table.Extent.xMin, table.Extent.yMin));
            table.Insert(row);
            //0
            Console.WriteLine(string.Format("xMax:{0} yMax:{1} xMin:{2} yMin:{3}", table.Extent.xMax, table.Extent.yMax, table.Extent.xMin, table.Extent.yMin));
            Console.Read();
0 Kudos
VinceAngelo
Esri Esteemed Contributor
And what does the original XML say the extent should be? 

- V
0 Kudos
MaoEdgar
Emerging Contributor
As you can see, the extent before I insert the polygon is NaN, then I insert a polygon((0 0, 10 0, 10 10, 0 10, 0 0)), so the extent should be changed to xMax:10 xMin:0 yMax:10 yMin:0, but it doesn't, it's 0.  If I use the xml from the FGDB sample, the extent is right,so I think there might be something wrong with my template, could you please have a look at that? The template is in the zip file in my first post.

Thanks,
Edgar
0 Kudos
VinceAngelo
Esri Esteemed Contributor
I'm not the best person to review your XML, but you could help your cause if you post it
as a singleton file.

- V
0 Kudos
MaoEdgar
Emerging Contributor
Alright, I found another way to recreate the problem, attached is the xml file I tested, you can download it if you needed, the code is below,

            Geodatabase geodatabase = Geodatabase.Create("../../TableSchemaDemo.gdb");
            string featureClassDef = "";
            using (StreamReader sr = new StreamReader("../../Streets.xml"))
            {
                while (sr.Peek() >= 0)
                {
                    featureClassDef += sr.ReadLine() + "\n";
                }
                sr.Close();
            }
            Table streetsTable = geodatabase.CreateTable(featureClassDef, "");

            Row row = streetsTable.CreateRowObject();

            MultiPartShapeBuffer line = new MultiPartShapeBuffer();
            line.Setup(ShapeType.Polyline, 1, 3);
            line.Parts = new int[] { 0 };

            Point[] points = new Point[3];
            points[0] = new Point(0, 0);
            points[1] = new Point(10, 0);
            points[2] = new Point(10, 10);
            line.Points = points;

            row.SetGeometry(line);
            streetsTable.Insert(row);

            //this two ways cannot query anything.
            RowCollection rows = streetsTable.Search("*", "", streetsTable.Extent, RowInstance.Recycle);
            //RowCollection rows = streetsTable.Search("*", "", new Envelope(9, 5, 11, 7), RowInstance.Recycle);

            //this way it returns one record. 
            //RowCollection rows = streetsTable.Search("*", "", new Envelope(-1, -1, 11, 11), RowInstance.Recycle);
            foreach (Row item in rows)
            {
                Console.WriteLine("Has row");
            }


The Streets.xml is from the sample "\FileGDB_API_VS2010_1_3\samples\TableSchema\Streets.xml" and I haven't change anything, as you can see in the code I added a line into the table, and I want to query it by the table.Extent but failed, and then I changed the Envelope to (9, 5, 11, 7) which intersects the line, failed again, then I changed the Envelope to (-1, -1, 11, 11) which contains the line, it succeeded, so is there any way to query a record which is intersecting the specified Envelope?

Thanks,
Edgar
0 Kudos
VinceAngelo
Esri Esteemed Contributor
The C++ sample code shows a step you did not perform -- invoking CalculateExtent()
before SetGeometry.  That seems to correlate to improper envelope maintenance.

- V
0 Kudos
MaoEdgar
Emerging Contributor
Thank you, it's working fine now.
0 Kudos