|
POST
|
Thanks for the response - I'm pretty new to the this stuff, could you explain how to assign that explicitly? The user is mapped to the DBO schema, so maybe that is the problem.
... View more
02-26-2018
12:14 PM
|
0
|
6
|
3698
|
|
POST
|
EDIT: When I try to access the workspace properties of the connection file, it says that the method workspaceType doesn't exist for describing data. When I use the regular 'Database Connections\myDB.sde' connection I can access the workspace properties just fine. When I run desc.dataType on it it comes back as "File"...how do I make it a workspace? The connection file is obviously not being treated as a workspace, and that's the first issue.. I'm getting an exit code of 0 and no errors when I do this, but it's not finding any feature classes so it's not working as I expect it to. The problem is that I'm creating a connection file using database authentication, setting the workspace to that connection file, then trying to list the feature classes. I get nothing returned. My first thought is that it's a permissions issue but the database user being used for authentication has read and write access, so now I'm not sure what the deal is. import arcpy
arcpy.CreateDatabaseConnection_management(r'C:\Users\xxx\Desktop\GIS_Testing', 'HBMTest.sde', 'SQL_SERVER',
'sde:sqlserver:myServerName', 'DATABASE_AUTH', 'HBMWriter', 'xxx',
'SAVE_USERNAME', 'myDBName')
arcpy.env.workspace = r'C:\Users\xxx\Desktop\GIS_Testing\HBMTest.sde'
featClasses = arcpy.ListFeatureClasses('*')
for fc in featClasses:
print fc When I use the code below, it works and will list the feature classes, but the purpose of using the "CreateDatabaseConnection" and passing in credentials is because eventually this script will be published up on a server where external users will be running it and they won't have my windows authentication to access the database, so I really need to make sure that the above is working. arcpy.env.workspace = r'Database Connections\HBMTest.sde'
featClasses = arcpy.ListFeatureClasses('*')
for fc in featClasses:
print fc Am I missing some silly thing in arcpy or is this more likely a permissions issue? These are the permissions set in SQL Server Mgmt Studio for the user:
... View more
02-26-2018
11:04 AM
|
0
|
9
|
4291
|
|
POST
|
To answer my own question 5 months later, this is definitely doable. Have users zip up their shapefile or a file geodatabase, upload it with your .NET application and unzip it. Write a python script and do all your geoprocessing in there, including connecting to databases and whatever. You could also do geoprocessing with ArcObjects in your .NET application, I simply used python because it's easier for me. Call that python script from your .NET application using ArcObjects IGeoProssessor2 interface. Use search/update/insert cursors to transfer and manipulate data in your python script.
... View more
02-19-2018
10:13 AM
|
1
|
0
|
1451
|
|
POST
|
I have a script that is run using a combination of ArcObjects and a python script. The process starts in C# Arcobjects code, I create a geoprocessor, and then I run a toolbox tool (python script) with uploaded data from the user. The data is uploading successfully, I can see it in file explorer, however my python script says it doesn't exist. Now if I go in the python IDE, the script runs just fine there using the same file in the same location. I'm not sure what's going on. This sets up the toolbox and passes the file geodatabase to the toolbox tool and runs it: //Set up HabitatClassification script
IGeoProcessorResult result;
IGeoProcessor2 gp = new GeoProcessor() as IGeoProcessor2;
string tlbxPath = Server.MapPath("~/ArcToolbox/HabitatMon.tbx");
gp.AddToolbox(@tlbxPath);
IVariantArray parameters = new VarArray();
parameters.Add(geodatabase);
//Run Habitat Classification script
try
{
result = gp.Execute("HabitatClassification", parameters, null);
} Now that I have passed the file geodatabase into the tool, in the python script, I set up the workspace and get the list of feature classes in the FGDB. It perform this step just fine, so clearly it can find the feature class I am looking for and it does, indeed, exist. #Get user uploaded geodatabase and set the workspace to it
uploadedGDB = sys.argv[1]
arcpy.env.workspace = uploadedGDB
#Get the patch feature class out of the geodatabase. Make sure the list created is not empty and that there
#is only one feature class within it.
patchfc = arcpy.ListFeatureClasses("*Patch*")
svyPtFC = uploadedGDB + r"\{0}".format(patchfc[0]) At this point in time, "svyPtFC" looks like this: C:\Users\xxx\Desktop\GIS_NET_Testing\ArcObjectsTesting\ArcObjects\UploadedFiles\NETTesting.gdb_02_17_2018_11_29_23\NETTesting.gdb\Patches It errors out on this line: result = arcpy.GetCount_management(svyPtFC) As a result, I get this displayed on my webpage (and you can clearly see it has the correct path the feature class displayed): Traceback (most recent call last):
File "C:\Users\xxx\xxx\PythonProjects\HabitatClassification.py", line 300, in <module>
result = arcpy.GetCount_management(svyPtFC)
File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\management.py", line 17419, in GetCount
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Rows: Dataset C:\Users\xxx\Desktop\GIS_NET_Testing\ArcObjectsTesting\ArcObjects\UploadedFiles\NETTesting.gdb_02_17_2018_11_29_23\NETTesting.gdb\Patches does not exist or is not supported
Failed to execute (GetCount).
Failed to execute (HabitatClassification).
Anybody know what's going on here? My first thought was the periods in the file path were causing an issue, but in the python IDE it goes through just fine so I'm not sure that's it.
... View more
02-17-2018
08:52 AM
|
0
|
1
|
1656
|
|
POST
|
Assuming I understand your suggestion correctly, that's exactly what I am doing already and this is the problem that arises. I'm using an insert cursor to pass data from the file geodatabase to the SDE database table.
... View more
02-16-2018
04:25 AM
|
0
|
2
|
2212
|
|
POST
|
I'm having a lot of trouble with this and can't seem to figure it out. Ideally, I would like my ArcSDE database float field to have a precision of 3 and a scale of 2, but when I transfer values from a file geodatabase using an insert cursor, it only transfers some of the values and I'm trying to figure out why it's only choosing to transfer some values. Maybe someone can shed some light for me.. I know file geodatabases don't have precision/scale and instead just hold binary type fields. So there can be a lot of decimal places and I see this in some of my values (i.e. 1.47999921 or something like that). What happens when your value has a smaller scale than the field it is being transferred to? I thought that if the scale of the destination database was larger than what is being inserted, it would just put the whole number in and append a zero to the end. So if I had 44.1 as a number to be inserted, it would insert 44.10 if the scale of the destination field was 2. If the scale of the destination database is smaller than what is being inserted, it will truncate the value and insert it. I have roughly 10 float fields. Most of them have values that only have one decimal place, but any field has the potential to have a value with multiple decimal places as some values are calculated dynamically in the script. When I set my precision to 3 and my scale to 1, all records are inserted. When I set my precision to 3 and my scale to 2, only about half the records are inserted. Is this because many of the records only have values with one decimal place, meaning scale cannot actually "scale up"? If this is the case, then you must programmatically add a 0 at the hundredths place in the decimal if you want to maintain a scale of 2 in the destination SDE database, right?
... View more
02-14-2018
06:19 AM
|
0
|
4
|
2432
|
|
POST
|
You're right. I figured it out after I posted this. I was using the summary_field parameter when I shouldn't have, I should have just used both fields in the frequency_field parameter. arcpy.Frequency_analysis(inTable, outTable, ['Code', 'Value'])
... View more
01-25-2018
10:47 AM
|
1
|
0
|
2369
|
|
POST
|
I've got a table that looks something like this: Code Value 11000 1 12000 0 13000 1 11000 0 11000 0 11000 0 12000 0 12000 1 13000 1 I want to find a result that groups by the "code" column and finds which number is most frequently occurring in the "value" column. Result would look something like this: Code Value 11000 0 12000 0 13000 1 I've explored the summary statistics tool and unfortunately there's no option to find the mode (frequency) that a value occurs in a field. Frequency_analysis doesn't do the grouping either. Is there any tool out there made for this already or is this something I'll have to come up with my own code for? It's certainly doable, was just hoping for an easy option already.
... View more
01-25-2018
08:57 AM
|
0
|
4
|
2737
|
|
POST
|
I haven't reached out to them yet, mostly because it's unlikely they have a GIS person on staff that will be able to reproduce the error since it's specifically an error that occurs with the arcpy library. I have seen no reports of the debugger being faulty with other libraries (yet). I will follow up there shortly, but I'd really like to know if this can be reproduced by someone who uses arpcy.
... View more
01-25-2018
06:47 AM
|
0
|
0
|
1127
|
|
POST
|
I would really appreciate if someone could test this and see if they can reproduce the problem I am having. I am working with ArcGIS 10.5 and PyCharm Community Edition 2017.3.3 (the most recent update). I have built a script in PyCharm, and I run it inside of PyCharm. I have PyCharm set to the ArcGIS interpreter (C:\Python27\ArcGIS10.5\python.exe) so I have access to the arcpy library. I have taken a snippet of my code and pasted below. I have attached a zip file with a shapefile for you to run it with (you'll have to change the directory of the output shapefile on the crop_intersect line). If you run it in "Run" mode, it should work. If you run it in "Debug" mode WITHOUT any breakpoints, it should also work. Now... place a breakpoint at the qh_buffer line. Run it in "debug" mode and step over that line when you get to it. It should break and most likely it will give you an error 000735 about invalid parameters/invalid input. Next, remove that breakpoint. Place a new breakpoint further down on the crop_intersect line. Run it in "debug" mode and step over that line when you get to it. It should run successfully to that point and then break giving you an error 000732: Input Features: Dataset #1; #2 does not exist or is not supported. I have checked and rechecked that these errors are invalid and these datasets are being created/the tools are written with correct syntax so the parameters are valid. I know this is a PyCharm IDE problem because I rolled back to a previous version of PyCharm and can run my script succesfully in debug mode with breakpoints, without throwing illegitimate errors. It also clearly is an IDE problem because there is no reason it should work on "run" mode, "debug" mode without breakpoints, and be able to successfully run through a line that previously caused an error when setting a new breakpoint further down the script, but not be able to run succesfully through debug mode with breakpoints. It is related to the breakpoints somehow. Can anyone reproduce this so I can be sure 100% sure it's IDE related and has nothing to do with my computer's configuration? Evidence suggests that the problem lies in how the debugger is interacting with the arcpy library, but I have no idea what the problem is beyond that. If anybody has any ideas, I'd love to hear them. import arcpy, sys
arcpy.env.overwriteOutput = True
svyPtFC = sys.argv[1]
select_query = '"FID" = 9'
qhPolys = arcpy.Select_analysis(svyPtFC, 'in_memory/qhPolys', select_query)
qh_buffer = arcpy.Buffer_analysis(qhPolys, 'in_memory/qh_buffer', '50
Meters')
cropFID = '"FID" = 1'
cropPoly = arcpy.Select_analysis(svyPtFC, 'in_memory/cropPoly', cropFID)
crop_intersect = arcpy.Intersect_analysis([[cropPoly, 1], [qh_buffer, 2]],
r'C:\Users\xxx\GIS_Testing\crp_int.shp')
feature_count = arcpy.GetCount_management(crop_intersect)
print feature_count
... View more
01-25-2018
04:45 AM
|
0
|
2
|
1395
|
|
POST
|
I probably will move to Pro eventually, but not yet. How do you install the 2.7 interpreter on Spyder? I went to Tools > Preferences > Python Interpreter and set it to C:/Python27/ArcGIS10.5/python.exe but when I try to run the code it says it can't find the arcpy module.
... View more
01-23-2018
10:20 AM
|
0
|
1
|
4316
|
|
POST
|
So I transferred this code to a different IDE called Wing. It works in debug there, so it's an issue with PyCharm. Leaving this question marked as "unanswered" because I wonder if anybody knows how to fix PyCharm.
... View more
01-23-2018
08:56 AM
|
0
|
3
|
4316
|
|
POST
|
EDIT: I moved my code to a different IDE and it works in debug there. It's a problem with PyCharm, anybody know how to fix it? I have no idea why this is happening, it just started occurring today. My python script runs fine as long as I don't run it in debug mode... in debug mode I get all sorts of errors about datasets not existing or parameters being invalid for certain tools. When I take that chunk of code causing issues, put it in it's own script and run it, it runs just fine. All the datasets DO exist, they all DO have features, all the arcpy statements are written correctly, and for the life of me I cannot fix this. I NEED to be able to use debugger, this is getting ridiculous. I'm using PyCharm IDE, just updated to the most recent version. I haven't had this problem before with PyCharm, has anybody else? I'm wondering if it's something with the IDE. I haven't changed much of my code today at all, maybe a few lines. I think part of the problem is creating/using in_memory feature classes. To fix this, I attempted to hardcode some of the outputs to my directory instead of using in_memory but it just changed the error message in debug mode to something else, rather than fixing the issue. This has been a long process of changing error messages and I couldn't describe them all to you if I tried, but one of them arose after trying to run the buffer tool: qhPolys = arcpy.Select_analysis(svyPtFC, 'in_memory/qhPolys', select_query)
qh_buffer = arcpy.Buffer_analysis(qhPolys, 'in_memory/qh_buffer', '50 Meters') The error message received here said that qhPolys didn't exist. I changed the in_memory/qhPolys to be hardcoded to my output directory. Still the same error occurs in debug ONLY. Again, I reiterate, the script works just fine if I let it run normally without debugging. After a bunch of messing around trying to figure out the issue, I eventually just reset the above coded lines to in_memory and debug worked fine through those (for no reason whatsoever, apparently) until a few lines down. Line 5 below started to give me issues saying that "ERROR 000732: Input Features: Dataset # 1;# 2 does not exist or is not supported" qhPolys = arcpy.Select_analysis(svyPtFC, 'in_memory/qhPolys', select_query)
qh_buffer = arcpy.Buffer_analysis(qhPolys, 'in_memory/qh_buffer', '50 Meters')
cropFID = '"FID" = {0}'.format(cropPatch)
cropPoly = arcpy.Select_analysis(svyPtFC, 'in_memory/cropPoly', cropFID)
crop_intersect = arcpy.Intersect_analysis([[cropPoly, 1], [qh_buffer, 2]],
r'C:\Users\xxx\GIS_Testing\intersect2.shp') I added these lines to determine that cropPoly and qh_buffer are, indeed, populated with features and shouldn't be giving any error messages. When I tested this with debugging on, it magically stepped through this without throwing the above error message like before (what the ****) feature_count2 = arcpy.GetCount_management(cropPoly)
feature_count3 = arcpy.GetCount_management(qh_buffer)
if feature_count2 > 0 and feature_count3 >0:
crop_intersect = arcpy.Intersect_analysis([[cropPoly, 1], [qh_buffer, 2]],
r'C:\Users\xxx\GIS_Testing\intersect2.shp') THEN on the next line, I got this error message: "Error 000735: Input Row: Value is required" feature_count = arcpy.GetCount_management(crop_intersect) crop_intersect has features. I went into ArcMap and checked the attribute table, there are records there to count. THERE IS NO REASON I SHOULD BE GETTING THIS ERROR MESSAGE. I'm way beyond frustrated at this point. I have shut down and restarted my computer even to see if it was just a glitch. Why won't my script work in debug mode but it works just fine without it?
... View more
01-23-2018
08:43 AM
|
0
|
8
|
4739
|
|
POST
|
I figured out how to do it, I think. I was using Select but you could use MakeFeatureLayer and then use SelectLayerByAttribute on that. Then you can delete the selected set using DeleteFeatures without creating a new output shapefile/feature class. It does appear to do what I need it to do, whether it's truly the "right" way to do it or not.
... View more
01-03-2018
01:46 PM
|
0
|
0
|
2177
|
|
POST
|
Is it possible to delete features from an existing dataset without creating a new output feature class with ArcPY? I have a dataset I'm working with and it gets altered over and over again throughout the whole script. Creating a new output feature class every time is going to get very very confusing. Is there no way to delete features without creating a new output file? It's not like you can select records and delete them from the main dataset since Select creates a new output file as well. Anything you delete from a selected set won't be reflected in the "real" dataset since selections are separate files. Am I wrong in this logic?
... View more
01-03-2018
12:50 PM
|
0
|
2
|
2712
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-18-2020 10:31 AM | |
| 2 | 09-16-2025 02:17 PM | |
| 3 | 09-12-2025 09:26 AM | |
| 1 | 08-16-2023 05:11 PM | |
| 1 | 02-27-2024 06:48 AM |
| Online Status |
Offline
|
| Date Last Visited |
09-16-2025
02:16 PM
|