| Message |
Thanks for your help. I noticed an error in the coding, and tried that. The feature cursor contains no data, just empty fields. I'm going to try the ITopologicalOperator Simplfy on the geometry object to see if that corrects this, I can't believe it's not working. I wonder if it has something to do with the fact that the polygon passed to the SpatialFilter resides in a different layer than the layer the SpatialFilter is run against? Or possibly the server context? I've checked that the source polygon has valid attributes (only problem I see is it has no Z attribute, but its only 2 dimmensional - when I view the IGeometry object in debug mode, it indicates that Envelope.Depth threw an exception - that the geometry is not Z-Aware - but this exception is not raised in the program), that I'm query the right layers, etc. |
| |
private void GetDistressData(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapctrl, ESRI.ArcGIS.Geometry.IGeometry mappoly)
{
MapFunctionality mapfunc = (MapFunctionality)mapctrl.GetFunctionality(2);//Distress Layer
MapResourceLocal mapres = (MapResourceLocal)mapfunc.MapResource;
IServerContext sc = mapres.ServerContextInfo.ServerContext;
IMapServer map = mapres.MapServer;
IMapServerObjects mapobj = (IMapServerObjects)map;
IMap fgmap = mapobj.get_Map(map.DefaultMapName);
IFeatureLayer fl = (IFeatureLayer)fgmap.get_Layer(2);//Distress Polygon Layer
IFeatureClass fc = fl.FeatureClass;
//ISpatialReference ir = (ESRI.ArcGIS.Geometry.ISpatialReference)fgmap.SpatialReference;
ESRI.ArcGIS.Geodatabase.IFeatureCursor fcursor = SpatialQuery(fc, mappoly,
ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelContains, "1=1");
//Create a datatable to hold the results:
System.Data.DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("SEVERITY");
dt.Columns.Add("STRTYPE");
dt.Columns.Add("DATEINSP");
dt.Columns.Add("INSPECTR");
dt.Columns.Add("COMMENT");
//end data table definition
IFeature pFeature;
while ((pFeature = fcursor.NextFeature()) != null)
{
//int id = pFeature.Fields.FindField("STRTYPE");
//string sID = pFeature.get_Value(id).ToString();
string iID = pFeature.get_Value(pFeature.Fields.FindField("ID")).ToString();
string Severity = pFeature.get_Value(pFeature.Fields.FindField("SEVERITY")).ToString();
string sType = pFeature.get_Value(pFeature.Fields.FindField("STRTYPE")).ToString();
string sDate = pFeature.get_Value(pFeature.Fields.FindField("DATEINSP")).ToString();
string sInspector = pFeature.get_Value(pFeature.Fields.FindField("INSPECTR")).ToString();
string sComment = pFeature.get_Value(pFeature.Fields.FindField("COMMENT")).ToString();
dt.Rows.Add(iID,Severity,sType,sDate,sInspector,sComment);
}
int iomg = dt.Rows.Count;
//-----------------------------------------------------------------
if (dt.Rows.Count > 0)
{
string returnstring = null;
GridView gvPoly = (GridView)mapctrl.Page.FindControl("gvPoly");
gvPoly.DataSource = dt;
gvPoly.DataBind();
gvPoly.Visible = true;
using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvPoly.RenderControl(htw);
htw.Flush();
returnstring = returnstring + sw.ToString();
}
CallbackResult cr = new CallbackResult("div", "griddiv", "innercontent", returnstring);
mapctrl.CallbackResults.Add(cr);
}
}
private ESRI.ArcGIS.Geodatabase.IFeatureCursor SpatialQuery(ESRI.ArcGIS.Geodatabase.IFeatureClass fc,
ESRI.ArcGIS.Geometry.IGeometry geo, ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum se,
string WhereClause)
{
ESRI.ArcGIS.Geodatabase.ISpatialFilter sf = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
//ESRI.ArcGIS.Geometry.IEnvelope env = geo.Envelope;
sf.Geometry = geo;
string nameOfShapeField = fc.ShapeFieldName;
sf.GeometryField = nameOfShapeField;
sf.SpatialRel = se;
//sf.SpatialRelDescription = "T**TF****";
sf.WhereClause = WhereClause;
//Line below is from sample code, except it returns all data, without filtering
//by polygon dimmensions:
ESRI.ArcGIS.Geodatabase.IQueryFilter qf = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
qf = (ESRI.ArcGIS.Geodatabase.IQueryFilter)sf;
ESRI.ArcGIS.Geodatabase.IFeatureCursor featcr;
featcr = fc.Search(sf,false);
return featcr;
} |