fmoisan

Get envelope point shapefile or geodatabase in vba (macro)

Discussion created by fmoisan on Jan 20, 2011
Latest reply on Jan 20, 2011 by fmoisan
Hi group!

I have a vba macro that get the selected layer in the toc and return the bounds (min max for X and Y) of that layer.  But it does not work with point layer...
How can I do that with point layer?

there goes the macro :

Sub Extent()

    Dim pDoc As IMxDocument
    Dim pmap As IMap
    Set pDoc = ThisDocument
    Set pmap = pDoc.FocusMap
    Dim pFLayer As IFeatureLayer
    Dim pDataset As IDataset
    Dim pGeoDataset As IGeoDataset
    Dim pEnv As IEnvelope
   
    Dim pSpatRefFact As ISpatialReferenceFactory
    Set pSpatRefFact = New SpatialReferenceEnvironment
   
    Dim pGeoCoordSys As IGeographicCoordinateSystem
    Set pGeoCoordSys = pSpatRefFact.CreateGeographicCoordinateSystem(esriSRGeoCS_WGS1984)
    Dim pSR As ISpatialReference
    Set pSR = pGeoCoordSys
   
    Set pFLayer = pDoc.SelectedItem
   
    Set pEnv = pFLayer.AreaOfInterest
        Set pGeoDataset = pFLayer.FeatureClass
        Set pEnv.SpatialReference = pGeoDataset.SpatialReference
        pEnv.Project pSR
       Debug.Print pFLayer.Name & ": MaxX = " & Format(pEnv.XMax, "##0.00")
       Debug.Print pFLayer.Name '& ": MaxY = " & Format(pEnv.YMax, "##0.00")
       Debug.Print pFLayer.Name & ": MinX = " & Format(pEnv.XMin, "##0.00")
       Debug.Print pFLayer.Name '& ": MinY = " & Format(pEnv.YMin, "##0.00")

End Sub


The source of the script : http://forums.esri.com/Thread.asp?c=93&f=992&t=208395
Thank you!

Outcomes