ThinkGeo.com    |     Documentation    |     Premium Support

InMemoryLayer with GeometryCollection does not support GetNearest?

Guys,


When I call layer.QueryTools.GetNearestTo() on an InMemoryFeatureLayer that has GeometryCollectionShaped features, I get an exception indicating that "Currently DecimalDegree is not supported."


I need this badly.   Is there some sort of workaround?


I am using version 5.5.38.0.


TIA


Klaus



Klaus, 
  
   Can you give us more info on your case? Can you give a sample code and actually a little sample would be ideal? That way will will know in what circumstances that exception gets raised and how to handle it. Thank you.

Val, I created a support ticket for this.  Basically, create an InMemoryFeatureLayer and add features with geometries of GeometryCollectionShape. Then call a layer.QueryTools.GetNearest on this layer and you will get an exception.   
  
 Thanks again.

Klaus,


  I talked to the Development Team regarding your situation and the recommendation is to not use GeometryCollectionShape for a Feature but instead to create a different feature for each shape as you can see in the code below. In the function Post10111 this is how you are creating the feature. In Post10111_Fix, this is how I recommend you create the features and the quetools qill work fine.


  From what I understood from the Development Team, they created GeometryCollectionShape to be in compliance with the geometry library JTS that we use for our geometric functions. But this has not been thouroughly tested for other functions such as the query tools. This is why I recommend you create features as you see in Post10111_Fix. Thank you.



public void LoadPost10111()
    {
        wpfMap1.MapUnit = GeographyUnit.DecimalDegree;
        wpfMap1.CurrentExtent = new RectangleShape(25, 75, 75, 25);
        wpfMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.StandardColors.White);

        InMemoryFeatureLayer inMemoryLayer = new InMemoryFeatureLayer();
        PolygonShape polygon = new PolygonShape("POLYGON((10 60,40 70,30 85, 10 60))");
        LineShape line = new LineShape("LINESTRING(60 60, 70 70,75 60, 80 70, 85 60,95 80)");
        Feature feature = new Feature(new GeometryCollectionShape(new BaseShape[] { line, polygon }));

        inMemoryLayer.InternalFeatures.Add(feature);
        inMemoryLayer.Open();
        inMemoryLayer.Columns.Add(new FeatureSourceColumn("test"));
        inMemoryLayer.Close();

        inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.RoyalBlue);
        inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Blue;
        inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen = new GeoPen(GeoColor.FromArgb(200, GeoColor.StandardColors.Red), 5);
        inMemoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        LayerOverlay staticOverlay = new LayerOverlay();
        staticOverlay.Layers.Add("InMemoryFeatureLayer", inMemoryLayer);
        wpfMap1.Overlays.Add("InMemoryOverlay", staticOverlay);

        //Exception occurs
        inMemoryLayer.Open();
        Collection<Feature> features = inMemoryLayer.QueryTools.GetFeaturesNearestTo(new PointShape(35, 40), GeographyUnit.DecimalDegree, 1, ReturningColumnsType.NoColumns);
        inMemoryLayer.Close();

        wpfMap1.Refresh();
    }

    public void Post10111_Fix()
    {
        wpfMap1.MapUnit = GeographyUnit.DecimalDegree;
        wpfMap1.CurrentExtent = new RectangleShape(25, 75, 75, 25);
        wpfMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.StandardColors.White);

        InMemoryFeatureLayer inMemoryLayer = new InMemoryFeatureLayer();
        PolygonShape polygon = new PolygonShape("POLYGON((10 60,40 70,30 85, 10 60))");
        LineShape line = new LineShape("LINESTRING(60 60, 70 70,75 60, 80 70, 85 60,95 80)");

        Feature polygonFeature = new Feature(polygon);
        Feature lineFeature = new Feature(line);

        inMemoryLayer.InternalFeatures.Add(lineFeature);
        inMemoryLayer.InternalFeatures.Add(polygonFeature);
        inMemoryLayer.Open();
        inMemoryLayer.Columns.Add(new FeatureSourceColumn("test"));
        inMemoryLayer.Close();

        inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.RoyalBlue);
        inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Blue;
        inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen = new GeoPen(GeoColor.FromArgb(200, GeoColor.StandardColors.Red), 5);

        inMemoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        LayerOverlay staticOverlay = new LayerOverlay();
        staticOverlay.Layers.Add("InMemoryFeatureLayer", inMemoryLayer);
        wpfMap1.Overlays.Add("InMemoryOverlay", staticOverlay);

        //No exception
        inMemoryLayer.Open();
        Collection<Feature> features = inMemoryLayer.QueryTools.GetFeaturesNearestTo(new PointShape(35, 40), GeographyUnit.DecimalDegree, 1, ReturningColumnsType.NoColumns);
        inMemoryLayer.Close();

        wpfMap1.Refresh();
    }