Adding point graphic at center of line feature using geometry service

5445
9
05-22-2011 12:32 PM
ImtiyazPasha1
New Contributor II
Hi,

I added Point at center of polygon but failed to add point at center of line using geometry service.

help me regarding this

Thanks in advance
0 Kudos
9 Replies
IgressT
New Contributor II
Hi,

I added Point at center of polygon but failed to add point at center of line using geometry service.

help me regarding this

Thanks in advance


I think it only works for polygons
0 Kudos
ImtiyazPasha1
New Contributor II
There should be any option to draw point graphic at center of line using geometry service or without using geometry service please help...
0 Kudos
JenniferNery
Esri Regular Contributor
This might be related thread: http://forums.arcgis.com/threads/29061-How-to-find-the-midpoint-of-a-polyline.

You can get the center of the polyline and add MapPoint in that location.
0 Kudos
IgressT
New Contributor II
This might be related thread: http://forums.arcgis.com/threads/29061-How-to-find-the-midpoint-of-a-polyline.

You can get the center of the polyline and add MapPoint in that location.


I tried that but it works only if the polyline is a straight line but what if its not.. see the image is there any other way
0 Kudos
ImtiyazPasha1
New Contributor II
This might be related thread: http://forums.arcgis.com/threads/29061-How-to-find-the-midpoint-of-a-polyline.

You can get the center of the polyline and add MapPoint in that location.



Yes polyline.extent.getCenter(); gets the polyline center but not exact center like the geometry service for polygon,

polyline.Extent.getCenter() not work for curved line or polygon it draws graphic outside the polygon or polyline i need the exact center of polyline.

thanks for your reply.

any other option please...
0 Kudos
ImtiyazPasha1
New Contributor II
any help please......
0 Kudos
ImtiyazPasha1
New Contributor II
finally I got it using ESRI.ArcGIS.Client.Geometry.PointCollection ps in line.Paths
and

<esriSymbol:PictureMarkerSymbol  x:Key="DefaultRasterSymbol" OffsetX="12" OffsetY="34" Source="" />

Thanks for all
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You might calculate the center of the polyline at the client side.

Very simplified version:
public static class GeometryExtension
{
    public static MapPoint Center(this Polyline polyline)
    {
        var path = polyline.Paths[polyline.Paths.Count / 2];
        int pointIndex = (path.Count-1)/2;
        MapPoint startPoint = path[pointIndex];
        MapPoint endPoint = path[pointIndex + 1];
        return new MapPoint((startPoint.X + endPoint.X)/2.0, (startPoint.Y + endPoint.Y)/2.0);
    }
}


Then you can get the center of a polyline by : MapPoint center= myPolyline.Center();

This is just returning the center of the middle segment but you might enhance the code depending on what you need exactly.
0 Kudos
ImtiyazPasha1
New Contributor II
Hi Dominique BROUX,

Yes your right but I did it with different approach.

Thanks
0 Kudos