POST
|
No. You can set the env workspace to your SDE connection. And by the way, it's 'management'. Great thanks - and oops 😛 EDIT: This has happened to me before -- it hangs up on arcpy.Rename_management() and doesn't work when trying to do this on SDE. I can always use C# or something, but this only took a few minutes to throw together, I don't know why it hangs up.
... View more
10-16-2012
04:37 AM
|
0
|
0
|
357
|
POST
|
Hello - When renaming a featureclass in an SDE db, do I have to include the full name? ex:
for fc in fcList:
arcpy.Rename_managemant(fc,"new_name")
or
for fc in fcList:
arcpy.Rename_managemant(fc,"DATABASE_NAME.new_name")
Thanks
... View more
10-15-2012
11:45 AM
|
0
|
3
|
1147
|
POST
|
What do you get when you do this? _feature.get_Value(_feature.Fields.FindField("MYFIELD")).ToString() cannot perform the operator on "object" and "double" If the value in the field is null, you will not be able to cast it to double. When there is a null value in a field, .net returns a dbnull.value which cannot be cast to a double even if the field type is double. Perhaps this is the problem. Ah, I believe this is probably the case. I will have to check tomorrow, but I'm pretty sure this is my problem. Thanks!
... View more
10-10-2012
01:06 PM
|
0
|
0
|
576
|
POST
|
Hello; I am trying to compare a double field: if ((double)_feature.get_Value(_feature.Fields.FindField("MYFIELD")) > 8.33) And I am getting an invalid cast error. I used the same logic before in my code, and I can't quite figure out why this is not letting me do this. Thanks
... View more
10-10-2012
11:56 AM
|
0
|
9
|
908
|
POST
|
Hello; I am working on creating a dissolved buffer of clusters of point features, so I can then count the number of features the dissolved buffer contains. The buffer is 25 meters and represents a specific feature, so if there is an intersection of buffers (dissolved), it is considered a single feature, and all of the points which created the buffer will fall into this new single polygon and be associated with that polygon. I had some assistance writing some code which ended up working well enough to a point on a file geodatabase that just has the single feature class in it. However, the working version of this will be operating on a database with a dataset. When I try to use the code on the database with a Dataset, it freezes at the ConstructUnion. Is the dataset confusing this? I've tried setting the spatial reference of the geometrybag to the SR of the dataset in the database, but i receive an RPC_E_SERVERFAULT error when I try this. Is there an easier way to create dissolved buffers? Thanks
... View more
10-09-2012
07:01 AM
|
0
|
3
|
494
|
POST
|
Use IFeatureClass::FindField to check if a field exists. If it returns -1, the field isn't in the feature class. if (f.findfield(name) == -1) return; Call the FindField method on the feature class' Fields collection. If it returns -1 then the field doesn't exist. Excellent, thank you both!
... View more
10-04-2012
11:21 AM
|
0
|
0
|
197
|
POST
|
Hello - I am trying to check whether a field exists before attempting to create it. The code I have so far is: private void CreateField(IDataset d, IFeatureClass f, string name, string alias) { // IF FIELD DOES NOT EXIST, RETURN, ELSE, CREATE IField field = new FieldClass(); IFieldEdit fe = (IFieldEdit)field; fe.Name_2 = name; fe.AliasName_2 = alias; fe.Type_2 = esriFieldType.esriFieldTypeString; fe.Length_2 = 20; Invoke(new MethodInvoker(delegate { UpdateLabel.Text = "Creating field " + field.Name + "\nfor " + d.Name.Split('.')[1] + "... "; })); f.AddField(field); } Thanks, Kevin
... View more
10-04-2012
10:40 AM
|
0
|
3
|
688
|
POST
|
*******EDIT******** I figure out everything using the Spatial and Query Filters. See the discussion here on the Windows Application template in the Choosing an ArcGIS for Desktop project template document. When you use the template you will have GUI options for defining your license and the binding code will be automatically added to the project for you. Once you have handled the proper license initialization and product binding you can start writing the ArcObjects code you need to make use of. See the Connecting to geodatabases and databases document for some details on how to connect to your enterprise geodatabase. Then you could use something like IWorkspace.DatasetNames or the geoprocessors list methods to get at the feature classes. Thank you very much, I was able to get a handle on my SDE perfectly. I am now a little stuck on my next task: I want to perform a spatial query; the way I had done it before was using IGeometry and ITopologicalOperator's on IFeatures... however, now I am using just Featureclasses. my code thus far is:
IFeatureWorkspace fws = (IFeatureWorkspace)ws;
IFeatureDataset opDS = fws.OpenFeatureDataset("Operational");
IFeatureDataset baseDS = fws.OpenFeatureDataset("Base");
IEnumDataset opEnum = opDS.Subsets;
IEnumDataset baseEnum = baseDS.Subsets;
IDataset opNext = opEnum.Next();
IDataset baseNext = baseEnum.Next();
while (baseNext != null)
{
IQueryFilter baseFilter = new QueryFilterClass();
IDataStatistics bds = new DataStatisticsClass();
IFeatureClass bfc = fws.OpenFeatureClass(baseNext.Name);
if (baseNext.Name.Equals("FIELD1")) bds.Field = "FIELD1";
else if (baseNext.Name.Equals("FIELD2")) bds.Field = "FIELD2";
else
{
baseNext = baseEnum.Next();
continue;
}
IFeatureCursor bcurs = bfc.Search(null, false);
bds.Cursor = (ICursor)bcurs;
System.Collections.IEnumerator pEnum = bds.UniqueValues;
pEnum.MoveNext();
while (pEnum.Current != null)
{
string f = pEnum.Current.ToString();
//etc etc
}
What I would like to do, is put a spatial filter on this featureclass, so I may use it's Geometry as the intersection for another featureclass I want to select from. The idea is to select features from one featureclass that intersects the above featureclass' field I am getting from "pEnum.Current", and add that unique value into a new field of the selected featureclass. (That is probably a little confusing). Example: I have a polygon containing 3 values in a "DISTRICT" field - 1, 2, and 3. I have a featureclass of points that will fall into one of these polygons. I want to select all the points in "DISTRICT=1" and add the value of "1" to a new field in the featureclass called "DISTRICT" *******EDIT******** I figured out everything using the Spatial and Query Filters.
... View more
09-17-2012
08:36 AM
|
0
|
0
|
201
|
POST
|
Hello, I recently began learning ArcObjects (C#), and successfully create a Desktop Add-in with a dockable window. My next challenge is to use ArcObjects outside of ESRI software (ArcMap, ArcCatalog, etc.) that will connect and list features in an SDE database connection. i.e. - A regular windows form with a single button that when clicked, will connect to the SDE, and fill a listbox with the feature classes within it. Is this possible to use ArcObjects without creating an Add-in? Any tips on how to perform this simple connect and access to featureclasses is much appreciated! Thank you, Kevin
... View more
09-14-2012
05:13 AM
|
0
|
2
|
971
|
POST
|
I think I may have figured out what is wrong. Since the ListFields function is not part of the 'mapping' module, it needs to read the full path of the layer. Replace: for sc in arcpy.ListFields(lyr): with: for sc in arcpy.ListFields(lyr.dataSource): Entire code: for de in searchfile.readlines():
if '--' in de:
fc=de.split('--')
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name==fc[1].split('\n')[0]:
print lyr.name,type(lyr)
for sc in arcpy.ListFields(lyr.dataSource):
if not sc.name in searchfile.readlines():
print sc.name Ah! Perfect, worked like a charm. Thank you for your help Jake, much appreciated.
... View more
09-07-2012
08:43 AM
|
0
|
0
|
646
|
POST
|
Sorry if I was unclear. My user is going to draw a polygon on the map or supply a point (dragging and dropping a push pin onto the map). Whichever geom is supplied (point or polygon) I want to convert that to JSON and send it to a script on my server. When the script on the server gets it I want to intersect that point/polygon with a layer that's stored on the server to find out if it intersects with the polygon/point. At worst it'll probably be a couple of polygons or one point, so you're saying I should convert those polygons/point to at least an in-memory feature layer? Maybe a shapefile or geodatabase feature class may be overkill? I'm very new to ArcGIS Python so I'm not sure what approach I should take to getting this done. What's the best way to store these "layers" on the server? In a geodatabase? What exactly is your code above outputting? A group of strings you are parsing to JSON? What part of your code functions properly at the moment and what is not working? As far as looking for intersection, if you don't want an output layer, shapefile, or featureclass, you can look into SelectLayerByLocation_management: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000072000000 Where you can then run an additional cursor through those 'selected' features. If the cursor is empty, it has not intersected the source layer.
... View more
09-07-2012
08:27 AM
|
0
|
0
|
759
|
POST
|
Can you attach a sample of your text file? It is basically laid out where anything with a '--' in front is the feature class, and what is below are the fields they should contain. --FEATURECLASS1 FIELD FIELD FIELD FIELD --FEATURECLASS2 FIELD FIELD FIELD FIELD FIELD --FEATURECLASS3 FIELD FIELD FIELD FIELD
... View more
09-07-2012
08:13 AM
|
0
|
0
|
646
|
POST
|
Hi Kevin, "for sc in arcpy.ListFields(lyr)" will return a field object. Try specifying the 'name' property for this object. Ex: for de in searchfile.readlines():
if '--' in de:
fc=de.split('--')
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name==fc[1].split('\n')[0]:
print lyr.name,type(lyr)
for sc in arcpy.ListFields(lyr):
if not sc.name in searchfile.readlines():
print sc.name Thanks for the reply - unfortunately, it is still returning the same error ... "[layer]" Does not exist, even though it is printing the layer name at the print lyr.name,type(lyr) line...
... View more
09-07-2012
06:42 AM
|
0
|
0
|
646
|
POST
|
I'm looking to compare a text file of features classes and their fields to those in a map doc. I'm using: for de in searchfile.readlines(): if '--' in de: fc=de.split('--') for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name==fc[1].split('\n')[0]: print lyr.name,type(lyr) for sc in arcpy.ListFields(lyr): if not sc in searchfile.readlines(): print sc where the first few lines are just string parsing the text file to locate the featureclass names. I can get to if lyr.name==fc[1].split('\n')[0]: print lyr.name,type(lyr) which prints the names of the layers fine, along with the type "<class 'arcpy._mapping.Layer'>" edit: However, it returns the following when I try to ListFields: Traceback (most recent call last): File "C:\Python26\ArcGIS10.0\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 323, in RunScript debugger.run(codeObject, __main__.__dict__, start_stepping=0) File "C:\Python26\ArcGIS10.0\Lib\site-packages\Pythonwin\pywin\debugger\__init__.py", line 60, in run _GetCurrentDebugger().run(cmd, globals,locals, start_stepping) File "C:\Python26\ArcGIS10.0\Lib\site-packages\Pythonwin\pywin\debugger\debugger.py", line 655, in run exec cmd in globals, locals File "C:\Users\kyanuk\Desktop\changesearch.py", line 16, in <module> for sc in arcpy.ListFields(lyr): File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 787, in ListFields return gp.listFields(*args) File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 342, in listFields self._gp.ListFields(*gp_fixargs(args))) IOError: "SIDEWALK" does not exist Can ListFields() be used this way for these featureclasses in my map doc?
... View more
09-07-2012
04:24 AM
|
0
|
6
|
1609
|
POST
|
It is possible to change fields alias in layer within mxd by arcpy?(Table Options > Appearance) Have you taken a look at this: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000071000000
... View more
09-05-2012
11:46 AM
|
0
|
0
|
1575
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|