POST
|
I've made the following change to the syntax of the query. But now I have another issue. Because I have a variable (int _val) and assigned it to 0, thats the only value thats being returned, 0. Whatever I assign _val to, whether 0 or 100, it outputs that value. It is not being used properly in my code. I'll have to trace through some more. In the same sense, if I don't assign it to a value at the top, of course I get an error when I use it at the bottom right before the curly beacket in the "Try" function. (Error: Use of unassigned local variable '_val' So, yes, I'll have to trace through to see what the issue is. Thanks for your help though. ------------------ I actually just realized my own mistake in why I wasn't getting the wrong value. My query wasn't returning anything because there was no data in it. A database change, (that I wasn't aware of) had occurred where we are migrating data to and from different tables. Database 101, make sure the table you are querying has data in it. lol But again, thanks for your assistance on everything.
... View more
04-28-2014
06:13 AM
|
0
|
0
|
396
|
POST
|
Thanks for your response. I think I may have got it. I created a function myself. The script is below:
public static class Utilities
{
public static IFeatureWorkspace m_FeatureWorkspace =null;
private static IFeatureWorkspace m_ReadOnlyWorkspace = null;
private static string _path = "C:\\Users\\Me\\MyStuff\\MyProject\\myFile.sde";
public static IFeatureWorkspace connect()
{
IWorkspaceFactory _workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();
m_ReadOnlyWorkspace = (IFeatureWorkspace)_workspaceFactory.OpenFromFile(_path, 1);
return m_ReadOnlyWorkspace;
}
}
I believe this to be correct and working. What do you think? I guess I would need to be sure, so I am also working on a conditional statement to "do something" or output a message whether I am actually connected to the sde file or not.
... View more
04-28-2014
05:50 AM
|
0
|
0
|
912
|
POST
|
So I've put together the following code:
public static int FirstQuery()
{
int _val = 0;
ICursor _pCursor = null;
try
{
IFeatureWorkspace _pfeatureWorkspace = Utilities.connect();
/*
* Query below will iterate through several rows of returned data from query
* I need a query to return a single value
*/
IQueryDef _pdq = _pfeatureWorkspace.CreateQueryDef();
_pdq.Tables = PersonsTable.TableName;
_pdq.SubFields = PersonsTable.PERSON_ID;
_pdq.WhereClause = PersonsTable.FIRST_NAME = "JAMARI";
_pCursor = _pdq.Evaluate();
int lIndex = _pCursor.FindField(_pdq.SubFields);
IRow _pRow = _pCursor.NextRow();
if (_pRow != null)
{
object _myObject = _pRow.get_Value(lIndex);
if (_myObject != null)
{
_val = Convert.ToInt32(_myObject);
return _val;
}
}
return _val;
}
catch (Exception)
{
return -1;
}
finally
{
if (_pCursor != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(_pCursor);
}
}
} This is a function that runs a query to output the id associated to my name (We have a PERSONS table with names and Id's in our database). I am passing this value to another function that outputs the value in a simple MessageBox. That function is below:
protected override void OnClick()
{
int _queryVal = 0;
MessageBox.Show("Jamari was here");
_queryVal = BasicQuery.FirstQuery();
MessageBox.Show("Query result is: " + _queryVal);
}
However, everytime I run it, it outputs the value -1. Am I missing something? I should get a value other than -1 because I know the ID associated with my name. I've been trying and changing and testing different things but nothing is quite working. Could it be the way I have my query set up; particularly in my lIndex variable? I'm almost there, but I have one minor road block that I'm just not seeing yet.
... View more
04-27-2014
07:56 AM
|
0
|
0
|
396
|
POST
|
Thanks for your input Mody and cc4ever. THe logic and the code snippet does makes sense and it does make more sense to just do NextRow once (and not, per say, loop through it) if you're trying t odisplay one value from a query. Just wanted some kind of confirmation on which direction to go and if there was another method besides ICursor and IRow to get a single value. THanks alot. I'll give this a shot and try a few examples and see what I come up with.
... View more
04-27-2014
07:13 AM
|
0
|
0
|
396
|
POST
|
Using C#, arcobjects and IQueryDef, I've been learning how to write queries to return rowsets and multiple results. I would also use ICursor and Irow to loope through each record from the cursor. This is great for multiple results but I am having trouble returning one result. I want to run a query to return a single integer from a query. Would I need to have ICursor or IRow still? I've been looking online for examples but everything incorporates a ICursor / IRow. I was using something along these lines:
private static List<object> GenericQuery(string sQueryColumn, string sFrom, string sWhere)
{
// connect to workspace
List<object> myObjects = new List<object>();
IQueryDef pQD = pFeatureWorkspace.CreateQueryDef();
pQD.Tables = sFrom;
pQD.SubFields = sQueryColumn;
pQD.WhereClause = sWhere;
ICursor pCursor = pQD.Evaluate();
//Loop through each of the records in the cursor
IRow pRow = pCursor.NextRow();
while (pRow != null)
{
object myObject = myObject = pRow.get_Value(lIndex);
myObjects.Add(myObject);
//Increment the cursor
pRow = pCursor.NextRow();
}
Of course, there would be an actual table name, subfields, and a where clause there. I would use ICursor to evaluate my query def but I just want one result. So if I created a function that returned an integer with a query that just returned an integer, would I still need ICursor / IRow? Not sure how to go about this. Not too many examples online. Any feedback on this would be greatly appreciated. Thanks in advance.
... View more
04-26-2014
06:38 AM
|
0
|
6
|
1012
|
POST
|
Working in C# I have been working with arcObjects and researching connecting to a geodatabase. I already have a working .SDE file created. Again, my lack of understanding and the convolution from the ArcGIS resource center is causing me confusion. I am not sure where to start exactly. I have bits and pieces as far as understanding. I believe I must start with an IFeatureWorkspace. From this I am supposed to use sdeWorkspaceFactoryClass, correct? I was going to use a line of code as follows:
IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();
m_ReadOnlyWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(nameOfFile, 0);
where "m_ReadOnlyWorkspace" is my created workspace and "nameOfFile" is my sde file. Should my "nameOfFile" variable be the entire path to the .SDE file or just the name of the file? Once I am able to make this line work, I should be [connected] to the database and able to run a query from a table correct? Am I missing any intermediate steps in the process? Any help or insight on these issues / questions would be greatly appreciated. Thanks in advance.
... View more
04-25-2014
08:53 AM
|
0
|
3
|
3750
|
POST
|
I appreciate your code snippet, but I still have no real understanding of all the misc other function calls (SimpleMarkerSymbol, MarkerElement, etc). I can look up their meaning but do not understand really why they are needed or why they should/would be needed. Like I said, I'm trying to understand and learn and create all from scratch. Code without explanation in my context won't really help And because I am using C# and don't exaclty know of all the references needed to import, it makes it a tad bit more challenging. Thanks for the post though.
... View more
04-24-2014
11:20 AM
|
0
|
0
|
555
|
POST
|
So I think it's starting to come around. I was able to add a "box" to an mxd document. It was more so a legend but its a start. My code is below: protected override void OnClick()
{
IMxDocument _mxDoc = ArcMap.Application.Document as IMxDocument;
IMap _map = _mxDoc.FocusMap;
IActiveView _activeView = _mxDoc.ActiveView;
// IActiveView _activeView = _map as IActiveView;
IPageLayout3 _pageLayout = _activeView as IPageLayout3;
Double posX = 2.0;
Double posY = 2.0;
Double legW = 5.0;
IGraphicsContainer _GraphContain = _pageLayout as IGraphicsContainer;
IMapFrame _mapFrame = _GraphContain.FindFrame(_map) as IMapFrame;
ESRI.ArcGIS.esriSystem.UID _uid = new UIDClass();
_uid.Value = "esriCarto.Legend";
IMapSurroundFrame _mapSurroundFrame = _mapFrame.CreateSurroundFrame((ESRI.ArcGIS.esriSystem.UID)_uid, null);
IQuerySize _querySize = _mapSurroundFrame.MapSurround as IQuerySize;
Double w = 0;
Double h = 0;
_querySize.QuerySize(ref w, ref h);
Double aspectRatio = w / h;
IEnvelope _envelope = new EnvelopeClass();
_envelope.PutCoords(posX, posY, (posX * legW), (posY * legW / aspectRatio));
IElement _element = _mapSurroundFrame as IElement;
_element.Geometry = _envelope;
_GraphContain.AddElement(_element, 0);
_activeView = _mxDoc.ActiveView;
if (_activeView is IPageLayout)
{
MessageBox.Show("You're in layout view");
}
else if (_activeView is IMap)
{
MessageBox.Show("You're in Data view");
}
_activeView.Refresh();
} I'm thinking I need to add a TextElement, as well as TextElement properties to the Graphics Container instead of just element properties. It is all grouped together with no real structure, but its a work in progress. What do you think?
... View more
04-23-2014
11:38 AM
|
0
|
0
|
555
|
POST
|
oooo000 I see....Ok. I'm beginning to get a better understanding of what needs to be done. Those ArcObjects sites don't explain things in dumb-downed terms for users who have never really used arcObjects (i.e. me). Thanks again. I now have somewhat of a pseudo-coded plan of attack.
... View more
04-16-2014
05:33 AM
|
0
|
0
|
555
|
POST
|
I am now working within a form. I've added a button to the form. I'm having trouble adding the 'ITextElement' to the mxd from clicking the button on the form. Is that possible? My code snippet is below. Please help, again!! namespace MapDecorator { public partial class Form1 : Form { private IElement _element; private IGlobeGraphicsElementProperties _elementProperties; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string[] files = System.IO.Directory.GetFiles(@"C:\This"); this.comboBox1.Items.AddRange(files); } private void button1_Click(object sender, EventArgs e) { this.Close(); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void PlaceText_Click(object sender, EventArgs e) { ITextElement _textElement = new TextElementClass(); _element = _textElement as IElement; ITextSymbol _textSymbol = new TextSymbolClass(); _textElement.Text = "Test me"; this._element = new TextElementClass(); } } } Thanks in advance
... View more
04-15-2014
07:58 AM
|
0
|
0
|
555
|
POST
|
Ok, I think I'm good until I hit the IF statement. I'm working in C# and not necessarily sure of how to write those statements in the "C#" way. Wait,..scratch that. It worked. Using your logic and some syntax adjustments, I was able to determine which view I was in. Thank you so much.
... View more
04-11-2014
08:46 AM
|
0
|
0
|
746
|
POST
|
I am having some trouble. I have tried the following: protected override void OnClick() { IElement _element; IMxDocument _mxDoc = ArcMap.Application.Document as IMxDocument; IMap _map = _mxDoc.FocusMap; IActiveView _activeView = _map as IActiveView; IPageLayout3 _pageLayout = _activeView as IPageLayout3; if (_activeView is IPageLayout3) { ITextElement _textElement = new TextElementClass(); _element = _textElement as IElement; ITextSymbol _textSymbol = new TextSymbolClass(); _textElement.Text = "Test me"; } else { MessageBox.Show("This tool only functions in layout view"); } _activeView.Refresh(); } But I am receiving the message box from the else statement. Am I even doing this right?? Please help??
... View more
04-10-2014
10:06 AM
|
0
|
0
|
746
|
POST
|
If "by the same" you mean they both provide a way to set and display text, then yes, they are essentially the same in that regard. You could check the ArcObjects API, but the .NET version is really impossible to find anything unless you are willing to click on every tree node in every namespace. Yes, that's what I meant. I think at this point, I've nearly gone through every tree node in every namespace. Completely new to this Esri ArcObjects thing. Clearly I'm still learning, but thanks so much for your assistance / help. I should be able to get somewhere now.
... View more
04-09-2014
10:26 AM
|
0
|
0
|
746
|
POST
|
Thanks for your input. I will take a look. I'm assuming the ITextElement, in simplistic terms, is a box that contains text? My confusion stems from wanting a text element or a textbox element. But again I assume they are essentially the same. Still getting used to Esri ArcObjects and training m mind to conform to their framework.
... View more
04-09-2014
06:32 AM
|
0
|
0
|
746
|
Title | Kudos | Posted |
---|---|---|
1 | 10-02-2014 12:34 PM | |
1 | 09-29-2014 09:10 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|