Is there a way to get the longitude and latitude coordinates from a feature class? I have some code which can select the first layer in the Table of Contents. I want to be able to get the lat./long. of a feature in that layer (any lat./long. within the Data Frame's current extent will do).
With a point file I can see this being pretty straightforward (using the IPoint interface), but how would I go about do this with a polygon?
(Bonus points to anyone who can tell me if I can get the lat./long. using a FactoryCode!)
Here's my code thus far:
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pTargetFL As IFeatureLayer
Dim pTargetGD As IGeoDataset
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap
Set pTargetFL = pMap.Layer(0) 'Set the IFeatureLayer as the first layer in the TOC
Set pTargetGD = pTargetFL.FeatureClass
Dim pTargetSR As ISpatialReference
Dim pGeoDatasetEdit As IGeoDatasetSchemaEdit
Dim pSpatRefFact As ISpatialReferenceFactory
Dim pProjCoordSys As IProjectedCoordinateSystem
Set pTargetSR = pTargetGD.SpatialReference 'Set the spatial reference object
Dim fatCode As Integer
fatCode = pTargetSR.FactoryCode
MsgBox ("Layer Name: " & pTargetFL.Name & vbNewLine & "Layer Projection: " & pTargetSR.Name & vbNewLine & "Factory Code: " & fatCode)
-
2If you want to get the coordinates in a different SR, you'll have to call ProjectEx.mkennedy– mkennedy2013年08月23日 18:27:50 +00:00Commented Aug 23, 2013 at 18:27
1 Answer 1
Search the feature class, get a FeatureCursor, the loop through the FeatureCursor, look at the .Shape property, cast it into an IPolygon, then you could cast the IPolygon into an IPointCollection, loop through the points and get each one's coordinates.