Is This Content Helpful?
We're glad to know this article was helpful.
If you create a layer which contains more than one entity type, i.e. Polygons and Lines, then the recordset of the layer will contain all of the layer's records (i.e. Lines and Polygons). This is the behavior at both MapObjects 1.2 and MapObjects 2.0.
For example, let's say you've created an SDE layer called "multiGeom" on your server. This layer contains both river features (100 lines) and country features (200 polygons). If you return all of the records in the multiGeom layer (Layer.Records), you will return a recordset with 300 records, using either MapObjects 2.0 or MapObjects 1.2. However, if you only ask for line entity types to be displayed, then only line features will be displayed; for example, MYUSER.MULTIGEOM.SHAPE.LINES would only draw lines.
One of the differences between MapObjects 1.2 and 2.0 occurs when you access the value of the "Shape" field for a record which does not contain the expected entity type for that layer, such as returning the value of a line record in a polygon-defined theme. For example, using the following code
Set pLine = pField.Value
in MapObjects 2.0, an error will be generated if the layer was defined as MYUSER.MULTIGEOM.SHAPE.POLYGONS, whereas with MapObjects 1.2, it will simply return nothing. This is due to internal changes in the way that MapObjects 2.0 handles NULL shapes and is not affected by the Visual Basic definition of the pLine object -- that is, dimensioning the pLine object as an Object rather than a MapObjects2.Line will not matter.
Ideally, MapObjects should only return those records which are of the specified type for the layer and this is something which we will be looking at for a future release. However, in the meantime, we suggest a workaround. Basically, we want to filter out only those features which are of the required entity type for our layer. To do this, we can user the FilterExpression method to narrow down the layer. For this, we need to have a field on which we can query, a field which describes the entity type for that record. However, no such field exists by default, in the layer's Business table in SDE. As a result, two options are available:
Dim oTable As New MapObjects2.Table
oTable.Name = "SDE.LAYERS"
oTable.Server = "drfinlay"
oTable.User = "sde_user"
oTable.Password = "sde_user"
oTable.Database = "esri_sde"
Dim oRec As MapObjects2.Recordset
Set oRec = oTable.SearchExpression("sde.layers.table_name = 'MULTIGEOM'")
Dim layerid As String
layerid = oRec.Fields.Item("LAYER_ID").Value
Dim filterExpr As String
filterExpr = "mo2dev.multigeom.shape IN (select mo2dev.F" & layerid & ".fid from mo2dev.F" & layerid & " where mo2dev.F" & layerid & ".entity=8)"
pLayer.FilterExpression = filterExpr
Set pRec = pLayer.Records