ThinkGeo.com    |     Documentation    |     Premium Support

GetFeaturesOverlapping

Hi ThinkGeo Team


I have managed to draw polygons based on the GPS coordinates collected using my GPS device. Now when I attempt to query to verify if the newly added polygon feature overlaps with the existing polygons, nothing appears although I am quite sure that the newly added polygon will overlap with the existing polygons. Below is part of my code that performs feature querying. Can you please correct me on that code?


 FeatureSourceColumn column = new FeatureSourceColumn("Temp", "string", 50);
            Collection<FeatureSourceColumn> columns = new Collection<FeatureSourceColumn>();
            columns.Add(column);

            InMemoryFeatureLayer inMemoryLayer = new InMemoryFeatureLayer(columns, new Collection<Feature>());

            GoogleOverlay google = new GoogleOverlay("Google Map");
            google.GoogleMapType = GoogleMapType.Normal;
            google.JavaScriptLibraryUri = new Uri(ConfigurationManager.AppSettings["GoogleUri"]);
            Map1.CustomOverlays.Add(google);           

            ManagedProj4Projection proj = new ManagedProj4Projection();
            proj.InternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(4326);
            proj.ExternalProjectionParameters = ManagedProj4Projection.GetGoogleMapParameters();
           
            inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.SymbolPen = new GeoPen(GeoColor.FromArgb(255, GeoColor.StandardColors.Green), 8);
            inMemoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            inMemoryLayer.FeatureSource.Projection = proj;


            double Latitude_Ring = 0;
            double Longitude_Ring = 0;


            Int64 PlotID = 0;
            Collection<Vertex> points_Feature = new Collection<Vertex>();

            Collection<Vertex> points = new Collection<Vertex>();

               // Looping through my data table for the existing features

                    for (int i = 0; i < rw.Length; i++)
                    {
                        double Latitude = double.Parse(rw[i]["Longitude"].ToString());
                        double Longitude = double.Parse(rw[i]["Latitude"].ToString());                   

                        Vertex vertex = new Vertex(Longitude, Latitude);
                        points.Add(vertex);
                    }


                    RingShape ring = new RingShape(points);
                    PolygonShape polygon = new PolygonShape(ring);

                    Feature feature_poly = new Feature(polygon);
                    feature_poly.ColumnValues.Add(key, "PolygonShape");
                    inMemoryLayer.InternalFeatures.Add(Polygon, feature_poly);


                    // Looping through my data table for the new feature

                    for (int i_plot = 0; i_plot < rw_plot.Length; i_plot++)
                    {
                       

                        Latitude_Ring = double.Parse(rw_plot[i_plot]["Longitude"].ToString());
                        Longitude_Ring = double.Parse(rw_plot[i_plot]["Latitude"].ToString());

                        Vertex vertex_Feature = new Vertex(Latitude_Ring, Longitude_Ring);
                        points_Feature.Add(vertex_Feature);
                    }

            RingShape ring_Feature = new RingShape(points_Feature);
            PolygonShape polygon_Feature = new PolygonShape(ring_Feature);

            Feature feature_Feature = new Feature(polygon_Feature);

          
            Collection<Feature> spatialQueryResults;
           
            inMemoryLayer.Open();
            spatialQueryResults = inMemoryLayer.QueryTools.GetFeaturesOverlapping(feature_Feature, new string[0]);

            InMemoryFeatureLayer spatialQueryResultLayer = new InMemoryFeatureLayer(columns, new Collection<Feature>());
            spatialQueryResultLayer.InternalFeatures.Clear();
            foreach (Feature feature in spatialQueryResults)
            {
                spatialQueryResultLayer.InternalFeatures.Add(feature.Id, feature);
            }



            TextStyle textStyle = new TextStyle("Temp", new GeoFont("Arial", 7), new GeoSolidBrush(GeoColor.SimpleColors.Red));
            spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = textStyle;

            spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.RoyalBlue);
            spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Blue;
            spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen = new GeoPen(GeoColor.FromArgb(200, GeoColor.StandardColors.Red), 5);
            spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.SymbolPen = new GeoPen(GeoColor.FromArgb(255, GeoColor.StandardColors.Green), 8);
            spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            LayerOverlay dynamicOverlay11 = new LayerOverlay();
            dynamicOverlay11.IsBaseOverlay = false;
            dynamicOverlay11.Name = "All Property";
            dynamicOverlay11.TileType = TileType.SingleTile;
            dynamicOverlay11.Layers.Add("DynamicLayer11", spatialQueryResultLayer);
            Map1.CustomOverlays.Add(dynamicOverlay11);

            Map1.CurrentExtent = inMemoryLayer.GetBoundingBox();

Best Regards,


Vincent.


 



Vincent, 
  
 Thanks for your code. 
  
 I read it and I think maybe the problem is projection. 
  
 Your "new feature" still under its original projection but your "existing features" under Google projection now. 
  
 Please try reprojection before did overlap query. 
  
 Regards, 
  
 Don

Hi Don


Thank you for the reply. I have discovered that, the query does not return anything. See the code snipet below.


Collection<Feature> spatialQueryResults;
           
            inMemoryLayer.Open();
            spatialQueryResults = inMemoryLayer.QueryTools.GetFeaturesOverlapping(feature_Feature, new string[0]);

            InMemoryFeatureLayer spatialQueryResultLayer = new InMemoryFeatureLayer(columns, new Collection<Feature>());
            spatialQueryResultLayer.InternalFeatures.Clear();
            foreach (Feature feature in spatialQueryResults)
            {
                spatialQueryResultLayer.InternalFeatures.Add(feature.Id, feature);
            }

I have overloaded this way, the method GetFeaturesOverlapping(Feature targetFeature, IEnumerable<string></string> returningColumnNames), whereby targetFeature is my newly added polygon. Is this way right? For more information, you can refer to my above posting with full code snipet


I have attached a file with set of coordinates for 4 polygons. Each set is identified by PlotID. The polygon out of the set of coordinates with PlotID = 16 has another polygon in it. Can you plot it and establish why the query returns null?


Best Regards,


Vincent



plots.txt (5.64 KB)

Hi ThinkGeo Team


To simplify the plotting of the above polygons, the polygon with coordinates set with PlotID = 14, is within the polygon with coordinates set PlotID = 16. Can you just plot the two sets and then perform the query mentioned above. I appreciate your help.


Best Regards,


Vincent



Hi ThinkGeo Team


Can you use the file attached here with the set of coordinates which a better arranged than the one above.


Best Regards,


Vincent



Plots2.txt (471 Bytes)

Vincent, 
  
 Please see my reply in ticket. 
  
 Regards, 
  
 Don