Creating a polyline from points in C++ with QT creator

2488
4
02-09-2017 12:41 PM
CleaBertholet
New Contributor

Hi fellow GIS persons,

 

I’m trying to implement some C++ code to start putting some basic features on a projection of a globe using QT creator.  My code compiles and displays my projected points on a map within the application I’m building, but my polyline code does not seem to be projecting.

Here is the code that produces the points, but will not produce lines.

void MapRay::addSymbols(vector<Point> *locations)
{
mn::GraphicsOverlay* graphicsOverlay = new mn::GraphicsOverlay(this);
graphicsOverlay->sceneProperties().setSurfacePlacement(mn::SurfacePlacement::Absolute);

m_sceneView->graphicsOverlays()->append(graphicsOverlay);

for (int i=0; i < locations->size(); i++)
{
Point loc = locations->at(i);

mn::SimpleMarkerSceneSymbol* smss = new mn::SimpleMarkerSceneSymbol(mn::SimpleMarkerSceneSymbolStyle::Sphere, QColor(255,0,0), 200, 200, 200, mn::SceneSymbolAnchorPosition::Center, this);

mn::Graphic* graphic = new mn::Graphic(mn::Point(loc.y, loc.x, loc.z, m_sceneView->spatialReference()), smss, this);


graphicsOverlay->graphics()->append(graphic);

}

mn::PolygonBuilder polylineBuilder(mn::SpatialReference::webMercator());

for (int i=0; i < 2; i++)
{
Point loc = locations->at(i);
polylineBuilder.addPoint(loc.y, loc.x, loc.z);
}

mn::SimpleLineSymbol* sls = new mn::SimpleLineSymbol(mn::SimpleLineSymbolStyle::Solid, QColor("blue"), 5, this);

mn::Graphic* lineGraphic = new mn::Graphic(polylineBuilder.toGeometry(), this);


mn::GraphicsOverlay* lineGraphicOverlay = new mn::GraphicsOverlay(this);

lineGraphicOverlay->setRenderer(new mn::SimpleRenderer(sls, this));

lineGraphicOverlay->graphics()->append(lineGraphic);

m_sceneView->graphicsOverlays()->append(lineGraphicOverlay);

}

Seems like it should be a simple process, but it's not working.

Any help would be much appreciated!


					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
0 Kudos
4 Replies
KoushikHajra
Esri Contributor

Hi Clea,

You seem to have a spatial reference problem.  I am not sure of the spatial reference of the points that you are passing to addSymbols().  You are using webMercator when you create the polygonBuilder.  Your builder needs to be in the same spatial reference as the points that are being added to it, especially when you are adding new points by taking the raw coordinates from existing points. If the sr's are different, then the points would get put in unexpected locations on the map.  

When you create your points, you use the spatial reference of the sceneView, which is why they work.  So, if you use the sceneView's spatial reference for the builder also, it should work.  

This should fix your problem.

PolylineBuilder polylineBuilder(m_sceneView->spatialReference()); 

Also, please note that sceneview always has a spatial reference of wgs84.  So, you could use the static function SpatialReference::wgs84() instead if you would like.

Hope that helps! 

CleaBertholet
New Contributor

This worked!  

Thanks so much, Koushik!

~Clea

0 Kudos
NorbertThoden
Occasional Contributor III

Hi!

Maybe it´s not the main focus, but:

Pay attention on code like

graphicsOverlay->sceneProperties().setSurfacePlacement(mn::SurfacePlacement::Absolute);

try it like this - arcgis-runtime-samples-qt/Surface_Placement.cpp at v.next · Esri/arcgis-runtime-samples-qt · GitHub 

Norbert

0 Kudos
NorbertThoden
Occasional Contributor III

To avoid the impression that i just copy the infos of Lucas, here is his complete post:

Not positive this will fix your issues, but we had a bug in our sample before, and it looks similar to what you have in the above code. The issue is that the sceneProperties getter returns a value object, so you are just setting the surface placement on a copy, and it never makes its way back to the graphics overlay. Instead, try it like this - arcgis-runtime-samples-qt/Surface_Placement.cpp at v.next · Esri/arcgis-runtime-samples-qt · GitHub

copyright: Lucas Danzinger :)

0 Kudos