Quantcast
Channel: Question and Answer » arcmap
Viewing all articles
Browse latest Browse all 248

Spatial reference does not match data frame for Bing Maps

$
0
0

In ArcObjects I am loading Bing Maps as a base layer. It’s coordinate system is esriSRProjCS3Type.esriSRProjCS_WGS1984WebMercatorMajorAuxSphere. On top of the base layer, I am trying to load points, lines and polygons via SqlGeometry objects where geometric coordinate system is WGS1984 or esriSRGeoCSType.esriSRGeoCS_WGS1984.

I am converting SqlGeometry to ESRI’s IGeometry objects and set spatial reference to esriSRGeoCSType.esriSRGeoCS_WGS1984 specifically:

public static IGeometry Convert(SqlGeometry sqlGeometry) { 
  int count;
  IGeometry esriGeometry;
  var factory = (IGeometryFactory3) new GeometryEnvironment();
  factory.CreateGeometryFromWkbVariant(sqlGeometry.STAsBinary().Value, out esriGeometry, out count);
  esriGeometry.SpatialReference = spatialReferenceForGeoCS_WGS1984;
  return esriGeometry;
}

And I am following ESRI’s documentation to create a feature class and assign spatial reference to it (doc):

public IFeatureClass CreateFeatureClass(String featureClassName,
  IFeatureWorkspace featureWorkspace,
  ISpatialReference spatialReference)
{
  // Instantiate a feature class description to get the required fields.
  IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
  IObjectClassDescription ocDescription = (IObjectClassDescription)fcDescription;
  IFields fields = ocDescription.RequiredFields;

  // Find the shape field in the required fields and modify its GeometryDef to
  // use point geometry and to set the spatial reference.
  int shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName);
  IField field = fields.get_Field(shapeFieldIndex);
  IGeometryDef geometryDef = field.GeometryDef;
  IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
  geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
  geometryDefEdit.SpatialReference_2 = spatialReferenceForGeoCS_WGS1984;

  // Create the feature class.
  IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(featureClassName, fields,
    ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple,
    fcDescription.ShapeFieldName, "");
  return featureClass;
}

Still when I start editing session, I am getting “Spatial reference does not match data frame” error. Is there another artifact that needs spatial reference?


Viewing all articles
Browse latest Browse all 248

Trending Articles