Info tool

Topics: General Topics
Mar 7, 2007 at 1:29 AM
Hi every body:

Some body knows how to do a info tool, this tool get all the data from all the objects on the map under a point.

I´m using this code but I don´t know how to get the data:

-------------------------------------------------------------------------------------------------------------------------
public string GetInfo(Map pmapMap, SharpMap.Geometries.Point ppntPoint)
{
string strResult="";
try
{
SharpMap.Layers.VectorLayer lyrMyLayer;
SharpMap.Data.FeatureDataSet fds = new SharpMap.Data.FeatureDataSet();
lyrMyLayer = (SharpMap.Layers.VectorLayer)pmapMap.Layers0;
lyrMyLayer.DataSource.Open();
SharpMap.Geometries.Point pntPoint2=new SharpMap.Geometries.Point(ppntPoint.X + 1,ppntPoint.Y + 1);
SharpMap.Geometries.BoundingBox bubBoundingBox = new SharpMap.Geometries.BoundingBox(ppntPoint, pntPoint2);
lyrMyLayer.DataSource.ExecuteIntersectionQuery(bubBoundingBox, fds);

if (fds.Tables.Count > 0)
{
strResult = fds.Tables0.Rows0.ItemArray.GetValue(0).ToString();
foreach (SharpMap.Data.FeatureDataRow feature in fds.Tables0)
{
strResult = feature0.ToString();
}
-----------------------------------------------------------------------------------------------------------

this sample raise me an error when i try to get the data from the objects.




Coordinator
Mar 13, 2007 at 11:42 PM
What type of Exception do you get? This would mean a lot in terms of what is going wrong. Just by looking at it, I wonder if you have an empty result set, so your fds.Tables0.Rows0.ItemArray is throwing a NullReferenceException.
Mar 14, 2007 at 12:15 AM
Hi:

Thanks by your help, but fortunally I founded my error, and now I have the next code for get all the atributes from a layer in a specific point.

There are two methods one search on the layer and the other get all the atributes from this layer and returns the data in to a array.



/// <summary>
/// This method get the info on only one layer under the point
/// </summary>
/// <param name="pmapMap">The map</param>
/// <param name="ppntPoint">The point under we are goig to try search</param>
/// <param name="intPositionLayer">The position of the layer in the map, zero is the initial position</param>
/// <param name="pdblFactor">The factor is the distance between the points 1 and 2 that form the bounding box</param>
/// <returns></returns>
private ArrayList GetInfoFeatures(Map pmapMap, SharpMap.Geometries.Point ppntPoint, int intPositionLayer, double pdblFactor)
{
ArrayList arlResult = new ArrayList();
try
{

SharpMap.Layers.VectorLayer lyrMyLayer = _LayerTools.getVectorLayer(pmapMap, intPositionLayer);//get the layer
SharpMap.Data.FeatureDataSet fds = new SharpMap.Data.FeatureDataSet();//Where the features will be stored
SharpMap.Geometries.Point pntPoint2 = new SharpMap.Geometries.Point(ppntPoint.X + pdblFactor, ppntPoint.Y + pdblFactor);//The second point in the square
SharpMap.Geometries.BoundingBox bubBoundingBox = new SharpMap.Geometries.BoundingBox(ppntPoint, pntPoint2);//Doing the area to search
lyrMyLayer.DataSource.ExecuteIntersectionQuery(bubBoundingBox, fds);//Seaching the features under the square
if (fds.Tables.Count > 0)//If al least one feature where founded
{
foreach (SharpMap.Data.FeatureDataRow feature in fds.Tables0)//Getting all the features
{

arlResult.Add(GetInfoFeature(feature)); //Getting all the data from one by one feature, the column name and the value
}
}
}
catch (Exception Ex)
{
return null;
}

return arlResult;
}


/// <summary>
/// This method return all the data of the feature, the column name and the value
/// </summary>
/// <param name="feature">The feature that was founded under the point</param>

/// <returns></returns>
private ArrayList GetInfoFeature(SharpMap.Data.FeatureDataRow feature)
{
ArrayList arlResult = new ArrayList();
try
{
foreach (System.Data.DataColumn ColColumn in feature.Table.Columns)
{
ArrayList arlDataColumn =new ArrayList();//A new array list
arlDataColumn.Add(ColColumn.ColumnName);//The column name
arlDataColumn.Add(featureColColumn.ColumnName.ToString()); //The value of the column
arlResult.Add(arlDataColumn); //The data of the column
}
return arlResult;//All the data of the feature

}
catch (Exception Ex)
{
return null;
}

return arlResult;
}