Connecting points on a map with dots and lines.

2550
7
07-15-2020 10:30 AM
johnmarker
New Contributor III

Hello,

I need some guidance as to the best way to do something. I have a map and when the user clicks on a location on the map it will place a dot marking the location. Then, when the user clicks another location it will connect those two dots with a line. Every click of a location will create a new dot and connect it with a line to the previously created dot. I would like these saved in a Geodatabase so that it is on local storage and not the server. I have been reading about feature tables and polylines. I couldn't find a way to create a polyline onClick. Any recommendations or examples would be much appreciated.  

0 Kudos
7 Replies
RobertBorchert
Frequent Contributor III

Do you need to have the points?

Is there data you need at those points?

If not just use the polyline tool and create your lines.  If you need the points you can run the vertices to points tool

0 Kudos
johnmarker
New Contributor III

The points were to represent the specific latitude and longitude on that location that was clicked. Is there a way to add a polyline with clicking on the location on the map?

0 Kudos
RobertBorchert
Frequent Contributor III

When in editing mode from the templates select the polyline feature class you want to draw.

0 Kudos
JaredCaccamo
Esri Contributor

Hi john marker‌,

What you are asking is definitely possible with the ArcGIS Runtime for Qt.

1) Create and render clicks as points

 

You are going to want to connect to the MapQuickView::mouseClicked(QMouseEvent& mouseEvent) signal which contains the screen coordinates of the mouse click. From there you will want to call MapQuickView::screenToLocation(double x, double y) which returns a Point in the coordinates of the GeoView. Then you can symbolize and add as a graphic to a graphics overlay which will render the clicked point on the map.

2) Create and render polyline from clicked point

You are going to want to use the class PolylineBuilder which is a helper class for building immutable polyline geometries. You will simply call PolylineBuilder::addPoint(Point&) which will connect the previous point to the newly added point creating a new segment. Then you call PolylineBuilder::toPolyline which is used to display and symbolize the polyline.

It will look something like the following:

connect(m_mapView, &MapQuickView::mouseClicked, this, [this](QMouseEvent &mouseEvent)
{
    // get click location, create point, symbolize, display as grpahic
    const Point clickedPoint = m_mapView->screenToLocation(mouseEvent.x(), mouseEvent.y());
    const Geometry pointGeom = GeometryEngine::normalizeCentralMeridian(clickedPoint);
    SimpleMarkerSymbol* pointMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Circle, QColor("red"), 10, this);
    m_graphicOverlay->graphics()->append(new Graphic(pointGeom, pointMarkerSymbol));

    // add point to polyline builder, create polyline from builder, symbolize, display polyline graphic
    m_polylineBuilder->addPoint(pointGeom);
    const Polyline singleLine = m_polylineBuilder->toPolyline();
    SimpleLineSymbol* lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dash, QColor("blue"), 3, this);
    m_graphicOverlay->graphics()->append(new Graphic(singleLine, lineSymbol));
});

Best Regards,

Jared

johnmarker
New Contributor III

I appreciate the very helpful response! Sorry, this is the first real go at using ArcGIS for me. So basically, I would be able to do it all using C++ for the most pat? Just create a new class and then implement the code from the code snippet that you shared? Will i need to save to to a GeoDataBaseFeatueTable, so that it can be saved off and re-uploaded if desired?

0 Kudos
JaredCaccamo
Esri Contributor

Hi john marker,

So the Geodatabase part is a bit more involved. They are most typically used in an offline scenario using either the Preplanned workflow or the On-demand workflow, Work offline—ArcGIS Runtime SDK for Qt | ArcGIS for Developers. But once you decide on which workflow works for you, then you would access a GeodatabaseFeatureTable from the Geodatabase and there you can make edits to that feature table and sync it back. Here is the API documentation for all members of GeodatabaseFeatureTable, List of All Members for GeodatabaseFeatureTable | ArcGIS for Developers. Also here is a sample demonstrating the Preplanned workflow, Download preplanned map | ArcGIS for Developers.

In regards to your question about the code snippet, yes you are correct.

I can definitely relate to the "new to ArcGIS" or GIS in general as my background was not in GIS. Lots of new concepts to learn and how to apply them correctly. The documentation has come a long way since I started here and it is a great resource for learning. Also if you didn't get to see the Plenary during UC this week, I would encourage you to go watch it online, I think it's on youtube. It helps paint a great picture of what ArcGIS is and where it's going and how it all works together.

Best Regards,

Jared

0 Kudos
johnmarker
New Contributor III

I added the code snippet you shared to the setMapView, which is a part of the ArcGIS Qt Quick C++ template build. it looks like this now,

void Missions::setMapView(MapQuickView* mapView)
{
    if (!mapView || mapView == m_mapView)
    {
        return;
    }
    m_mapView = mapView;
    m_mapView->setMap(m_map);

    connect(m_mapView, &MapQuickView::mouseClicked, this, [this](QMouseEvent &mouseEvent)
    {
        const Point clickedPoint = m_mapView->screenToLocation(mouseEvent.x(), 
            mouseEvent.y());
        const Geometry pointGeom = 
        GeometryEngine::normalizeCentralMeridian(clickedPoint);
        SimpleMarkerSymbol* pointMarkerSymbol = new 
        SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Circle, QColor("red"), 10, this);
        m_graphicOverlay->graphics()->append(new Graphic(pointGeom, pointMarkerSymbol));

        m_polylineBuilder->addPoint(pointGeom);
        const Polyline singleLine = m_polylineBuilder->toPolyline();
        SimpleLineSymbol* lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dash, 
            QColor("blue"), 3, this);
        m_graphicOverlay->graphics()->append(new Graphic(singleLine, lineSymbol));
        m_mapView->graphicsOverlays()->append(m_graphicOverlay);
    });

    emit mapViewChanged();
}

When i added "m_mapView->graphicsOverlays()->append(m_graphicOverlay);" to the code it would display the dots. However, I cannot get the line to appear that connects the dots. 

An exception is thrown when I do m_polylineBuilder->addPoint(pointGeom);

0 Kudos