You are here: > ESRI Forums > arcgis engine forums > Thread Replies

ArcGIS Engine Forums

ArcGIS Engine: Developer Kit forum

How can I get the location Name using lat/l...   prashant kapate May 12, 2009
Re: How can I get the location Name using l...   Reena Bhatt May 14, 2009
Re: How can I get the location Name using l...   prashant kapate May 14, 2009
Re: How can I get the location Name using l...   Reena Bhatt May 14, 2009
Re: How can I get the location Name using l...   prashant kapate May 14, 2009
Re: How can I get the location Name using l...   Reena Bhatt May 14, 2009
Re: How can I get the location Name using l...   prashant kapate May 14, 2009
Re: How can I get the location Name using l...   Reena Bhatt May 14, 2009
Re: How can I get the location Name using l...   prashant kapate May 14, 2009
Re: How can I get the location Name using l...   Reena Bhatt May 15, 2009
Re: How can I get the location Name using l...   prashant kapate May 15, 2009
Re: How can I get the location Name using l...   prashant kapate May 15, 2009
Re: How can I get the location Name using l...   Reena Bhatt May 15, 2009
Re: How can I get the location Name using l...   prashant kapate May 15, 2009
Re: How can I get the location Name using l...   Reena Bhatt May 15, 2009
Re: How can I get the location Name using l...   prashant kapate May 17, 2009
Re: How can I get the location Name using l...   Reena Bhatt May 17, 2009
Re: How can I get the location Name using l...   prashant kapate May 18, 2009
Re: How can I get the location Name using l...   Reena Bhatt May 19, 2009
Re: How can I get the location Name using l...   prashant kapate May 19, 2009
Re: How can I get the location Name using l...   Reena Bhatt May 19, 2009
Re: How can I get the location Name using l...   Reena Bhatt May 19, 2009
Re: How can I get the location Name using l...   prashant kapate May 19, 2009
Re: How can I get the location Name using l...   Reena Bhatt May 21, 2009
Re: How can I get the location Name using l...   prashant kapate May 22, 2009
Re: How can I get the location Name using l...   Reena Bhatt May 22, 2009
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject How can I get the location Name using lat/long 
Author prashant kapate 
Date May 12, 2009 
Message Hi,
I want to display the tooltip on map. For that I required the location details. I am able to get the latitude and longitude and not able to get the location name using that lat/long. Can you please give us your valuable thought. Please find the code below 
 
while(pRteFeature != NULL)
    {
      pRteFeature->get_Shape(&geometryPtr);

      if(geometryPtr != NULL)
      {
        pPointPtr = (IPointCollectionPtr)geometryPtr;
        pPointPtr->get_PointCount(&count);

        for(i = 0; i < count;i++)
        {
          pPointPtr->get_Point(i, &pointPtr);
          pointPtr->get_Y(&y);
          pointPtr->get_X(&x);          
          yMin.Add(y);
          xMin.Add(x);
          
        }
      }

      pFCursor->NextFeature(&pRteFeature);
    }
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author Reena Bhatt 
Date May 14, 2009 
Message Here's the code to either identify or show tooltip for point based on X,Y co-ordinates on Mapcontrol's mouse move or down event.

 
 
Set pMap = frmmap.MapControl1.Map
    Set pLayer = frmmap.MapControl1.Layer(0)
    Set pFLayer = pLayer
    Set pActiveView = frmmap.MapControl1.ActiveView
    Set pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y)
    pPoint.X = mapX
    pPoint.Y = mapY

    Set pIdentify = pLayer
    Set pTopologicalOperator = pPoint
    Set pGeometry = pTopologicalOperator.Buffer(MapControl1.Extent.Width / 200)
    Set pSpatialFilter = New SpatialFilter
    Set pSpatialFilter.Geometry = pGeometry
    pSpatialFilter.GeometryField = "Shape"
    pSpatialFilter.SpatialRel = esriSpatialRelIntersects
    Set pFClass = pFLayer.FeatureClass
    Set pFCursor = pFClass.Search(pSpatialFilter, True)
    Set pFeature = pFCursor.NextFeature

    frmmap.MapControl1.FlashShape pFeature.Shape, 2, 300
 
  ~Reena  
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author prashant kapate 
Date May 14, 2009 
Message Thanks for the update. But this is not solve my problem. My problem is I have the latitude and longitude and I want the location name using these latitude/longitude. Ex: Lat = 33 and Long = -77 using this lat/long I want to get the location name ex: NEWYORK City. Is there any API in ESRI 9.3 ArcGIS Engine should give me the location detail or description using the lat/long.

Sample:

locationName = GetLocation(Latitude,Longitude) 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author Reena Bhatt 
Date May 14, 2009 
Message If you want to get the location name from your layer's attribute then you can do it thru spatialfilter and queryfilter by passing your co-ordinates. 
  ~Reena  
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author prashant kapate 
Date May 14, 2009 
Message Can you give code sample using these API? 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author Reena Bhatt 
Date May 14, 2009 
Message Have you tried anything with code, can help you out. As the code I had is wht I have posted to U, and believe that should help you. 
  ~Reena  
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author prashant kapate 
Date May 14, 2009 
Message I didn't receive any code. I am working on vc++ and I didn't find any related API to get the location details. The API you specified is use for Web (spatialfilter and queryfilter) but I am using the ArcGIS Engine which don't have web API. Can you give me some VC++ sample for ArcGIS engine.? Thanks in Advance. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author Reena Bhatt 
Date May 14, 2009 
Message Am using ArcGIS Engine 9.2 and no web based products.

This code is in VB.
 
  ~Reena  
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author prashant kapate 
Date May 14, 2009 
Message Here I have the latitude and longitude and I want to get the location Name. Can you suggest some thought on this code?
while(pRteFeature != NULL)
{
pRteFeature->get_Shape(&geometryPtr);

if(geometryPtr != NULL)
{
pPointPtr = (IPointCollectionPtr)geometryPtr;
pPointPtr->get_PointCount(&count);

for(i = 0; i < count;i++)
{
pPointPtr->get_Point(i, &pointPtr);
pointPtr->get_Y(&y);
pointPtr->get_X(&x);
yMin.Add(y);
xMin.Add(x);

}
}

pFCursor->NextFeature(&pRteFeature);
}

 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author Reena Bhatt 
Date May 15, 2009 
Message Pretty simple I guess: You already have your lat-long. Now what you have to do first get your layer's position and set it to ILayer interface. Hope you know how to get that. That you can do by index property of Mapcontrol. Chk the code with comments to understand it better.

 
 
Set pMap = frmmap.MapControl1.Map

   'Once you retrive layer index set pLayer object of ILayer interface
    Set pLayer = frmmap.MapControl1.Layer(<layer index>)

    Set pFLayer = pLayer
    Set pActiveView = frmmap.MapControl1.ActiveView

    
    Set pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y)

    'Your lat - long i.e mapx and mapy can be passed here inplace of X and Y
    pPoint.X = mapX
    pPoint.Y = mapY

    'Here's the code to identify feature based on X & Y ( You can neglect this code)

    Set pIdentify = pLayer
    Set pTopologicalOperator = pPoint
    Set pGeometry = pTopologicalOperator.Buffer(MapControl1.Extent.Width / 200)
    Set pSpatialFilter = New SpatialFilter
    Set pSpatialFilter.Geometry = pGeometry
    pSpatialFilter.GeometryField = "Shape"
    pSpatialFilter.SpatialRel = esriSpatialRelIntersects
    Set pFClass = pFLayer.FeatureClass
    Set pFCursor = pFClass.Search(pSpatialFilter, True)
    Set pFeature = pFCursor.NextFeature

    'Feature flash option can be neglected in Your case

    frmmap.MapControl1.FlashShape pFeature.Shape, 2, 300

    'Setting the identify object using pPoint 

    Set pIDArray = pIdentify.Identify(pPoint)

    'If identified or clicked feature (in your case feature on mouse hover) is set to something then :

    If Not pIDArray Is Nothing Then

       'Set it to element index 0
      Set pFeatIdObj = pIDArray.Element(0)
      Set pIdObj = pFeatIdObj
      
      'Here you will get layer name
      Msgbox (pIdObj.Layer.Name)
      
      'Here you will get feature object name and in your case ur location name. Instead of messagebox you can set it to map tool tip 
      Msgbox (pIdObj.Name)

    End If	
 
  ~Reena  
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author prashant kapate 
Date May 15, 2009 
Message HI ,

Thanks you very much but still I didn't able to find the out location details. Please see the location details I am using. I have 2 location A and B with latitude/Longitude.

Loc A = 38.9504/-77.0864
Loc B = 38.8822/-77.0036

MY actual problem, i am getting lat/long from ESRI API and using the lat/long I want location or street name or street no.

In your code I did't understand what is MapControl1.

My main aim is to get location name or street name from ESRI API, after getting location name , Our MapControl automaticaly display this detail on Map. Right now we had hardcoded the location name.

When I am trying to get travel path on map using your recommended code I am getting only 3 name.

1) Edge 14219294 (SDC Edge Source)
2) Edge 14219296 (SDC Edge Source)
3) Edge 14219298 (SDC Edge Source)
Can you give me an Idea where is my code is wrong? or please tell me the way implement this code. 
 
INAResultPtr pNATraversalResult;                    //directions agent
    m_pNAContext->get_Result(&pNATraversalResult);
    INATraversalResultQueryPtr pNATraversalResultQuery;
    pNATraversalResultQuery = pNATraversalResult ;
    IFeatureClassPtr pTraversalFClass;
    pNATraversalResultQuery->get_FeatureClass(esriNETEdge,&pTraversalFClass);
    IFeatureCursorPtr pFCursor;
    IFeaturePtr pRteFeature;
    pTraversalFClass->Search(NULL,TRUE,&pFCursor);
    pFCursor->NextFeature(&pRteFeature);

    IGeometryPtr geometryPtr;
    double x, y;
    CDoubleArray xMin;
    CDoubleArray yMin;

    xMin.SetSize(0,100);
    yMin.SetSize(0,100);

    IPointPtr pointPtr;
    IPointCollectionPtr pPointPtr;

    while(pRteFeature != NULL)
    {
      pRteFeature->get_Shape(&geometryPtr);

      if(geometryPtr != NULL)
      {
        pPointPtr = (IPointCollectionPtr)geometryPtr;
        pPointPtr->get_PointCount(&count);

        for(i = 0; i < count;i++)
        {
          pPointPtr->get_Point(i, &pointPtr);
          pointPtr->get_Y(&y);
          pointPtr->get_X(&x);
           yMin.Add(y);
           xMin.Add(x);
          }
        }
      }

      pFCursor->NextFeature(&pRteFeature);
    }
    
    IIdentifyPtr pIdentify;
    IArrayPtr pIDArray ;
    IUnknownPtr  pItem;
    IIdentifyObjPtr pIdObj;
    ILayerPtr pLayer;
    INetworkLayerPtr pNetworkLayer(CLSID_NetworkLayer);
    pNetworkLayer->putref_NetworkDataset(m_pNetworkDataset);
    pLayer = pNetworkLayer;
    
    pIdentify = pLayer ;
    pIdentify->Identify(geometryPtr,&pIDArray);        
    if(pIDArray != NULL)
    {    
      long countArray;
      BSTR locationName;
      pIDArray->get_Count(&countArray);      
      for(i =0 ; i < countArray ; i++)
      {        
        pIDArray->get_Element(i,&pItem);      
        pIdObj = pItem ;
        pIdObj->get_Name(&locationName);
        AfxMessageBox(locationName);
      }            
    }
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author prashant kapate 
Date May 15, 2009 
Message Hi,

I have made some changes in the code but I am getting the location name as a edge details. Please find the update code. 
 
long i = 0;
    long count = 0;

    //edge details
    INAResultPtr pNATraversalResult;                    //directions agent
    m_pNAContext->get_Result(&pNATraversalResult);
    INATraversalResultQueryPtr pNATraversalResultQuery;
    pNATraversalResultQuery = pNATraversalResult ;
    IFeatureClassPtr pTraversalFClass;
    pNATraversalResultQuery->get_FeatureClass(esriNETEdge,&pTraversalFClass);
    IFeatureCursorPtr pFCursor;
    IFeaturePtr pRteFeature;
    pTraversalFClass->Search(NULL,TRUE,&pFCursor);
    pFCursor->NextFeature(&pRteFeature);

    IGeometryPtr geometryPtr;

    double x, y;

    CDoubleArray xMin;
    CDoubleArray yMin;

    xMin.SetSize(0,100);
    yMin.SetSize(0,100);

    IPointPtr pointPtr;
    IPointCollectionPtr pPointPtr;

    double lastx = 0;
    double lasty = 0;

    IIdentifyPtr pIdentify;
    IArrayPtr pIDArray ;
    IFeatureIdentifyObjPtr  FeatureIdentifyObjPtr ;
    IUnknownPtr  pItem;
    IIdentifyObjPtr pIdObj;
    ILayerPtr pLayer;
    INetworkLayerPtr pNetworkLayer(CLSID_NetworkLayer);
    pNetworkLayer->putref_NetworkDataset(m_pNetworkDataset);
    pLayer = pNetworkLayer;   
    pIdentify = pLayer ;    

    
    BSTR locationName;
    long pIDArrayCount;
    
    while(pRteFeature != NULL)
    {
      pRteFeature->get_Shape(&geometryPtr);                  
      if(geometryPtr != NULL)
      {
        pPointPtr = (IPointCollectionPtr)geometryPtr;
        pPointPtr->get_PointCount(&count);        
        for(i = 0; i < count;i++)
        {
          pPointPtr->get_Point(i, &pointPtr);
          pIdentify->Identify(pointPtr,&pIDArray);        
          pointPtr->get_Y(&y);
          pointPtr->get_X(&x);
          if(pIDArray != NULL)
          {
            pIDArray->get_Count(&pIDArrayCount);            
            pIDArray->get_Element(i,&pItem);      
            pIdObj = pItem ;            
            pIdObj->get_Name(&locationName); 
            AfxMessageBox(locationName);            
          }
          
          if (x != lastx || y != lasty)
          {
            yMin.Add(y);
            xMin.Add(x);
            lastx = x;
            lasty = y;
          }
        }
      }
      
      pFCursor->NextFeature(&pRteFeature);
    }
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author Reena Bhatt 
Date May 15, 2009 
Message What is Edge details? Are you not able to get attribute column index from where you actually want your location name. 
  ~Reena  
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author prashant kapate 
Date May 15, 2009 
Message I didn't have any idea about this. Can you give some idea . 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author Reena Bhatt 
Date May 15, 2009 
Message What are you adding to your Mapcontrol? Layer or Shapefile? And from whre you want your location name? 
  ~Reena  
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author prashant kapate 
Date May 17, 2009 
Message I am adding layer to MapControl. I want location name at below place.

for(i = 0; i < count;i++)
{
pPointPtr->get_Point(i, &pointPtr);
pIdentify->Identify(pointPtr,&pIDArray);
pointPtr->get_Y(&y);
pointPtr->get_X(&x);
// Here I want location Name using the point x and y
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author Reena Bhatt 
Date May 17, 2009 
Message Hi Prashant, first of all to get location name from you layer file , you need to identify the attribute column index. Lets say your layer is having following attribute columns :
1. LocationID (id of particular location)
2. Location Name (Name you want)

Now first of all you need to identify or find the field index using IField interface. And for that you need to know your field name ofcourse. If you know the index of field then you can directly get location name directly.

Now once you have X and Y , try the code I have already provided using ISpatialFilter and you will get your location name.

 
  ~Reena  
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author prashant kapate 
Date May 18, 2009 
Message I don't have the location name. I want to get the location name from ESRI API. I have make some changes as per your comments . Please give me your comments, How can I get the location Name. How can get location Name using spatialFilter, can you give me an example. 
 
for(i = 0; i < count;i++)
        {
          pPointPtr->get_Point(i, &pointPtr);          
          pointPtr->get_Y(&y);
          pointPtr->get_X(&x);
          pointPtr->PutCoords(x,y);             
          spatialFilter->putref_Geometry(pointPtr);              
          pTraversalFClass->get_ShapeFieldName(&shapeFieldName);
          spatialFilter->put_GeometryField(shapeFieldName);          
          spatialFilter->put_SpatialRel(esriSpatialRelIntersects);
          IFeatureCursorPtr featureCursor;
          pTraversalFClass->Search(spatialFilter, true,&featureCursor);    
          long fieldIndex;
          featureCursor->FindField(shapeFieldName,&fieldIndex);             
          IFieldsPtr fieldsPtr;
          featureCursor->get_Fields(&fieldsPtr);    
          fieldsPtr->get_FieldCount(&pIDArrayCount);
          for(long k = 0; k< pIDArrayCount ;k++)
          {
            IFieldPtr fieldPtr;
            fieldsPtr->get_Field(k,&fieldPtr);
            fieldPtr->get_Name(&locationName);
            AfxMessageBox(locationName);
          }
          if (x != lastx || y != lasty)
          {
            yMin.Add(y);
            xMin.Add(x);
            lastx = x;
            lasty = y;
          }
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author Reena Bhatt 
Date May 19, 2009 
Message Its getting bit confusing now. Can you just answer to some of the questions:

1. Are you adding Shapefile or Layer to your Mapcontrol? If not any then what ?

2. You said you dont have location name and want to add it. Also you said you need to show location name. So is it you want to add location name or just want to display it from somewhere ?



 
  ~Reena  
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author prashant kapate 
Date May 19, 2009 
Message Hi Reena, Thanks for the help.

I am using layer for MapControl.
I want to get location name from ESRI API using the lat/long. ex: locationName = GetLocationName(lat,long). Is there any such kind of API in ESRI who will give me location name using lat/long.

My problem is , I want to display the location name or street name or street no. on map. To display name, I need a name for that location using ESRI API. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author Reena Bhatt 
Date May 19, 2009 
Message Ok finally you are making it clear that your are adding Layer file to Mapcontrol.

Now let me tell you that with every layer file you would have attributes attached with it. For example if you are working in .NET platform then do following and you would know:

1. Create new project in .NET
2. Create new Mapcontrol1 Application
3. Here just add the Layer I have attached herewith to Mapcontrol1.
4. Now just run the application and you would be able to see the location names.

The location names you are seeing is coming from the attributes attached with Layer file. Each Layer has got attributes attached to it.

And what you are trying to do is display location name as Map tip when you move your mouse cursor on some point.

This point is one of the feature of your layer file. So it should have different attributes attached to it. Best way to identify them is to add your layer to Mapcontrol and just use "Identify" tool available with ArcGIS. When you will click on your point , it will show you attributes and thus the name for that particular location.

That is the index of your field from where you want to get Location Name, so just add that index in the code I have provided you earlier.

Now comes another scene, if you dont have such name in your attributes file then you need to insert them manually in your layer file. That also can be done but programatically.

Now just let me know what is the case with you. Sorry it got long enough but hope you will make out.



 
  ~Reena  
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author Reena Bhatt 
Date May 19, 2009 
Message Sorry attaching sample Layer here.
 
  ~Reena  
  Continents.lyr (opens in new window)
 
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author prashant kapate 
Date May 19, 2009 
Message Sorry again. But I am using VC++ and I already I have the 3rd party MapControl tool. I don't want to consider MapControl. I just want to get location name from ESRI. Our MapControl is automatically display the location name. I just need the location name and I will pass location name as parameter for MapControl and MapControl will display that name on Map. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author Reena Bhatt 
Date May 21, 2009 
Message If your third party Mapcontrol already displays location name that means your layer holds the name. So can move thru all fields and get it.
Again I dint got what you mean by "location name from ESRI". 
  ~Reena  
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author prashant kapate 
Date May 22, 2009 
Message To display the location name on map, we need that location name. I don't have the location name to display on map. I want to get that location name from ESRI. Just like ESRI giving me latitude/longitude, is there any such API in ESRI which will give me location name also. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How can I get the location Name using lat/long 
Author Reena Bhatt 
Date May 22, 2009 
Message No ESRI has no such API which will provide you location name just like it provides lat-long. But you said your thrid party Mapcontrol displays location name, where is that coming from? If you dont mind, can you post the layer file you are using just to check from my side? 
  ~Reena