1

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)
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Aug 23, 2013 at 18:23
1
  • 2
    If you want to get the coordinates in a different SR, you'll have to call ProjectEx. Commented Aug 23, 2013 at 18:27

1 Answer 1

2

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.

answered Aug 23, 2013 at 18:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.