|     Blog    |     Wiki    |     Support

Get rectangle shape dimensions for state

I’m looking to load the initial CurrentExtent of the map based on what state the user is allowed to see so for example if a user is working with Nevada, the CurrentExtent is set to the RectangleShape of Nevada. I have seen references to the US RectangleShape (below) but what is the best method to get a specific shape dimension for a US state/region? Is there a way to either generate that or is there a list I can use?

// US
mapView.CurrentExtent = new RectangleShape(-14180662, 5547256, -7832569, 1777465);

Thank you,

Hi Eric,

We don’t have the default bouding box for each state in US. But it’s easy to get it.

If you have the state shape of US, you can loop the features(states) in it, and get bouding box of each feature, that should be what you want.

You can save the result as a colleciton, or you can dynamic get it from the shape file by spatial query.

Here is a simple sample code:

        ShapeFileFeatureLayer states = new ShapeFileFeatureLayer(@"..\..\AppData\states.shp");
        Collection<Feature> features = states.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns);
        foreach (Feature feature in features)
            if (feature.ColumnValues["State Column Name In Your Data"] == "Your Target State Name")
                // The rect is what you want
                RectangleShape rect = feature.GetBoundingBox();

Any question please let us know.