GeometryException when drawing a line on the map

985
5
Jump to solution
01-19-2012 05:24 AM
_lkerArg_n
New Contributor
I tried to draw a line on a graphic layer added to map with the lines of code below. I get a geometry exception. What am I doing wrong?

                           Segment segment = new Line();    segment.setStart(startPoint);    segment.setEnd(endPoint);        Log.d("SEGMENT", "x: " + segment.getStartX() + "y: " + segment.getStartY());        Symbol lineSymbol = new SimpleLineSymbol(Color.BLUE, 4);    someGraphicsLayer.addGraphic(new Graphic(segment, lineSymbol));
0 Kudos
1 Solution

Accepted Solutions
SebastianGreifeneder1
New Contributor III
When you specify a Graphic you've to provide a "Geometry". IMO "Segment" itself isn't a Geometry, it's only part of it within polylines or polygons.
So, for graphics you should use Point, Polyline or Polygon.

View solution in original post

0 Kudos
5 Replies
_lkerArg_n
New Contributor
I did what I want to by using Polyline.

Polyline poly = new Polyline();
poly.startPath(startPoint);
poly.lineTo(endPoint);
   
allyGraphicsLayer.addGraphic(new Graphic(poly, new SimpleLineSymbol(Color.BLUE, 5)));


Still i wonder what did I do wrong in the code in the previous post.
0 Kudos
BradFrecker
New Contributor
I have seen the exact same error, and would also like to know what is wrong with the above code.
0 Kudos
IvanBespalov
Occasional Contributor III
mggl,

Unfortunately I can not compile your code now, but try to use Polyline when creating a Graphic.

try
{
    Segment segment = new Line();
    segment.setStart(startPoint);
    segment.setEnd(endPoint);
    Log.d("SEGMENT", "x: " + segment.getStartX() + "y: " + segment.getStartY());

    Polyline pLine = new Polyline();
    pLine.addSegment(segment, true);
   
    Symbol lineSymbol = new SimpleLineSymbol(Color.BLUE, 4);
    int addedGraphicId = someGraphicsLayer.addGraphic(new Graphic(pLine, lineSymbol));
    Log.d("Class/activity name for logging", "Graphic added id=" + addedGraphicId);
}
catch (Exception ex)
{
    // log exception ex.getMessage()
}
0 Kudos
SebastianGreifeneder1
New Contributor III
When you specify a Graphic you've to provide a "Geometry". IMO "Segment" itself isn't a Geometry, it's only part of it within polylines or polygons.
So, for graphics you should use Point, Polyline or Polygon.
0 Kudos
IvanBespalov
Occasional Contributor III
Sebastian,

There are no any documentation from ESRI developers, where Segment is not a Geometry!

Also no any documentation about "witch Geometries types can be used with Graphic".

Finally:
So, for graphics you should use Point, Polyline or Polygon.

you right, but I did not find any documentation about it.
0 Kudos