Select to view content in your preferred language

Adding Multiple Point's of Coordinate

1883
10
12-07-2011 04:31 AM
MuhammadWaqar_ul_islam
Occasional Contributor
i m using http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Project sample to plot x,y values
i have add a text file that contain x,y value and plot a last point[x,y] from an array values

My problem is how to add multiple point value from an array not a single value
when i run this code

double ax = 0 ; double ay = 0;
          MapPoint inputMapPoint = new MapPoint(ay, ax, new SpatialReference(4326));
          while (i <= count)
          {
              double.TryParse(test[i, 0], out ax);
              double.TryParse(test[i, 1], out ay);
              inputMapPoint.X = ay;
              inputMapPoint.Y = ax;
              geometryService.ProjectAsync(new List<Graphic>() { new Graphic() { Geometry = inputMapPoint } }, MyMap.SpatialReference, inputMapPoint);
              i++;
          }

its gives this error "Task does not support concurrent I/O operations. Cancel the pending request or wait for it to complete."

geometryService.ProjectAsync(new List<Graphic>() { new Graphic() { Geometry = inputMapPoint } }, MyMap.SpatialReference, inputMapPoint);
0 Kudos
10 Replies
DominiqueBroux
Esri Frequent Contributor

its gives this error "Task does not support concurrent I/O operations. Cancel the pending request or wait for it to complete."


The problem is that you execute your task in the loop --> multiple times : that's not supported.

Instead, you should build your graphics list in the loop and execute the task once after the loop.

Something like:
 
IEnumerable<Graphic> graphics = new List<Graphic>();
while (i <= count)
{
double.TryParse(test[i, 0], out ax);
double.TryParse(test[i, 1], out ay);
graphics.Add(new MapPoint(ay, ax, new SpatialReference(4326));
i++;
}
geometryService.ProjectAsync(graphics, MyMap.SpatialReference, null);
 
0 Kudos
CHRISTOSCHARMATZIS
Deactivated User
The problem is that you execute your task in the loop --> multiple times : that's not supported.

Instead, you should build your graphics list in the loop and execute the task once after the loop.

Something like:
 
IEnumerable<Graphic> graphics = new List<Graphic>();
while (i <= count)
{
double.TryParse(test[i, 0], out ax);
double.TryParse(test[i, 1], out ay);
graphics.Add(new MapPoint(ay, ax, new SpatialReference(4326));
i++;
}
geometryService.ProjectAsync(graphics, MyMap.SpatialReference, null);
 


but the IEnumerable does not contain .Add method...?
What can we do then...?
0 Kudos
DominiqueBroux
Esri Frequent Contributor

but the IEnumerable does not contain .Add method...?
What can we do then...?


Sorry.
IList<Graphic> graphics = new List<Graphic>();
.......
0 Kudos
MuhammadWaqar_ul_islam
Occasional Contributor
still getting error on this
graphics.Add(new MapPoint(ay, ax, new SpatialReference(4326)));

Error2:Argument 1: cannot convert from 'ESRI.ArcGIS.Client.Geometry.MapPoint' to 'ESRI.ArcGIS.Client.Graphic'

Error1: The best overloaded method match for 'System.Collections.Generic.ICollection<ESRI.ArcGIS.Client.Graphic>.Add(ESRI.ArcGIS.Client.Graphic)' has some invalid arguments

what next to do
0 Kudos
CHRISTOSCHARMATZIS
Deactivated User
Sorry.
IList<Graphic> graphics = new List<Graphic>();
.......



I try to change it from List to IList but I still have the same error..
"Task does not support concurrent I/O operations. Cancel the pending request or wait for it to complete."

I have tried the IEnumerable solution...but I get the same error as....Waqar82_geo.
0 Kudos
MuhammadWaqar_ul_islam
Occasional Contributor
As thier any other way to plot multiple point
i m stuck here 
special help is appreciated
0 Kudos
MuhammadWaqar_ul_islam
Occasional Contributor
i haved another way but still only single point is ploted on the map

private void mapWells_Loaded(object sender, RoutedEventArgs e)
        {
            GraphicsLayer wellsLayer = mapWells.Layers["WellsLayer"] as GraphicsLayer;
             // wellsLayer = mapWells.Layers["WellsLayer"] as GraphicsLayer;
   if (wellsLayer == null)
            {
                wellsLayer = new GraphicsLayer()
                {
                    ID = "wellsLayer"
                };
                mapWells.Layers.Add(wellsLayer);

                Graphic marker = new Graphic();
                marker.Symbol = new SimpleMarkerSymbol();
                wellsLayer.Graphics.Add(marker);
            }
            double[] x = new double[] { 305737.67, 305937.67, 305837.67, 305637.67 };
            double[] y = new double[] { 2740242.96, 2740252.96, 2742232.96, 2739232.96 };
            //for (int External = 0; External < 1; External++)
            //  for (int Internal = 0; Internal < 1; Internal++)
            MapPoint[] location = new MapPoint[1];
            for (int i = 0; i < 1; i++)
            {
                location = new MapPoint(x, y, new SpatialReference(4326));
                wellsLayer.Graphics[0].Geometry = location;
            }

            //MapPoint location = new MapPoint(305737.67, 2740242.96, mapWells.SpatialReference);
            //wellsLayer.Graphics[0].Geometry = location;
       }

is there any possibility or not to plot
0 Kudos
DominiqueBroux
Esri Frequent Contributor
is there any possibility or not to plot


I am not sure to exactly understand what you mean.
In your last post, you are just trying to add graphics in a loop. That's obviously possible, there is a sample here:
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AddGraphics

If I come back to the first posts :
  - it's possible to project multiple graphics by calling only once the project task : you just need to give the list of graphics as input of the task.
  - if, for any reason, you absolutely need to execute tasks in //, you have to instantiate new task objects. One single task doesn't support concurrent operation.
0 Kudos
MuhammadWaqar_ul_islam
Occasional Contributor
i am able to plot multiple point on my map code is attached
but one error occurs for the Input coordinate for multiple points only

MapPoint inputMapPoint = e.UserState as MapPoint;
resultGraphic.Attributes.Add("Input_Coordinate", inputMapPoint.X + "," + inputMapPoint.Y);


error Object reference not set to an instance of an object.
error prt screen is attached


void OnWebReadCompleted(object sender, OpenReadCompletedEventArgs e)
{

double ax = 0; double ay = 0; long az = 0;

IList<Graphic> graphics = new List<Graphic>();
while (i <= count)
{
double.TryParse(test[i, 0], out ax);
double.TryParse(test[i, 1], out ay);
MapPoint inputMapPoint = new MapPoint(ay, ax, new SpatialReference(4326));
graphics.Add(new Graphic() { Geometry = inputMapPoint });

i++;

}
geometryService.ProjectAsync(graphics, MyMap.SpatialReference, null);

}


void geometryService_ProjectCompleted(object sender, GraphicsEventArgs e)
{
int i;
for (i = 0; i < e.Results.Count; i++)
//e.Results.Count
{
Graphic resultGraphic = new Graphic();
resultGraphic = e.Results;
Graphic resultGraphic2 = new Graphic();
if (resultGraphic.Geometry.Extent != null)
{
resultGraphic.Symbol = LayoutRoot.Resources["RoundMarkerSymbol"] as SimpleMarkerSymbol;

MapPoint resultMapPoint = resultGraphic.Geometry as MapPoint;
resultGraphic.Attributes.Add("Output_Coordinate", resultMapPoint.X + "," + resultMapPoint.Y);

MapPoint inputMapPoint = e.UserState as MapPoint;

resultGraphic.Attributes.Add("Input_Coordinate", inputMapPoint.X + "," +inputMapPoint.Y);


graphicsLayer.Graphics.Add(resultGraphic);

}
else
{
MessageBox.Show("Invalid input coordinate, unable to project.");
}
}
}
0 Kudos