Select to view content in your preferred language

How to select a subset from a feature class and add the subset as a layer in ArcMap?

4087
11
11-18-2010 02:08 PM
ShanshanZhou
Emerging Contributor
Hi, I am working on a application developed on .NET platform that interacts with ArcMap, and I would like to know if the proposed process I need to develop can be done or not. If can, how to do it. Your help and advices are highly appreciated.

Basically, we have a feature class in ArcSDE that contains about 20 million of points. Each point feature has a "NAME" field, and normally around 50 - 2000 points are associated with one pacific NAME value. I have developed a form using VB.NET to allow user to input the NAME value they would like to show on the map. My question is: how can I select a subset of the point features based on the user input and display them as a layer in ArcMap.

As I mentioned before, there are huge volume of point features, so I don't want to load the whole feature class into ArcMap - it takes ages to draw. I only want to select a subset of the points from ArcSDE feature class, and show these points in map. Is this difficult to do? I haven't found any relevant information on the net so far.

Please let me know if I didn't explain the question clearly. Thanks in advance for your help!
0 Kudos
11 Replies
ShanshanZhou
Emerging Contributor
Hi Richard,

I connect to Oracle to perform SQL, not via SDE or using layer in the map. I don't think ESRI support max or min function in attribute query. It seems you only can define the WHERE clause but not the SELECT part.

Here is the code I use to get the X, Y value. The where clause in my SQL is the same as the definition query in the point layer.

        Dim SQL As String
        Dim WhereClause As String
        WhereClause = " WHERE NCR_ID IN (" + ptsStr + ")"
        SQL = "SELECT MIN(X) AS MIN_X, MIN(Y) AS MIN_Y, MAX(X) AS MAX_X, MAX(Y) AS MAX_Y FROM TBL_POINTS" + WhereClause
        
        Dim cmd As New OracleCommand(SQL, cn)
        cmd.Connection.Open()
        Dim rdr As OracleDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
       
        While rdr.Read        
            minx = rdr("MIN_X")
            miny = rdr("MIN_Y")
            maxx = rdr("MAX_X")
            maxy = rdr("MAX_Y")
        End While
        rdr.Close()
        cmd.Dispose()
      
        'Set up the envelope for the new map extent
        Dim pEnv As IEnvelope = New Envelope
        pEnv.PutCoords(minx, miny, maxx, maxy)
        pEnv.Expand(1.1, 1.1, True)
        pMxDoc.ActivatedView.Extent = pEnv

        'Refresh the map
        pMxDoc.ActivatedView.Refresh()


To answer you question, I wanna zoom to the layer which has a definition query on it, so extent should be the overall extent of the valid features only. I don't know why, but the "zoom to layer" function works in my ArcMap desktop, when I right click on the layer (with definition query) and click on "Zoom to Layer", the map zooms to the valid extent (not the whole extent of the layer). And when it comes to VB.NET, that zoom to layer function doesn't behave that way any more, it zooms to the extent of the entire layer. I am a bit confused actually.
0 Kudos
RichardFairhurst
MVP Alum
...To answer you question, I wanna zoom to the layer which has a definition query on it, so extent should be the overall extent of the valid features only. I don't know why, but the "zoom to layer" function works in my ArcMap desktop, when I right click on the layer (with definition query) and click on "Zoom to Layer", the map zooms to the valid extent (not the whole extent of the layer). And when it comes to VB.NET, that zoom to layer function doesn't behave that way any more, it zooms to the extent of the entire layer. I am a bit confused actually.


Thanks for the code.  Probably connecting to Oracle is the fastest, but I think that this is supposed to be possible thorugh one of the ArcObjects interfaces.  I know that IDataStatistics is supposed to be able to do this kind of output, but probably cannot do the query in one shot like your code and is probably not as fast.

The behavior difference of Zoom to Layer could be dependent on how the menu command percieves the state of the layer being manipulated by ArcObjects.  Some ArcObjects actions occur in memory and do not get seen by the user level interface until the code stops or certain events are triggered.  I don't think I ever tried that command the way you have, but it may be useful outside of code even if the code doesn't work.  Thanks for the reply.
0 Kudos