ThinkGeo.com    |     Documentation    |     Premium Support

MultipolygonShape not displaying

I’m creating a few RectangleShapes, converting them into Polygons, and then adding them to a collection of polygonshapes. I then turn that collection of polygons into a multipolygonshape, create a new feature with that multipolygonshape, and add it to my map. However, the multipolygonshape is not appearing, but the label for it is. I am using a custom value style for this layer.

Below is the code for creating the rectangle shapes and converting them to polygon shapes. My goal here is to make a grid shape on the map:

double rectangleHeight = 20; //height and width of each rectangle
double rectangleWidth = 20;
Collection<PolygonShape> rectangleShapes = new Collection<PolygonShape>(); //holds the rectangles converted to polygons
PointShape anchorPoint = new PointShape(0, 0); //this will be the upper left point of the rectangle
RectangleShape rectangleShape = new RectangleShape(); //first rectangle shape, other rectangles will be calculated off of this one
PointShape lowerRight = (PointShape)anchorPoint.CloneDeep();
lowerRight.TranslateByOffset(rectangleWidth, -rectangleHeight, GeographyUnit.DecimalDegree, DistanceUnit.Meters;
rectangleShape = new RectangleShape(anchorPoint, lowerRight);
rectangleShapes.Add(rectangleShape.ToPolygon());

for (int i = 0; i < 2; i++) //I want a 2x2 grid shape, so four rectangles total
{
    for (int j = 0; j < 2; j++)
    {
        if (i ==0 && j == 0) //we already created the first rectangle
        {
            //do nothing
        }
        else //create the other rectangles
        { 
            RectangleShape newRectangle = (RectangleShape)rectangleShape.CloneDeep();
            newRectangle.TranslateByOffset(rectangleWidth * j, -rectangleHeight * i, GeographyUnit.DecimalDegree, DistanceUnit.Meters;
            rectangleShapes.Add(newRectangle.ToPolygon());
        }
    }

MultipolygonShape polygonShape = new MultipolygonShape(rectangleShapes);

Feature newGrid = new Feature(polygonShape);  
newGrid.Id = gridName;
newGrid.ColumnValues.Add("styleName", "EmptyRed2");
newGrid.ColumnValues.Add("fontStyleName", "Title1");
newGrid.ColumnValues.Add("Label", gridName);

(MapModel.userFeaturesOverlay.Layers["User Polygons Layer"] as InMemoryFeatureLayer).InternalFeatures.Add(gridName, newGrid);
Map.Refresh();

Here’s how I’m adding the style. Note: Individual PolygonShapes in this layer display just fine. It’s when I try combining them into a MultipolygonShape that they stop working:

public static ValueStyle valueStyle = new ValueStyle();

InMemoryFeatureLayer userPolygonsLayer = new InMemoryFeatureLayer
{
    Name = "User Polygons Layer"
};
userPolygonsLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(MapModel.valueStyle);
userPolygonsLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(MapModel.fontValueStyle);
userPolygonsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
MapModel.userFeaturesOverlay.Layers.Add(userPolygonsLayer.Name, userPolygonsLayer);

valueStyle.ValueItems.Add(new ValueItem(parentStyleModel.Name, (parentStyleModel as PolyStyleModel).PolyStyle //PolyStyle is just a simple area style. Red outline, no fill color

Hi Dan,

I build a sample based on your code, it works.

Please try it: 9313.zip (12.2 KB)

Regards,

Ethan

Looks like I had a projection problem. The shape was actually displaying but it was stretched out so far I couldn’t see it. Thanks!

Hi Dan,

Any question please let us know.

Regards,

Ethan