ThinkGeo.com    |     Documentation    |     Premium Support

Finding areaLayer,pointLayer and lineLayer separately

hi 





In my application I  want that when i click on button zoom to mumbai and then i click on map  it should not go back to world map,instead it should remain in mumbai  and also  i want to display info related to roads or landmarks whenever I  click on them,ie, I want to identify area layer,point layer and line  layer separately.how to do this??? 



Please help.Reply soon. 



Bhagyashree,


Thanks for your post.
 
I think following code snippet shows you how to identify the type of the shape file, please take a try against it.
 

ShapeFileType shapeFileType = shapeFileFeatureLayer.GetShapeFileType();
if (shapeFileType == ShapeFileType.Point || shapeFileType == ShapeFileType.Multipoint)
{
    //Point;
}
 
if (shapeFileType == ShapeFileType.Polyline)
{
     //line;
}
 
if (shapeFileType == ShapeFileType.Polygon)
{
         //area;
}

 
Any more questions please feel free to let me know.
 
Thanks.
 
Yale

Yale 
  
 I added this code,but I am getting error=:"The name ‘shapeFileFeatureLayer’ does not exist in the current context ". 
  
 Reply soon 
  
 Thanks

Yale


 


I have attached my code.I am not geeting how to add code for point , line and area.I want that whenevr I click on a point  information related to point stored in dbf files should be displayed.Similarly for area and line.


 


Please help.


Reply soon.


 


Thanks.



002_001_Mycode.txt (24.1 KB)

Bhagyashree,


I checked the attached code and found out why the point information cannot be displayed in your appliation, when you process the query operation for point shape layers you should use the following code:


 



Collection<Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesNearestTo(e.Position, GeographyUnit.Meter, 1, ReturningColumnsType.AllColumns);
The query operations are differents between the point shape layers and area/line shape layers, please use the code above for point shape layers again, if the point information still cannot display please let us know,


Thanks,


Scott,



hi


 


I have modified my code.In my code I am finding if the layer is arealayer,pointlayer or linelayer and displaying their respective information in gridview.But whenevr I click on pointlayer or linelayer it accepts it as arealayer and displays on arealayer related to information .I have attached my code.


 


Please reply soon.please........


 


Thanks


 


 



Mymodifiedcode.txt (28.2 KB)

Bhagyashree,


If still need to do some changes in your code for meeting your requirements exactly, you should change the judgement order for point shape, line shape and area shape. The point shape should be put the first, the line shape is the second and the area shape is the third. Here is the modified code below:


 



 foreach (Layer layer in Map1.DynamicOverlay.Layers)
            {
                layer.Open();
                {
                    Collection<Feature> selectedFeatures = ((FeatureLayer)layer).QueryTools.GetFeaturesNearestTo(e.Position,GeographyUnit.DecimalDegree,1,ReturningColumnsType.AllColumns);
                    foreach (Feature feature in selectedFeatures)
                    {
                        
                        BaseShape currentShape = feature.GetShape();
  if (currentShape is PointBaseShape)
                        {
                            if (currentShape.Contains(e.Position))
                            {
                                
                                Collection<Feature> selectedFeatures2 = ((FeatureLayer)layer).QueryTools.GetFeaturesNearestTo(e.Position, GeographyUnit.DecimalDegree, 1, ReturningColumnsType.AllColumns);
                                if (FeatureSelected.Count > 0)
                                {
                                    Collection<FeatureSourceColumn> columns = ((FeatureLayer)layer).QueryTools.GetColumns();
                                    DataTable table = new DataTable();
                                    foreach (FeatureSourceColumn column in columns)
                                    {
                                        table.Columns.Add(column.ColumnName);
                                    }

                                    foreach (Feature feature1 in selectedFeatures2)
                                    {
                                        DataRow row = table.NewRow();
                                        for (int i = 0; i < table.Columns.Count; i++)
                                        {
                                            row[i] = feature.ColumnValues[table.Columns[i].ColumnName];
                                        }
                                        table.Rows.Add(row);
                                    }
                                    this.FeaturesGridView.DataSource = table;
                                    this.FeaturesGridView.DataBind();
                                    break;
                                }
                            }
                        }
    else if (currentShape is LineBaseShape)
                        {
                            if (currentShape.Contains(e.Position))
                            {
                                
                                Collection<Feature> selectedFeatures3 = ((FeatureLayer)layer).QueryTools.GetFeaturesContaining(e.Position,  ReturningColumnsType.AllColumns);
                                if (FeatureSelected.Count > 0)
                                {
                                    Collection<FeatureSourceColumn> columns = ((FeatureLayer)layer).QueryTools.GetColumns();
                                    DataTable table = new DataTable();
                                    foreach (FeatureSourceColumn column in columns)
                                    {
                                        table.Columns.Add(column.ColumnName);
                                    }
                                    foreach (Feature feature1 in selectedFeatures3)
                                    {
                                        DataRow row = table.NewRow();
                                        for (int i = 0; i < table.Columns.Count; i++)
                                        {
                                            row[i] = feature.ColumnValues[table.Columns[i].ColumnName];
                                        }
                                        table.Rows.Add(row);
                                    }
                                    this.FeaturesGridView.DataSource = table;
                                    this.FeaturesGridView.DataBind();
                                    break;
                                }
                            }
                        }
                        else if (currentShape is AreaBaseShape)
                        {
                            if (currentShape.Contains(e.Position))
                            {
                                
                                Collection<Feature> selectedFeatures1 = ((FeatureLayer)layer).QueryTools.GetFeaturesContaining(e.Position, ReturningColumnsType.AllColumns);
                                if (FeatureSelected.Count > 0)
                                {
                                    Collection<FeatureSourceColumn> columns = ((FeatureLayer)layer).QueryTools.GetColumns();
                                    DataTable table = new DataTable();
                                    foreach (FeatureSourceColumn column in columns)
                                    {
                                        table.Columns.Add(column.ColumnName);
                                    }

                                    foreach (Feature feature1 in selectedFeatures1)
                                    {
                                        DataRow row = table.NewRow();
                                        for (int i = 0; i < table.Columns.Count; i++)
                                        {
                                            row[i] = feature.ColumnValues[table.Columns[i].ColumnName];
                                        }
                                        table.Rows.Add(row);
                                    }
                                    this.FeaturesGridView.DataSource = table;
                                    this.FeaturesGridView.DataBind();
                                    break;
                                }
                            }
                        }                     
                    }
                    layer.Close();
                }
Any more questions please let me know again,


Thanks,


Scott,



hi Scott 
  
 Thanks for your quick reply.I tried whatever you told me in your previous post,but still the problem is there.Only information related to arealayer is displayed whereever i click. 
  
 Please reply soon. 
  
 Thanks

Bhagyashree, 
  
 Please give us all of your shape files so that we can track the problem exactly, currently we just have your code and cannot find out the exact problem on your side, so if it is possible, please send all of your shape files to support@thinkgeo.com and we will check your problem as soon as possible. 
  
 Thanks, 
  
 Scott,

Hi 
  
 Scott 
  
 I have mailed my shapefiles to support@thinkgeo.com  as told by you.Please reply soon.Its urgent. 
  
 Thanks 
  
  


Bhagyashree, 
  
 Also I have another request, can you zip your whole sample solution to us that includes the .cs file and .aspx file, currently you just sent the code of .cs file to us, after we resolve it we will send the whole solution of the sample application to you so that you can run it directly and won’t need to do anything else. 
  
 Thanks, 
  
 Scott,

Hi Scott 
  
 I have mailed you.Please check it . 
  
 Please reply soon.its urgent. 
  
 Thanks 


Hi scott 
  
 Now new problem=;Whenever I click on any button or map …"Object reference not set to instance of an object"  error is occurring. 
  
 PLease make it fast.reply soon 
  
  
 Thanks

Hi  Scott 
  
  
 I hope you have got all that you wanted to solve my problem from the support team.Please  do it as early as possible…I am waiting… 
  
 Thanks

Bhagyashree,


The attachment is the sample what I changed for you, the general logic is that if the queried point features are not null we will return the first point feature and bind it to datagrid else we will query the line features and area features. For this application, I suggest you to add 3 datagrid to the page and they are for the point record, line record and area record sperately. Because when you click on the map, sometimes we will get point records, line records and area records together, currently you just display the result for point record and ignore the line and area records.


Also please copy the data to the App_Data folder, because the attachment limition issue in this forum I just attached the sample code for you,


Thanks,


Scott,



displaymap.zip (143 KB)

Hi Scott


 


 


Thanks for your solution.I tried it ,but the following error is occuring.As per your instruction I included 3 gridviews.


 


 



Server Error in '/' Application.


An item with the same key has already been added.


                             Description: An unhandled exception occurred during  the execution of the current web request. Please review the stack trace  for more information about the error and where it originated in the  code.              



 Exception Details: System.ArgumentException: An item with the same key has already been added.



Source Error: 




    
        
            
            
Line 309:                    layer.Open();
Line 310:                    ShapeFileType type = featureLayer.GetShapeFileType();
Line 311:                    Collection<Feature> nearestFeatures = featureLayer.QueryTools.GetFeaturesNearestTo(e.Position, GeographyUnit.DecimalDegree, 1, ReturningColumnsType.AllColumns);
Line 312:                    double radius = 10.0 / Map1.Width.Value * Map1.CurrentExtent.Width;
Line 313:                    EllipseShape searchingEllipse = new EllipseShape(e.Position, radius, radius);
            
        
    



 Source File:  C:\inetpub\wwwroot\displaymap\displaymap\Main.aspx.cs    Line:  311             



Stack Trace: 




    
        
            
            
[ArgumentException: An item with the same key has already been added.]
   System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +51
   System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +7528340
   ThinkGeo.MapSuite.Core.FeatureSource.GetColumnNamesInsideFeatureSource(IEnumerable`1 returningColumnNames) +415
   ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesNearestTo(BaseShape targetShape, GeographyUnit unitOfFeatureSource, Int32 numberOfItemsToFind, IEnumerable`1 returningColumnNames) +1150
   ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesNearestTo(BaseShape targetShape, GeographyUnit unitOfFeatureSource, Int32 numberOfItemsToFind, ReturningColumnsType returningColumnNamesType) +84
   ThinkGeo.MapSuite.Core.QueryTools.GetFeaturesNearestTo(BaseShape targetShape, GeographyUnit unitOfData, Int32 numberOfItemsToFind, ReturningColumnsType returningColumnNamesType) +218
   displaymap._Default.Map1_Click(Object sender, MapClickedEventArgs e) in C:\inetpub\wwwroot\displaymap\displaymap\Main.aspx.cs:311
   ThinkGeo.MapSuite.WebEdition.Map.OnClick(MapClickedEventArgs e) +78
   ThinkGeo.MapSuite.WebEdition.Map.xfb36c1f2a05b18e6(String[] x0e0b8dc2ebe82aa3) +125
   ThinkGeo.MapSuite.WebEdition.Map.x3296715cc7992de2(String x055cc4f8164153bb) +342
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

            
        
    





Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053              


 


 


Please reply soon.


 


Thanks


 



hi  
  scott 
  
 Thanks for your solution .I tried your solution, but the following error is occuring. 
  
  Server Error in ‘/’ Application. 
 An item with the same key has already been added. 
 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
 Exception Details: System.ArgumentException: An item with the same key has already been added. 
  
 Source Error: 
  
 Line 309:                    layer.Open(); 
 Line 310:                    ShapeFileType type = featureLayer.GetShapeFileType(); 
 Line 311:                    Collection<Feature> nearestFeatures = featureLayer.QueryTools.GetFeaturesNearestTo(e.Position, GeographyUnit.DecimalDegree, 1, ReturningColumnsType.AllColumns); 
 Line 312:                    double radius = 10.0 / Map1.Width.Value * Map1.CurrentExtent.Width; 
 Line 313:                    EllipseShape searchingEllipse = new EllipseShape(e.Position, radius, radius); 
  
  
 Source File: C:\inetpub\wwwroot\displaymap\displaymap\Main.aspx.cs    Line: 311 
  
 Stack Trace: 
  
 [ArgumentException: An item with the same key has already been added.] 
    System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +51 
    System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +7528340 
    ThinkGeo.MapSuite.Core.FeatureSource.GetColumnNamesInsideFeatureSource(IEnumerable`1 returningColumnNames) +415 
    ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesNearestTo(BaseShape targetShape, GeographyUnit unitOfFeatureSource, Int32 numberOfItemsToFind, IEnumerable`1 returningColumnNames) +1150 
    ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesNearestTo(BaseShape targetShape, GeographyUnit unitOfFeatureSource, Int32 numberOfItemsToFind, ReturningColumnsType returningColumnNamesType) +84 
    ThinkGeo.MapSuite.Core.QueryTools.GetFeaturesNearestTo(BaseShape targetShape, GeographyUnit unitOfData, Int32 numberOfItemsToFind, ReturningColumnsType returningColumnNamesType) +218 
    displaymap._Default.Map1_Click(Object sender, MapClickedEventArgs e) in C:\inetpub\wwwroot\displaymap\displaymap\Main.aspx.cs:311 
    ThinkGeo.MapSuite.WebEdition.Map.OnClick(MapClickedEventArgs e) +78 
    ThinkGeo.MapSuite.WebEdition.Map.xfb36c1f2a05b18e6(String[] x0e0b8dc2ebe82aa3) +125 
    ThinkGeo.MapSuite.WebEdition.Map.x3296715cc7992de2(String x055cc4f8164153bb) +342 
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565 
  
  
 Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053 
 
  
  
  
  
 Please help.Please reply soon. 
  
 Thanks

Bhagyashree, 
  
 As so far, we talked about your solution, but we didn’t find out any bugs or errors for our map control, that is determined by your own logic, I’m sorry we cannot provide the further support on this point. If you would like to do your own requirements exactly and need our helps please contact Professional Service team of ThinkGeo, 
  
 Thanks, 
  
 Scott,