In the Runtime SDKs, a Graphic is a type of Feature. The Feature interface is implemented by the classes Graphic and GeodatabaseFeature. All features, including graphics, have geometry and attributes, and are therefore indistinguishable when displayed on the map. So, what's the difference between features and graphics?
The biggest difference is that features are stored with a dataset and graphics are stored in memory. Features are displayed in a feature layer, which may use data from an online service or from a local cache. In either case, those features are physically stored on disk somewhere. Graphics, on the other hand, are always stored in memory on the client. They live in a graphics layer, and must be instantiated programmatically at runtime.
Although the term can also refer to a graphic, "feature" is most often used to refer to things like geodatabase or geopackage features, meaning features stored in a database. Graphics are usually called "graphics", although "graphic feature" would be more precise.
- Have geometry
- Have attributes stored in a table
- Are stored on disk
- Are displayed through a feature layer (of a single geometry type)
- Are symbolized according to the renderer defined for the feature service or the feature layer that contains them
- Can be selected via the feature layer
- Have geometry
- Have attributes stored in a collection of key/value pairs
- Are stored in memory
- Are displayed through a graphics layer (that can display graphics of diverse geometry types)
- Can be symbolized individually or according to the renderer applied to the graphics layer that contains them
- Can be selected
- Some display properties can be defined by the graphic, such as visibility and draw order
When to use features
Because features are stored in a database, they can be used to display a common set of data to all users of your app and between user sessions. On the other hand, graphics are created in the client app at runtime and therefore can only be used for a single user's session (unless you add logic to persist the graphics between sessions, such as serialization). Features can define a geometry type and an attribute schema that is consistent for the data you want to represent.
With these differences in mind, perhaps the most common use of features is to share data among several users.
You can publish features as part of a feature service. Layers in a feature service can be displayed in a map, symbolized in various ways, and queried using attribute, spatial, or temporal criteria. The rich editing tools available in the Runtime SDK also make it possible to expose editing functionality in your application, including the ability to control the types of edits made and who gets to make them.
When to use graphics
Graphics are created programmatically at runtime and do not need to be physically stored. This makes them ideal for displaying things specific to the current user's session with the application, or anything that only needs to be displayed temporarily.
Graphics are commonly used to perform things such as:
- Show the results of spatial analysis, such as buffer polygons around input features
- Highlight a selection in the map
- Add geometry drawn interactively by the user
- Provide animation for data that changes quickly (such as GPS positions or moving objects)
- Show text on the map