felix_arnet

Querying Co-ordinates from geometries in ArcObjects

Blog Post created by felix_arnet on Sep 9, 2015

If you need the x,y (and z) co-ordinates of polyline, polygon or multipoints vertices for some reason, there are a lot of possibilities to get them.

 

The most self explaining way probably is

 

 

IPointCollection points = (IPointCollection)geom;

 

for (int i = 0; i < points.PointCount; i++)

{

  IPoint p = points.get_Point(i);

  double x = p.X;

  double y = p.Y;

}

 

However, this is also the slowest method. A bit faster it gets, when you use

 

 

double x, y;

p.QueryCoords(out x, out y);

 

 

instead of getting x and y separatly.

 

Some improvement can be achieved by using

 

   points.QueryPoint(i, queryPoint);

 

instead of points.get_Point(i); or

 

IEnumVertex enumPoints = points.EnumVertices;

 

instead of the for-Loop.

But the biggest improvement (of a factor 5 or more) you get, when you query the data as WKSPoints:

 

IPointCollection4 points = (IPointCollection4)geom;

for (int i = 0; i < points.PointCount; i++)

{

  WKSPointZ p;

  points.QueryWKSPointZs(i, 1, out p);

  double x = p.X;

  double y = p.Y;

}

 

Note, that IGeometryBridge is recommended to get WKSPointZ in .net-Environment, but of the upper code works and has virtually the same performace. Moreover, i had problems with IGeometryBridge, when i tried the code in 64-bit Environment (ArcGIS 10.2).

Outcomes