Skip to main content
Added language tag
Source Link
Hornbydd
  • 44.6k
  • 5
  • 42
  • 84

Look in to the "NearestFeature" method on IIndexQuery2.

You can use this to get the nearest water main feature to each building. I guess you would then somehow need to loop thru the vertices on each building to find which one is the closest distance to this feature, then build a new polyline using the vertices from the building and watermain as endpoints. The only time I have done this was using two point featureclasses, wish I could offer more than that off the top of my head.. :D

IFeatureCursor pDepthCursor = pDepthSoundings.Search(null, false);
IFeatureIndex2 pFtrInd = new FeatureIndexClass();
pFtrInd.FeatureClass = pDepthSoundings.FeatureClass;
pFtrInd.FeatureCursor = pDepthCursor;
pFtrInd.Index(null, pCombinedEnvelope);
IIndexQuery2 pIndQry = pFtrInd as IIndexQuery2;

int FtdID = 0;
double dDist2Ftr = 0;
pIndQry.NearestFeature(ppoint, out FtdID, out dDist2Ftr);

IFeature pCloseFeature = pDepthSoundings.FeatureClass.GetFeature(FtdID);
IFeatureCursor pDepthCursor = pDepthSoundings.Search(null, false);
IFeatureIndex2 pFtrInd = new FeatureIndexClass();
pFtrInd.FeatureClass = pDepthSoundings.FeatureClass;
pFtrInd.FeatureCursor = pDepthCursor;
pFtrInd.Index(null, pCombinedEnvelope);
IIndexQuery2 pIndQry = pFtrInd as IIndexQuery2;

int FtdID = 0;
double dDist2Ftr = 0;
pIndQry.NearestFeature(ppoint, out FtdID, out dDist2Ftr);

IFeature pCloseFeature = pDepthSoundings.FeatureClass.GetFeature(FtdID);

Look in to the "NearestFeature" method on IIndexQuery2.

You can use this to get the nearest water main feature to each building. I guess you would then somehow need to loop thru the vertices on each building to find which one is the closest distance to this feature, then build a new polyline using the vertices from the building and watermain as endpoints. The only time I have done this was using two point featureclasses, wish I could offer more than that off the top of my head.. :D

IFeatureCursor pDepthCursor = pDepthSoundings.Search(null, false);
IFeatureIndex2 pFtrInd = new FeatureIndexClass();
pFtrInd.FeatureClass = pDepthSoundings.FeatureClass;
pFtrInd.FeatureCursor = pDepthCursor;
pFtrInd.Index(null, pCombinedEnvelope);
IIndexQuery2 pIndQry = pFtrInd as IIndexQuery2;

int FtdID = 0;
double dDist2Ftr = 0;
pIndQry.NearestFeature(ppoint, out FtdID, out dDist2Ftr);

IFeature pCloseFeature = pDepthSoundings.FeatureClass.GetFeature(FtdID);

Look in to the "NearestFeature" method on IIndexQuery2.

You can use this to get the nearest water main feature to each building. I guess you would then somehow need to loop thru the vertices on each building to find which one is the closest distance to this feature, then build a new polyline using the vertices from the building and watermain as endpoints. The only time I have done this was using two point featureclasses, wish I could offer more than that off the top of my head.. :D

IFeatureCursor pDepthCursor = pDepthSoundings.Search(null, false);
IFeatureIndex2 pFtrInd = new FeatureIndexClass();
pFtrInd.FeatureClass = pDepthSoundings.FeatureClass;
pFtrInd.FeatureCursor = pDepthCursor;
pFtrInd.Index(null, pCombinedEnvelope);
IIndexQuery2 pIndQry = pFtrInd as IIndexQuery2;

int FtdID = 0;
double dDist2Ftr = 0;
pIndQry.NearestFeature(ppoint, out FtdID, out dDist2Ftr);

IFeature pCloseFeature = pDepthSoundings.FeatureClass.GetFeature(FtdID);
Source Link
ericoneal
  • 825
  • 4
  • 13

Look in to the "NearestFeature" method on IIndexQuery2.

You can use this to get the nearest water main feature to each building. I guess you would then somehow need to loop thru the vertices on each building to find which one is the closest distance to this feature, then build a new polyline using the vertices from the building and watermain as endpoints. The only time I have done this was using two point featureclasses, wish I could offer more than that off the top of my head.. :D

IFeatureCursor pDepthCursor = pDepthSoundings.Search(null, false);
IFeatureIndex2 pFtrInd = new FeatureIndexClass();
pFtrInd.FeatureClass = pDepthSoundings.FeatureClass;
pFtrInd.FeatureCursor = pDepthCursor;
pFtrInd.Index(null, pCombinedEnvelope);
IIndexQuery2 pIndQry = pFtrInd as IIndexQuery2;

int FtdID = 0;
double dDist2Ftr = 0;
pIndQry.NearestFeature(ppoint, out FtdID, out dDist2Ftr);

IFeature pCloseFeature = pDepthSoundings.FeatureClass.GetFeature(FtdID);