Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Background:

  • Add-In for ArcGIS 10 Desktop via ArcObjects for .NET
  • The below code returns ALL features for the layer when the map is specified with any Geographic Coordinate System.
  • However, the below code works fine when the map is specified with a Projected Coordinate System. That is, returning a subset of the features within the radius.

//

IPoint viewPoint = new PointClass() as IPoint;      
// lon, lat here are WGS 84
viewPoint.PutCoords(lon, lat);  

// project input point to coordinate system of map  
ISpatialReferenceFactory srFactory = new SpatialReferenceEnvironmentClass();  
IGeographicCoordinateSystem pcs =
srFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);  

pcs.SetFalseOriginAndUnits(0.0, 0.0, 1000);
ISpatialReference srWgs84;
srWgs84 = pcs;
// if not WGS84 project it (omitting subroutine here..)
if (!CompareSpatialRefs(map.SpatialReference, srWgs84))
{
    //Geometry Interface to do actual project
    IGeometry geometry;
    geometry = viewerPoint;
    geometry.SpatialReference = srWgs84;
    geometry.Project(map.SpatialReference);
    viewPoint = geometry as IPoint;
}
else
    viewPoint.SpatialReference = srWgs84;

esriUnits distUnits = map.DistanceUnits;
// convert meters to map dist units (again, omitting subroutine..)
double bufferDist = ConvertToMapUnits(_myQueryRadiusInMeters, distUnits);
// using ITopoOp to generate a buffer
ITopologicalOperator topoOperator = (ITopologicalOperator)viewPoint;
IGeometry viewBuffer = topoOperator.Buffer(bufferDist);
IFeatureClass featureClass = myFeatureLayerInQuestion.FeatureClass;
IFeatureCursor featCursor = PerformSpatialQuery(featureClass, viewBuffer,
                                  esriSpatialRelEnum.esriSpatialRelIntersects, "");

...


// code straight from the ArcGIS Snippet Finder
public IFeatureCursor PerformSpatialQuery(IFeatureClass featureClass, IGeometry searchGeometry, esriSpatialRelEnum spatialRelation, string whereClause)
{
    if (featureClass == null)
        return null;
    // create a spatial query filter
    ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();

    // specify the geometry to query with
    spatialFilter.Geometry = searchGeometry;

    // specify what the geometry field is called on the Feature Class 
    // that we will be querying against
    System.String nameOfShapeField = featureClass.ShapeFieldName;
    spatialFilter.GeometryField = nameOfShapeField;

    // specify the type of spatial operation to use
    spatialFilter.SpatialRel = spatialRelation;

    // create the where statement
    spatialFilter.WhereClause = whereClause;

    // perform the query and use a cursor to hold the results
    IQueryFilter queryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
    queryFilter = (ESRI.ArcGIS.Geodatabase.IQueryFilter)spatialFilter;
    IFeatureCursor featureCursor = featureClass.Search(queryFilter, false);

    return featureCursor;
}

At this point, I iterate over the features in the featureCursor, calling featCursor.NextFeature(). Again any Projected Coordinate System, good. It appears for any Geographic Coordinate System, the cursor contains all the features for the layer.

Many thanks for any help!

EDIT: I believe I've figured out the issue. Please see my posted answer below.

share|improve this question
    
Could it have something to do with your false origin? –  Jim B Oct 20 '10 at 4:10
    
Quite possibly... Also playing with calling CreateProjectedCoordinateSystem() and projecting in that direction –  Josh Oct 20 '10 at 16:53
add comment

1 Answer

up vote 2 down vote accepted

It appears my omitted subroutine, ConvertToMapUnits, held the answer, as well as problematically using map.DistanceUnits as opposed to map.MapUnits.

Specifically, if the map is specified with a Geographic Coordinate System, convert selection radius in meters to decimal degrees:

// convert meters to map units - including a meters to decimal degrees conversion
// for the given latitude... 
esriUnits mapUnits = map.MapUnits;
// in this case 'buffDist' is now in dd
double buffDist = ConvertToMapUnits(myQueryRadiusInMeters, mapUnits, inputLat);
// using ITopoOp to generate a buffer
ITopologicalOperator topoOperator = (ITopologicalOperator)viewPoint;
IGeometry viewBuffer = topoOperator.Buffer(buffDist);

....

This seems like a classic mistake, but I hope it will prove helpful to others.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.