Get The Extent of Underlying Data of a Layer

304
4
Jump to solution
10-30-2013 12:34 AM
SusannSchmidt
New Contributor III
Hello,

In ArcMap I have a SpatialReference EPSG 32633 of the Dataframe and a Layer(Shape) loaded with EPSG 31494. Now I want to get the Extent of the original underlying Data. So I take my Layer as IGeoDataset:

ESRI.ArcGIS.Geometry.ISpatialReference spatialReference = (pLayer as IGeoDataset).SpatialReference; ESRI.ArcGIS.Geometry.IEnvelope envelope =  (pLayer as IGeoDataset).Extent;


The SpatialReference is 31494, but the Extent shows me the Coordinates in EPSG 32633.

In the Properties-Dialog of the Layer the Extent shows the Coordinates in 31494. How can I get these Coordinates?

Thanks for any idea.
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Regular Contributor III
No, your code is incorrect:

(pLayer as IGeoDataset).SpatialReference;

You are performing a QI from ILayer to IGeoDataset.  Calling the SpatialReference property here returns the spatial reference of the layer because that's what object you're working with.

In order to get the spatial reference of the data source, you need to access the data source (not the layer):

IFeatureLayer featureLayer = yourLayer;
IGeoDataset geoDataset = featureLayer.FeatureClass as IGeoDataset;

View solution in original post

0 Kudos
4 Replies
NeilClemmons
Regular Contributor III
The spatial reference of a feature layer in the map and the spatial reference of that layer's data source are not necessarily the same.  To get the spatial reference of the data source you need to access the data source itself.  You can get a reference to a feature layer's data source via IFeatureLayer.FeatureClass.
0 Kudos
SusannSchmidt
New Contributor III
Dear Neil, thank you for watching my problem.
I knew that the Spatial References of the Map and the Layer are not the same, this is just the reason of my question. I access the correct SpatialReference (this from the Shape) over the Interface IGeoDataset, which should show me the underlying Datasource. But the member 'Extent' of the IGeoDataset doesn't show it in the right Spat.Ref. Could this be a bug? In an older Forum-Discussion is shown also the way over the IGeoDataset. I searched the FeatureClass and the FeatureClass.FeatureDataset but can't find an envelope there.
0 Kudos
NeilClemmons
Regular Contributor III
No, your code is incorrect:

(pLayer as IGeoDataset).SpatialReference;

You are performing a QI from ILayer to IGeoDataset.  Calling the SpatialReference property here returns the spatial reference of the layer because that's what object you're working with.

In order to get the spatial reference of the data source, you need to access the data source (not the layer):

IFeatureLayer featureLayer = yourLayer;
IGeoDataset geoDataset = featureLayer.FeatureClass as IGeoDataset;

View solution in original post

0 Kudos
SusannSchmidt
New Contributor III
That's it! Thank you so much for your help.
0 Kudos