POST
|
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.
... View more
11-23-2010
01:16 PM
|
0
|
0
|
136
|
POST
|
Hi Richard, It turns out we figured out a different way. As I mentioned before, we have X,Y coordinates value of the points table. So I used SQL query to get min and max X, Y values from the selected points, and created a envelope with these coordinates. The map will be zoom to the envelope instead. It works quite fast, because running SQL takes very minimal amount of time. However, this method is only applicable for our particular exercise, for zooming to a layer with definition query I guess it is a still tough question. Many thanks for your help! All the suggestions and code are very helpful!
... View more
11-23-2010
12:30 PM
|
0
|
0
|
835
|
POST
|
Hi Richard, Thank you very much for the code. I have implemented it, and I reckon this selection method is slightly faster than the merging extent by looping through each features. However when it comes to large number of features, the time taken is still quite significant - users have to click on a button and wait for half a minute before map starts drawing. I found it is very fast if I right click on the layer in ArcMap and then click "Zoom to Layer" button. Any idea how that function works? I want the application not only work but also work fast (at least time of response is reasonable). Any solution to improve the speed of zooming to the layer with definition query on? Your suggestion is highly appreciated. Cheers,
... View more
11-22-2010
01:14 PM
|
0
|
0
|
835
|
POST
|
Hi Richard, Hope you had a great weekend. Thank you very much for the sample code. I tested it in the morning, and it worked very well, the definition query seems quite effective. The only problem I found is that if I would like to zoom to the layer extent with definition query, it always zoom to the full extent of the layer. After investigation, I found some code to loop through all the features and join the extent together to get the correct extent. However when large number of points (over 5000 pts) encountered, this method will take significant amount of time (over 20 secs). Do you have any better idea which can get the extent faster? While browsing, I also found the code below quite interesting. According to the description, QueryDef can be used to generate a virtual table or feature class. I tried to get a feature class using this method, however it seems CType method only works for ITable, but not IFeatureClass. I guess if this method can return a feature class, it may be a faster approach than definition query. Any idea how to cast to feature class? or any comments about this method? http://edndoc.esri.com/arcobjects/9.2/NET/3b7e4013-8886-4c51-8cec-77368a1c51bb.htm The IQueryName2 interface Along with creating cursors, a QueryDef can be used to generate a virtual table or feature class. By using the IQueryName2 interface on a co-created table query name object, a QueryDef can be specified. Following this, the name of the virtual table and the workspace it will be created in must be specified through the IDatasetName.Name and IDatasetName.WorkspaceName interfaces. After the object is cast to the IName interface, the IName.Open method can then be called, as shown in the following code example: [VB.NET]
Public Function CreateQueryTable(ByVal workspace As IWorkspace, ByVal queryDef As IQueryDef, ByVal tableName As String) As ITable
' Create a reference to a TableQueryName object.
Dim queryName2 As IQueryName2 = New TableQueryNameClass()
queryName2.PrimaryKey = ""
' Specify the query definition.
queryName2.QueryDef = queryDef
' Get a name object for the workspace.
Dim dataset As IDataset = CType(workspace, IDataset)
Dim workspaceName As IWorkspaceName = CType(dataset.FullName, IWorkspaceName)
' Cast the TableQueryName object to the IDatasetName interface and open it.
Dim datasetName As IDatasetName = CType(queryName2, IDatasetName)
datasetName.WorkspaceName = workspaceName
datasetName.Name = tableName
Dim Name As IName = CType(datasetName, IName)
' Open the name object and get a reference to a table object.
Dim table As ITable = CType(Name.Open(), ITable)
Return table
End Function
Again, many thanks for your help!
... View more
11-21-2010
07:33 PM
|
0
|
0
|
835
|
POST
|
Hi Richard, thank you very much for your reply and the suggestions are very helpful. I am looking to apply a definition query on the data not a select layer. As background info, the point feature class contains the locations of trucks collected every 15 seconds, and the table is updated quite frequently (not real-time tho). There is a master table of the data contains X,Y coordinates for location, and we spatilaise the data into a SDE feature class using these coordinates. The reason we doing so is that we hope this can speed up the drawing. I assume it will take longer time to create points on the fly using X,Y coordinates. Please correct me if I'm wrong. Honestly, I still do not have a clear picture how this thing will work out. I guess what I wanted to do is "open an SDE connection in memory without a layer and only create a prefiltered layer with a definition query", could you please provide me some more info/sample code how to do this? If you have any other better solutions, please advice. Many thanks!
... View more
11-18-2010
03:44 PM
|
0
|
0
|
835
|
POST
|
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!
... View more
11-18-2010
02:08 PM
|
0
|
11
|
3454
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|