Select to view content in your preferred language

Joining Database with Map Layer

4044
12
01-07-2013 06:53 AM
Labels (1)
GeorgeFaraj
Frequent Contributor
Hello,

I have a database table (MSSQL) that contains additional information about my layer's features. I want to be able to show this information as part of the layer's map tip. The layer contains an ID attribute that links each feature to a record in the table. Can someone direct me towards achieving this?

PS. I assume map tips are the only way to display information in the map about features, since I haven't found any info about traditional labeling anywhere. I would prefer labeling within the features, so if anyone has any information about that, I'd appreciate it as well.

Thanks!
0 Kudos
12 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

To label graphics/features you can use the TextSymbol. If your data is point geometry this is straightforward, but if your data comprises lines or polygons you might want to use the GeometryService task with either an online or local geometry server and execute the LabelPoints operation - http://resources.arcgis.com/en/help/runtime-wpf/apiref/index.html?ESRI.ArcGIS.Client~ESRI.ArcGIS.Cli....

There's an example of using the TextSymbol in the WPF Sample Application and in the online SL SDK: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AddGraphics.


Cheers

Mike
0 Kudos
GeorgeFaraj
Frequent Contributor
I will look into that for labeling, thanks. Any clues about the joining?
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

You could consider wrapping your table and the geometries in a class that exposes IEnumerable<Graphic> and then use that to set the GraphicsSource property of a GraphicsLayer.

There are a couple of SL samples online which demonstrate this:
http://resources.arcgis.com/en/help/silverlight-api/samples/start.htm#UsingGraphicsSource
http://resources.arcgis.com/en/help/silverlight-api/samples/start.htm#UsingPointDataSource


Cheers

Mike
0 Kudos
GeorgeFaraj
Frequent Contributor
I tried the LabelPoints for labeling, and I have some questions:

1) My feature layer is set to OnDemand mode because it's quite large, how can I make the labels show up for features on demand?

2) The labeling placement seems to be very simple. Is there any way to make label placement smart like in ArcMap / ArcObjects (horizontal, straight, or straight then horizontal)?

3) Is there any way to have the labels show only when they fit inside the polygon? It looks really ugly when I zoom out and hundreds of labels overlap each other and are not even legible.


Thanks,
George
0 Kudos
GeorgeFaraj
Frequent Contributor
Any ideas?
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

Improved labelling at the API level for Graphics/FeatureLayers is currently under investigation for a future release.

In the mean time, the only way to get advanced control over labelling would be to have the labels of the features rendered as a dynamic map service by the RuntimeLocalServer - i.e. the labelling is defined in ArcMap then shared as a Map Package. There is a more to set up, but the additional effort is mostly in the configuration rather than the code. This could be achieved by adding the feature class containing the spatial features to a map document and adding the table from the database to the map document then performing the join between the two and labelling based on one of the fields from the joined table. You could choose no symbology for the layer in ArcMap and just enable labelling if you're rendering the features from the feature layer within your actual application. When packaging, you'll need to use the GP tool, "Package Map" and make sure that the option to "Support the ArcGIS Runtime" is checked and the option to "Include Enterprise geodatabase data..." is unchecked. The effect of this is that the Map Package would contain a File GDB with your spatial features whilst the joined table would remain in the database. Admittedly it gets more complicated if you are going to be editing the features as well. In this case, you can create an ArcGISLocalFeatureLayer on to that File GDB to perform edits. If your edits are elsewhere then you may need to sync them with this labeling database, or vary the above setup to cater for your scenario.

Another variation on this is to use a dynamic map service (server / local) for rendering all the features and labelling and then add the same content as a selection-only feature layer for editing.

I hope that's given you some more options, please don't hesitate to get in touch if you need any more information.

Cheers

Mike
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
... It occurred to me that there's probably another more programmatic way to achieve this too although your table may well need to be registered with the geodatabase for this to work. You could investigate using the DynamicLayer capability of map services. This capability, added to ArcGIS Server at 10.1 and the RuntimeLocalServer at 1.0 allow the client API to make per request modifications to the entire contents of a map service - by that I mean change the rendering of layers, redefine the order of layers, define entirely new layers from registered workspaces and assign rendering. For info on the REST spec for this see: http://resources.arcgis.com/en/help/rest/apiref/index.html?dataSource.html#join.

As a developer working with the RuntimeLocalServer, when you define a new LocalMapService you can set the properties to enable the dynamic layers capability and to register workspaces with the RuntimeLocalServer. You then work with the LayerDrawingOptions property (to define rendering) and the DynamicLayerInfos property (to define datasources) on the ArcGISLocalDynamicMapServiceLayer. One of the datasource types is a JoinDataSource to correspond with the REST spec for the join table data source.

URLs:
http://resources.arcgis.com/en/help/runtime-wpf/apiref/index.html?ESRI.ArcGIS.Client~ESRI.ArcGIS.Cli...
http://resources.arcgis.com/en/help/runtime-wpf/apiref/index.html?ESRI.ArcGIS.Client~ESRI.ArcGIS.Cli...
http://resources.arcgis.com/en/help/runtime-wpf/apiref/index.html?ESRI.ArcGIS.Client~ESRI.ArcGIS.Cli...

It's incomplete - but here's some sample code for setting up the two table datasources and the join:

                                            
LayerSource leftTableLayerSource = new LayerDataSource
{
    DataSource = new TableDataSource 
    {
        DataSourceName = leftTable,
        WorkspaceID = workspaceInfoId, 
    }
};
LayerSource rightTableLayerSource = new LayerDataSource
{
    DataSource = new TableDataSource
    {
        DataSourceName = rightTable,
        WorkspaceID = workspaceInfoId,
    }
};
dataSource = new JoinDataSource 
{
    JoinType = JoinType.LeftInnerJoin,
    LeftTableSource = leftTableLayerSource,
    LeftTableKey = leftTableKey,
    RightTableSource = rightTableLayerSource,
    RightTableKey = rightTableKey
};


Cheers

Mike
0 Kudos
GeorgeFaraj
Frequent Contributor
The way we want to support labeling in our app is on-the-fly, meaning that the user can define what fields are displayed and other options, so I don't think the approach of having the labels be defined in ArcMap will work for us. We don't want the user switching between our app and ArcMap, since that will be a pain for them.

By the way, I tried handling the Updated event on the layer, to label features on demand, but when I do a Query inside that event, I'm still only getting the first 1000. The features that are newly visible are not returned, and thus labels are not placed on them.

Also, I've been looking for a sample of using JoinDataSource and haven't been able to find one. Do you have one?

Thanks,
George

EDIT: I posted this before I saw your second response. I will look at that further, thanks!
0 Kudos
GeorgeFaraj
Frequent Contributor
Mike,

Could I do the Join on a Feature Layer, or only the dynamic layers have this capability? I actually need this for labeling features, so how would this work?
0 Kudos