Renderer On Date Ranges

626
1
Jump to solution
04-17-2013 03:29 PM
CaryRoberts
New Contributor III
Hi Everyone,
So lets say I want to symbolize one field that has date and time and break it down by Current_TimeStamp  for > 90 days, 60 - 90 days etc. Then I would like to render each selection with a specific color, red, yellow, green. I  can select for data range and set the symbols for each range but only the first draws the color. I pull the feature class from SDE and reference the FC three times for each selection, renderer and Geofeaturelayer. The renderer through a loop selects each date and symbolizes each record for each date range (YUK). I figured if I could set individual renderer's for selection I would be OK. Should I continue down this path? Should I try and export the selection to LYR file and import back into ArcMap for symbolization? A bit of confusion here. Heres my code VS 2010 ArcMAP V 10.

            Dim featureInspectLayer As IFeatureLayer = New FeatureLayerClass
            featureInspectLayer.FeatureClass = featureInspectClass
            featureInspectLayer.Name = "Inspections_>_90_Days"
            featureInspectLayer.Visible = True

            ' If activeView Is Nothing OrElse featureInspectLayer Is Nothing OrElse whereClause Is Nothing Then
            'Return
            'End If
            Dim featureInspectSelection As IFeatureSelection = TryCast(featureInspectLayer, IFeatureSelection) ' Dynamic Cast
            ' Set up the query
            Dim feature As ESRI.ArcGIS.Geodatabase.IFeature
            Dim queryFilter As IQueryFilter = New QueryFilterClass '
            Dim Day90Filter As String = "WHERE [InspectionDate] in (SELECT max([InspectionDate]) FROM VECTOR.SDE.PolyInspection GROUP BY [SourceSiteID]) AND InspectionDate <= Current_TimeStamp - 90"

            queryFilter.WhereClause = Day90Filter
            Dim featSelection As IFeatureSelection = featureInspectLayer
            featSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, False)
            featSelection.SelectionChanged()

            Dim selectionSet As ISelectionSet = featSelection.SelectionSet
            Dim featCursor As IFeatureCursor = Nothing
            selectionSet.Search(Nothing, True, featCursor)

            Dim NineDay As IRgbColor
            NineDay = New RgbColor
            NineDay.Red = 255
            NineDay.Green = 0
            NineDay.Blue = 0

            Dim symd As New SimpleFillSymbol
            symd.Style = esriSimpleFillStyle.esriSFSSolid
            symd.Outline.Width = 6

            Dim uvRenderer As IUniqueValueRenderer = New UniqueValueRenderer
            uvRenderer.FieldCount = 1
            uvRenderer.Field(0) = "InspectionDate"
            uvRenderer.DefaultSymbol = symd
            uvRenderer.UseDefaultSymbol = True

            Dim sym As ISimpleFillSymbol = Nothing
            feature = featCursor.NextFeature
            Do Until feature Is Nothing
                sym = New SimpleFillSymbol
                sym.Style = esriSimpleFillStyle.esriSFSSolid
                sym.Outline.Width = 6
                sym.Outline.Color = NineDay
                sym.Color = NineDay
                uvRenderer.AddValue(feature.Value(feature.Fields.FindField("InspectionDate")), "", sym)
                feature = featCursor.NextFeature()
            Loop

            ' adds Inspection Feature layer
            activeView.FocusMap.AddLayer(featureInspectLayer)
            activeView.Extent = activeView.FullExtent
            activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, Nothing, Nothing)
            mapDoc.ActiveView.ContentsChanged()
            featSelection.SelectionChanged()
            pMxDoc.UpdateContents()

            Dim geofeatureInspectLayer As IGeoFeatureLayer = featureInspectLayer
            geofeatureInspectLayer.Renderer = uvRenderer

Thanks Folks
0 Kudos
1 Solution

Accepted Solutions
CaryRoberts
New Contributor III
Well Howdy Folks,
I think I was trying to do to much. UVRenderer is for multiple attributes in one field or column, if Im not mistaken. I could get things to renderer but not display. So plan B, everybody has to have a plan b. I decided to query by date range from the most recent entry (date) and export out to file geodatabase and then load back into arc map and then use the simple renderer. Works much better and not much of a load from the query.  So heres what I did...

'/////////////////////////////START OF 30 OR LESS

            Dim feature10Layer As IFeatureLayer = New FeatureLayerClass
            feature10Layer.FeatureClass = feature10InspectClass
            feature10Layer.Name = "Treatments"
            feature10Layer.Visible = True
            Dim feature10InspectSelection As IFeatureSelection = TryCast(feature10Layer, IFeatureSelection) ' Dynamic Cast

            Dim query10Filter As IQueryFilter = New QueryFilterClass '
            Dim Day10Filter As String = "WHERE [InspectionDate] in (SELECT max([InspectionDate]) FROM VECTOR.SDE.PolyInspection GROUP BY [SourceSiteID])  AND InspectionDate  > Current_TimeStamp -30 and InspectionDate < Current_TimeStamp"
            Dim feat10Selection As IFeatureSelection = feature30Layer
            query10Filter.WhereClause = Day10Filter


            feat10Selection.SelectFeatures(query10Filter, esriSelectionResultEnum.esriSelectionResultNew, False)
            feat10Selection.SelectionChanged()

            Dim selection10Set As ISelectionSet = feat10Selection.SelectionSet
            Dim feat10Cursor As IFeatureCursor = Nothing
            selection10Set.Search(Nothing, True, feat10Cursor)

            Dim pIn10Workspace As IFeatureWorkspace
            pIn10Workspace = workspaceFactory.Open(propertySet, 0)

            pFeatureClass = pIn10Workspace.OpenFeatureClass("VECTOR.SDE.PolyInspection")

         
            pDataSet = pFeatureClass
            pDatasetName = pDataSet.FullName

            pathExport = "c:\GISDATA\Inspection"
         
            pOutWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactory
            pOutWorkspace = pOutWorkspaceFactory.OpenFromFile(pathExport & "\Inspect.gdb", 0)
            pOutWorkspaceDataset = pOutWorkspace
            pOutWorkspaceName = pOutWorkspaceDataset.FullName
            pOutDatasetName = New FeatureClassName
            pOutDatasetName.Name = "Under30"
            pOutDatasetName.WorkspaceName = pOutWorkspaceName

            Try
                Dim pFeatWorkSpc As IFeatureWorkspace
                pFeatWorkSpc = pOutWorkspace
                Dim pfeatClass As IFeatureClass
                pfeatClass = pFeatWorkSpc.OpenFeatureClass("Under30")
                Dim pdaset As IDataset
                pdaset = pfeatClass
                pdaset.Delete()
            Catch exy As Exception
                ' if it doesnt exist then thats OK
            End Try

            'Dim pExportOperation As IExportOperation
            pExportOperation = New ExportOperation
            pExportOperation.ExportFeatureClass(pDatasetName, query10Filter, selection10Set, Nothing, pOutDatasetName, 0)
            feat10Selection.Clear()

            pOutWorkspaceName = Nothing
            featSelection = Nothing
            pExportOperation = Nothing
            selectionSet = Nothing
            pFeatureClass = Nothing
            pDataSet = Nothing
            pDatasetName = Nothing

            '/////////////////////////////////////END OF THIRTY DAY OR LESS

  '//////////////////START 30 DAY OR LESS

            ' Use the IFeatureWorkspace interface to open a feature class.
            Dim featureGDBWorkspace As IFeatureWorkspace = CType(workspaceGDB, IFeatureWorkspace)
            Dim featureClass As IFeatureClass = featureGDBWorkspace.OpenFeatureClass("Under30")


            Dim p10Layer As IFeatureLayer = New FeatureLayerClass
            p10Layer.FeatureClass = featureClass
            p10Layer.Name = "Under30"
            p10Layer.Visible = True

            Dim pSimRend As ISimpleRenderer
            pSimRend = New SimpleRenderer
            Dim pGeoLay As IGeoFeatureLayer
            Dim PFS As ISimpleFillSymbol
            PFS = New SimpleFillSymbol
            With PFS
                .Style = esriSimpleFillStyle.esriSFSHollow
                Dim pcOL As IColor
                pcOL = New RgbColor
                Dim pLineSym As ILineSymbol = .Outline
                pLineSym.Width = 1.25
                pcOL.RGB = RGB(0, 255, 0)
                pLineSym.Color = pcOL
                .Outline = pLineSym
            End With
            pGeoLay = p10Layer
            pSimRend.Label = "Under30"
            pSimRend.Symbol = PFS
            pGeoLay.Renderer = pSimRend

            activeView.FocusMap.AddLayer(p10Layer)

            p10Layer = Nothing
            pSimRend = Nothing
            pGeoLay = Nothing

            '///////////////////END OF 30 DAY OR LESS

View solution in original post

0 Kudos
1 Reply
CaryRoberts
New Contributor III
Well Howdy Folks,
I think I was trying to do to much. UVRenderer is for multiple attributes in one field or column, if Im not mistaken. I could get things to renderer but not display. So plan B, everybody has to have a plan b. I decided to query by date range from the most recent entry (date) and export out to file geodatabase and then load back into arc map and then use the simple renderer. Works much better and not much of a load from the query.  So heres what I did...

'/////////////////////////////START OF 30 OR LESS

            Dim feature10Layer As IFeatureLayer = New FeatureLayerClass
            feature10Layer.FeatureClass = feature10InspectClass
            feature10Layer.Name = "Treatments"
            feature10Layer.Visible = True
            Dim feature10InspectSelection As IFeatureSelection = TryCast(feature10Layer, IFeatureSelection) ' Dynamic Cast

            Dim query10Filter As IQueryFilter = New QueryFilterClass '
            Dim Day10Filter As String = "WHERE [InspectionDate] in (SELECT max([InspectionDate]) FROM VECTOR.SDE.PolyInspection GROUP BY [SourceSiteID])  AND InspectionDate  > Current_TimeStamp -30 and InspectionDate < Current_TimeStamp"
            Dim feat10Selection As IFeatureSelection = feature30Layer
            query10Filter.WhereClause = Day10Filter


            feat10Selection.SelectFeatures(query10Filter, esriSelectionResultEnum.esriSelectionResultNew, False)
            feat10Selection.SelectionChanged()

            Dim selection10Set As ISelectionSet = feat10Selection.SelectionSet
            Dim feat10Cursor As IFeatureCursor = Nothing
            selection10Set.Search(Nothing, True, feat10Cursor)

            Dim pIn10Workspace As IFeatureWorkspace
            pIn10Workspace = workspaceFactory.Open(propertySet, 0)

            pFeatureClass = pIn10Workspace.OpenFeatureClass("VECTOR.SDE.PolyInspection")

         
            pDataSet = pFeatureClass
            pDatasetName = pDataSet.FullName

            pathExport = "c:\GISDATA\Inspection"
         
            pOutWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactory
            pOutWorkspace = pOutWorkspaceFactory.OpenFromFile(pathExport & "\Inspect.gdb", 0)
            pOutWorkspaceDataset = pOutWorkspace
            pOutWorkspaceName = pOutWorkspaceDataset.FullName
            pOutDatasetName = New FeatureClassName
            pOutDatasetName.Name = "Under30"
            pOutDatasetName.WorkspaceName = pOutWorkspaceName

            Try
                Dim pFeatWorkSpc As IFeatureWorkspace
                pFeatWorkSpc = pOutWorkspace
                Dim pfeatClass As IFeatureClass
                pfeatClass = pFeatWorkSpc.OpenFeatureClass("Under30")
                Dim pdaset As IDataset
                pdaset = pfeatClass
                pdaset.Delete()
            Catch exy As Exception
                ' if it doesnt exist then thats OK
            End Try

            'Dim pExportOperation As IExportOperation
            pExportOperation = New ExportOperation
            pExportOperation.ExportFeatureClass(pDatasetName, query10Filter, selection10Set, Nothing, pOutDatasetName, 0)
            feat10Selection.Clear()

            pOutWorkspaceName = Nothing
            featSelection = Nothing
            pExportOperation = Nothing
            selectionSet = Nothing
            pFeatureClass = Nothing
            pDataSet = Nothing
            pDatasetName = Nothing

            '/////////////////////////////////////END OF THIRTY DAY OR LESS

  '//////////////////START 30 DAY OR LESS

            ' Use the IFeatureWorkspace interface to open a feature class.
            Dim featureGDBWorkspace As IFeatureWorkspace = CType(workspaceGDB, IFeatureWorkspace)
            Dim featureClass As IFeatureClass = featureGDBWorkspace.OpenFeatureClass("Under30")


            Dim p10Layer As IFeatureLayer = New FeatureLayerClass
            p10Layer.FeatureClass = featureClass
            p10Layer.Name = "Under30"
            p10Layer.Visible = True

            Dim pSimRend As ISimpleRenderer
            pSimRend = New SimpleRenderer
            Dim pGeoLay As IGeoFeatureLayer
            Dim PFS As ISimpleFillSymbol
            PFS = New SimpleFillSymbol
            With PFS
                .Style = esriSimpleFillStyle.esriSFSHollow
                Dim pcOL As IColor
                pcOL = New RgbColor
                Dim pLineSym As ILineSymbol = .Outline
                pLineSym.Width = 1.25
                pcOL.RGB = RGB(0, 255, 0)
                pLineSym.Color = pcOL
                .Outline = pLineSym
            End With
            pGeoLay = p10Layer
            pSimRend.Label = "Under30"
            pSimRend.Symbol = PFS
            pGeoLay.Renderer = pSimRend

            activeView.FocusMap.AddLayer(p10Layer)

            p10Layer = Nothing
            pSimRend = Nothing
            pGeoLay = Nothing

            '///////////////////END OF 30 DAY OR LESS
0 Kudos