Select to view content in your preferred language

missing polyline  from querytask

3065
9
Jump to solution
10-13-2013 12:27 PM
LefterisKoumis
Frequent Contributor
I run a query from a point layer. The intention is to capture the lat long fields of the selected points and draw a polyline connecting the points. The polyline does not appear. Suggestions? Thank you.



private function doQuery():void
   {
    queryTask.execute(query, new AsyncResponder(onResult, onFault));
    function onResult(featureSet:FeatureSet, token:Object = null):void
    {
     if (featureSet.features.length == 1)
     {
      myMap.zoomTo(featureSet.features[0].geometry);
     }
     else if (featureSet.features.length > 1)
     {
      var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(featureSet.features);
      if (graphicsExtent)
      {
       myMap.extent = graphicsExtent;
      }
      var m:int;
      var pA:Array;
      pA=[];
      for(m=0; m<featureSet.features.length; m++){
       var obj:Object = new Object();
       obj.lat= featureSet.attributes["Lat"];
       obj.long=featureSet.attributes["Long"];
      
       pA.push(new MapPoint(obj.lat,obj.long, new SpatialReference(102100)));
      }
      var pLine:Polyline=new Polyline(null,new SpatialReference(102100));
      pLine.addPath(pA);
      var gra:Graphic=new Graphic(pLine);
      gra.symbol = new SimpleLineSymbol("solid",0xFF3333,1,3);
    
      myGraphicsLayer2.add(gra);
           
     }
    
    
    }
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Lefteris,

   The points geometry might be in WebMercator but the attributes of Lat and Long are in Geographic.

So did you test the code I provided? If it worked than you should mark this thread as answered.

Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow these steps as shown in the below graphic:

View solution in original post

0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Emeritus
Lefteris,

   Based on the field name of Lat and Long, are the coordinates in the point feature Geographic? If so then you need to re-project them to 102100 before you add them to the polyline. Just declaring them as WKID 102100 does not re-project them.
0 Kudos
LefterisKoumis
Frequent Contributor
Lefteris,

   Based on the field name of Lat and Long, are the coordinates in the point feature Geographic? If so then you need to re-project them to 102100 before you add them to the polyline. Just declaring them as WKID 102100 does not re-project them.


No, they are not. The points are in the same coordinate system (Web Mercator) in the point layer as well. I included below the rest of the code in case you spot something. At this point all I get are all the selected points based on the query but the polyline is not drawn. I tried the option to use another graphiclayer as well (not shown below, I removed it) so I can draw the polyline on it, but it didn't work.

Thank you for your input.

<fx:Declarations>
  <!-- Layer with US States -->
  <esri:QueryTask id="queryTask"
      showBusyCursor="true"
      url="http://10.112.89.131/dea_arcgis/rest/services/postmile_2012/d2_test/MapServer/0"
      useAMF="true"/>
 
  <esri:Query id="query"
     outSpatialReference="{myMap.spatialReference}"
     returnGeometry="true"
     outFields="[Route,Odometer,Lat,Long]"
     where = "Route = 3 AND Odometer &lt; 118.955 AND Odometer &gt; 47.717">
  
  
  
  </esri:Query>
</fx:Declarations>



<esri:Map id="myMap">
  <esri:extent>
   <esri:Extent xmin="-13909920" ymin="2928237" xmax="-7354680" ymax="6362400">
    <esri:SpatialReference wkid="102100"/>
   </esri:Extent>
  </esri:extent>
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
  <esri:GraphicsLayer id="myGraphicsLayer" graphicProvider="{queryTask.executeLastResult.features}"/>
 
</esri:Map>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Lefteris,

  Looks like you have you lat and Long reversed when you create your map point.
0 Kudos
LefterisKoumis
Frequent Contributor
Lefteris,

  Looks like you have you lat and Long reversed when you create your map point.


Points are entered in order of lat, long

I created a datagrid to show the lat long that it captures and they are correct (see attached). So I don't think its a case of reverse lat long. But I do know that it is something simple.


[ATTACH=CONFIG]28355[/ATTACH]
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Lefteris,

  OK, the reason I mentioned that I thought you have your lat and Long reversed when you are creating your map points for the poly line is this. A MapPoint takes an X and a Y (in that order). What you have is:

pA.push(new MapPoint(obj.lat,obj.long, new SpatialReference(102100)));

Which equates to
MapPoint(Y, X, new SpatialReference(102100)));


Also your attached table shows me that the Lat and Long coordinates are NOT webmercator they are geographic and DO need to be projected.

So here is the code that I would be using:

            private function doQuery():void
            {
                queryTask.execute(query, new AsyncResponder(onResult, onFault));
                function onResult(featureSet:FeatureSet, token:Object = null):void
                {
                    if (featureSet.features.length == 1)
                    {
                        myMap.zoomTo(featureSet.features[0].geometry);
                    }
                    else if (featureSet.features.length > 1)
                    {
                        var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(featureSet.features);
                        if (graphicsExtent)
                        {
                            myMap.extent = graphicsExtent;
                        }
                        var m:int;
                        var pA:Array = [];
                        var wmp:WebMercatorMapPoint;
                        for(m=0; m<featureSet.features.length; m++){
                            wmp = new WebMercatorMapPoint(featureSet.attributes["Long"], featureSet.attributes["Lat"]);
                            pA.push(wmp);
                        }
                        var pLine:Polyline = new Polyline(null, new SpatialReference(102100));
                        pLine.addPath(pA);
                        var gra:Graphic=new Graphic(pLine, new SimpleLineSymbol("solid",0xFF3333,1,3), null);
                        
                        myGraphicsLayer2.add(gra);
                    }
                }
            }
0 Kudos
LefterisKoumis
Frequent Contributor
Lefteris,

  OK, the reason I mentioned that I thought you have your lat and Long reversed when you are creating your map points for the poly line is this. A MapPoint takes an X and a Y (in that order). What you have is:

pA.push(new MapPoint(obj.lat,obj.long, new SpatialReference(102100)));

Which equates to
MapPoint(Y, X, new SpatialReference(102100)));


Also your attached table shows me that the Lat and Long coordinates are NOT webmercator they are geographic and DO need to be projected.

So here is the code that I would be using:

            private function doQuery():void
            {
                queryTask.execute(query, new AsyncResponder(onResult, onFault));
                function onResult(featureSet:FeatureSet, token:Object = null):void
                {
                    if (featureSet.features.length == 1)
                    {
                        myMap.zoomTo(featureSet.features[0].geometry);
                    }
                    else if (featureSet.features.length > 1)
                    {
                        var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(featureSet.features);
                        if (graphicsExtent)
                        {
                            myMap.extent = graphicsExtent;
                        }
                        var m:int;
                        var pA:Array = [];
                        var wmp:WebMercatorMapPoint;
                        for(m=0; m<featureSet.features.length; m++){
                            wmp = new WebMercatorMapPoint(featureSet.attributes["Long"], featureSet.attributes["Lat"]);
                            pA.push(wmp);
                        }
                        var pLine:Polyline = new Polyline(null, new SpatialReference(102100));
                        pLine.addPath(pA);
                        var gra:Graphic=new Graphic(pLine, new SimpleLineSymbol("solid",0xFF3333,1,3), null);
                        
                        myGraphicsLayer2.add(gra);
                    }
                }
            }


ok, thanks. The reason I thought that the point are in webmercator is because the source of the point layer indicated that they were in the web mercator coord system. I guess I was wrong.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Lefteris,

   The points geometry might be in WebMercator but the attributes of Lat and Long are in Geographic.

So did you test the code I provided? If it worked than you should mark this thread as answered.

Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow these steps as shown in the below graphic:

0 Kudos
LefterisKoumis
Frequent Contributor
Lefteris,

   The points geometry might be in WebMercator but the attributes of Lat and Long are in Geographic.

So did you test the code I provided? If it worked than you should mark this thread as answered.

Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow these steps as shown in the below graphic:



Are you sarcastic? I have already checked other answers and I don't need the idiot pictures to show me how to do it. Certainly, responding to  questions with capital letters is not welcome either. Thanks for your help but in the future ignore my questions. Let other users who have more patience to answer them. FYI, I found the answer myself before you posted the last answer, after I checked the Flex APi and found the webmercatorpoint.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Lefteris,

   Hmm... Based on the wording of your post I can tell you were irritated when you posted. Now how you got sarcastic from my posts I am not sure. I have used that exact image and bold text for some time now in my six years helping people on these forums, and I have to say that this is the first time I have been accused of not having patience. In the process of helping hundreds of people on these forums I can not remember who knows how to mark answers as answered and who does not, hence the use of the informative graphic and text. When I posted that images and text you had yet to mark the post as answered. My use of capital letters was for emphasis of what I wanted to draw your attention to and not meant to be condescending. I am sorry to say that you have become a victim of misreading or reading into electronic communication where you can not hear or see the tone of the author. Best of wishes to you in your future Flex and Viewer endeavors.
0 Kudos