ThinkGeo.com    |     Documentation    |     Premium Support

Best way to dynamically alter shape parameters in an InMemoryFeatureLayer

I have an InMemoryFeatureLayer to store a series of EllipseShape objects.
I want to be able to dynamically alter the height and width of the EllipseShape objects.
I have tried to get each EllipseShape object from the InMemoryFeatureLayer in turn in order to use SetHeight and SetWidth as follows:

        EllipseShape range_ring = (EllipseShape)rx_ring_layer.InternalFeatures[rx_entry.Id.ToString()].GetShape();
        range_ring.SetHeightByUnit(radius, Map.MapUnit, DistanceUnit.Meter);
        range_ring.SetWidthByUnit(radius, Map.MapUnit, DistanceUnit.Meter);

Unfotunately, I get an InvalidCastException as the EllipseShape objects appear to have been stored as PolygonShape objects, despite them being created as follows:

            PointShape point = new PointShape(rx_entry.Longitude, rx_entry.Latitude);
            if (Map.MapUnit == GeographyUnit.Meter)
                point = (PointShape)proj4.ConvertToExternalProjection(point);
            rx_ring_layer.InternalFeatures.Add(rx_entry.Id.ToString(), new Feature(new EllipseShape(point, radius)));

Also, I have read the following in the help documentation for GetShape:

This method allows you to get a shape class from a Feature. Because the Feature stores the geometry for itself in well-known binary, it may take some time to generate a shape class if the geometry is complex.

It seems that the way I am going about this is all wrong. As I am new to Map Suite and GIS software in general, I was wondering if anyone could point me in the right direction?

Hi Daniel,

After the EllipseShape is created on map, it exist as a polygon, so you cannot edit it.

The correct way is like this:

  1. Create a Feature based on your EllipseShape, and save the key parameters for example: centerPointFeature, horizontalRadius, verticalRadius.

  2. When you want to edit it, find the feature, read it’s original value, modify them and create a totally new EllipseShape.

  3. Remove old Feature with EllipseShape, and add the new Feature with EllipseShape.

Wish that’s helpful.

Regards,

Ethan

Hi Ethan,

Many thanks for your response. What you describe is exactly how I’ve ended up doing it. It just seems slightly wasteful to create a new object rather than edit an existing one. Clearly, changing the radius of an ellipse will require it to be completely re-rendered, so I guess the time taken to do object deletion and re-creation is insignificant in comparison to the time taken to re-render.

Regards,

Dan.

Hi Dan,

You can choose edit it or rebuild it, but I think the speed shouldn’t be feel when you use it exception you batch process lots of shapes.

Regards,

Ethan