Add features with GeometryTyp polygon

749
5
Jump to solution
12-10-2019 07:54 AM
MagdalenaOchsenbauer
New Contributor

Is there any example for adding features with GeometryTyp polygon in combination with SketchEditor?

I studied this example with GeometryTyp point: Add features (Feature Service) | ArcGIS for Developers , but I've not found a comparable example for GeometryTyp polygon.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Hi again,

Polygon inherits from Geometry so you can cast your geometry to a polygon once you're happy it is a polygon. Use code looking something like:

if (sketchGeometry.getGeometryType() == GeometryType.POLYGON) {
  Polygon polygon = (Polygon) sketchGeometry;
}

or

if (sketchGeometry instanceof Polygon) {
  Polygon polygon = (Polygon) sketchGeometry;
}

Hope this helps!

Trevor

View solution in original post

0 Kudos
5 Replies
by Anonymous User
Not applicable

Hello!

The sketch editor samples does exactly that!

Cheers,

Trevor

0 Kudos
MagdalenaOchsenbauer
New Contributor

Thank you very much for your reply, but how can I convert the sketchGeometry to a Polygon to save it in a FeatureLayer?

Geometry sketchGeometry = mSketchEditor.getGeometry();
0 Kudos
by Anonymous User
Not applicable

Hi again,

Polygon inherits from Geometry so you can cast your geometry to a polygon once you're happy it is a polygon. Use code looking something like:

if (sketchGeometry.getGeometryType() == GeometryType.POLYGON) {
  Polygon polygon = (Polygon) sketchGeometry;
}

or

if (sketchGeometry instanceof Polygon) {
  Polygon polygon = (Polygon) sketchGeometry;
}

Hope this helps!

Trevor

0 Kudos
MagdalenaOchsenbauer
New Contributor

Thank you very much! It's solved.

0 Kudos
novruzjaf
New Contributor II

How to fix this problem?

0 Kudos