How to create layer with polygon

340
2
Jump to solution
10-23-2022 10:43 PM
SIASIA1
New Contributor

Hi, I want to create layer with polygon.

There is no error but, I can't see polygon UI

 

 

var gl_param = new GraphicsLayerCreationParams { Name = job_id };
QueuedTask.Run(() =>
{
var graphicsLayer = LayerFactory.Instance.CreateLayer<ArcGIS.Desktop.Mapping.GraphicsLayer>(gl_param, map);
double xMax, yMax, xMin, yMin;

(xMax, yMax) = (a, b);
(xMin, yMin) = (c, d);

List<Coordinate2D> plyCoords = new List<Coordinate2D>();
plyCoords.Add(new Coordinate2D(xMax, yMax));
plyCoords.Add(new Coordinate2D(xMax, yMin));
plyCoords.Add(new Coordinate2D(xMin, yMax));
plyCoords.Add(new Coordinate2D(xMin, yMin));
Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);

var poly_symbol = SymbolFactory.Instance.ConstructLineSymbol(
SymbolFactory.Instance.ConstructStroke(
ColorFactory.Instance.RedRGB, 1.0, SimpleLineStyle.Solid));

var graphic = new CIMPolygonGraphic()
{
Symbol = poly_symbol.MakeSymbolReference(),
Polygon = poly,
};
graphicsLayer.AddElement(graphic);
});

 

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

To test your snippet i used the following code to define the envelope:

 

var env = MapView.Active.Extent;
(xMax, yMax) = (env.XMax, env.YMax);
(xMin, yMin) = (env.XMin, env.YMin);

 

This works for me, but the graphic i get is a bow tie.  

Wolf_0-1666616725822.png

Because you don't get a graphic at all, i assume that your projection for your a, b, c and d values needs to be defined.  I don't know what your projection is, but you have to add it here:

 

Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords, map.SpatialReference);

 

Replace map.SpatialReference with the spatial reference for your corner coordinates.  I.e. SpatialReferences.WGS84 if you are using lat/long.

View solution in original post

0 Kudos
2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

To test your snippet i used the following code to define the envelope:

 

var env = MapView.Active.Extent;
(xMax, yMax) = (env.XMax, env.YMax);
(xMin, yMin) = (env.XMin, env.YMin);

 

This works for me, but the graphic i get is a bow tie.  

Wolf_0-1666616725822.png

Because you don't get a graphic at all, i assume that your projection for your a, b, c and d values needs to be defined.  I don't know what your projection is, but you have to add it here:

 

Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords, map.SpatialReference);

 

Replace map.SpatialReference with the spatial reference for your corner coordinates.  I.e. SpatialReferences.WGS84 if you are using lat/long.

0 Kudos
SIASIA1
New Contributor

Oh, I have wrong value.

I Solved it. Thanks! 😄

0 Kudos