How to iterate and retrieve geometry values from dataset?

Topics: Data Access, SharpMap Project, SharpMap v2.0
Dec 19, 2008 at 3:31 PM

Hi, 

I am trying to iterate through table and retrieve all the data it contains.

The following code allows me to retrieve non-geometry columns. What changes do i need to do in my code in order to retrieve also geometry out of the table?

IFeatureProvider provider = ....

IExtents extent = provider.GetExtents();
FeatureQueryExpression query = FeatureQueryExpression.Intersects(extent);
var layer = new GeometryLayer(provider);
IEnumerable<FeatureDataRow> features = layer.Select(query);
IEnumerator<FeatureDataRow> enumerator = features.GetEnumerator();

while (enumerator.MoveNext()) {
FeatureDataRow dataRow = enumerator.Current;
for (int i = 0; i < dataRow.Table.Columns.Count; i++) {
Console.Write(dataRow[i].ToString() + " " );
}
Console.WriteLine();
}

Thanks.

Coordinator
Dec 19, 2008 at 4:09 PM
Hi slaks, each FeatureDataRow has a geometry property so your code would be:
while (enumerator.MoveNext()) {

FeatureDataRow dataRow = enumerator.Current;

for (int i = 0; i < dataRow.Table.Columns.Count; i++)

{

Console.Write(dataRow[i].ToString() + " " );

}

Console.WriteLine(dataRow.Geometry.ToString()); // or dataRow.Geometry.AsText()

}


hth
FObermaier