ArcGIS Blog

Display GeoJSON features in your QML app

The ArcGIS Runtime SDK for Java has put out a blog and sample application showing how you can view and interact with GeoJSON features in an ArcGIS Runtime application.  The blog does a great job of explaining the basic principles of GeoJSON, as well as showing how GeoJSON features map to Esri Features. One of the great things about the ArcGIS Runtime SDKs is that the APIs are very consistent between the different SDK products, so this exact same workflow and process is very simple to achieve in Qt with our new QML API.

To see an example of how to do this, download the source for a sample project from ArcGIS Online. Please note that this sample is not supported.

In order to consume these features in the QML API, you will need to first include the GeoJsonParser.qml file, which is included in the above link. Then, declare a GeoJsonParser component, and set the source property equal to the path to your .geojson file.

GeoJsonParser { 
    id: geoJsonParser 
    source: "/User/airports.geojson" 
}

The GeoJsonParser will eventually return a list of Graphics (which is a subclass of Feature), each of which contain geometry, attributes, and a symbol. To get this output to display on the map, you will need to declare a GraphicsLayer inside of your map.

GraphicsLayer {
    id: gl
    renderingMode: Enums.RenderingModeStatic
}

Inside of the GeoJsonParser, define a signal handler called onFeaturesParsed. This signal handler will implement some JavaScript code to wait for all the features to be parsed, and then to loop through the feature list, and add each item into the GraphicsLayer.

onFeaturesParsed: {
    for (var i in featureList) {
        gl.addGraphic(featureList[i]);
    }
}

Finally, call the loadGeoJsonFeatures() function on the GeoJsonParser, and this will begin the parsing. The signal handler will load the Graphics into the GraphicsLayer once the features are parsed and converted. The output app will look something like the following:

The code sample on ArcGIS Online contains both the implementation, and an example of how to use it. The example shows how you can take it one step further, and add in your own custom symbology, as well as query the feature for attributes. This is a great example of how easy it is to write powerful applications with QML and the ArcGIS Runtime SDK for Qt. Please see the GeoJSON spec for further information about GeoJSON, and if you haven’t already downloaded the SDK, you can read more about it here.

About the author

Lucas is a Product Engineering Lead on the ArcGIS Runtime SDK team. He is the Product Owner of the ArcGIS Runtime SDK for Qt and also leads the ArcGIS Runtime Toolkit team. In his free time, he likes spending time outdoors, traveling, and cooking.

Connect:
0 Comments
Inline Feedbacks
View all comments

Next Article

Basemap Releases Include Over 300 New and Updated Communities

Read this article