|
POST
|
With CalculateField_management, try removing "PYTHON_9.3". You aren't actually passing an expression, just a value.
... View more
02-10-2015
03:09 PM
|
0
|
0
|
2820
|
|
POST
|
Review the documentation on ArcPy Data Access cursors. The arcpy.da update cursor doesn't have a setValue method, that was for the older-style update cursor. You are effectively mixing up the syntax for the two types of cursors.
... View more
02-10-2015
03:00 PM
|
0
|
1
|
2820
|
|
POST
|
I am not understanding your predicament. Could you post a screenshot or some specific examples of what you would like to see and what you are actually seeing? Regarding your code, you don't have to loop over the dataframes if you aren't going to pass them to ListLayers. Calling ListLayers without a dataframe object will list the layers in all of the dataframes.
... View more
02-10-2015
01:35 PM
|
0
|
0
|
1965
|
|
POST
|
You can't pass ListLayers only a dataframe object, it will fail. At a minimum, and map document or layer needs to be passed. That said, the code still has an issue.
... View more
02-10-2015
01:28 PM
|
1
|
1
|
1965
|
|
POST
|
Have you tried putting in a sleep call to pause the script in between calling serviceStartStop()? I wonder if the server sometimes gets bogged down and file locks aren't released right away. Have you tried re-starting or re-stopping the service that just failed, does it work the second time right after it failed the first time?
... View more
02-09-2015
12:59 PM
|
0
|
0
|
2558
|
|
POST
|
Let's jump over to the other thread to continue the discussion.
... View more
02-09-2015
12:48 PM
|
0
|
0
|
2737
|
|
POST
|
Taking your question at face value, i.e., does SelectLayerByAttribute or similar tools have internal checking for SQL injection, I think the answer is pretty clearly no. I just did a quick check using SelectLayerByAttribute, and I was able to drop a table in SQL Server by injecting extra SQL into the where_clause of the tool. Since MS Access doesn't support multiple SQL statements, it didn't work on personal geodatabases. It also didn't work on file geodatabases, which I am guessing is for the same reason. Of course, I could use less invasive SQL injection with all three to return more records than intended. Although I didn't check all DBMSes and all forms of SQL injection, the fact that I could successfully use some SQL injection with some DBMSes gives a strong indication the tools themselves are not doing any internal checks for SQL injection. I think Esri would say these tools are simply passing SQL along, and that hardening against SQL injection should be taking place elsewhere. Not only would programming internal checks get complicated and quickly, it would likely involve putting big constraints on how SQL is used with those tools. Always a trade off. The tools you reference might not be hardened against SQL injection, but that doesn't mean the floodgates are open. There are still multiple layers in the application stack between these tools and the interface of ArcGIS Server that users will be interacting with. One thing Esri introduced, I can't remember when exactly, is standardized queries for ArcGIS Server. In terms of publishing GP tools, there may be extra precautions in place, I don't know. I am a firm believer in seeing is believing, especially with ArcGIS. Regardless of what the documentation does or doesn't say, I say test it and see for yourself.
... View more
02-09-2015
12:45 PM
|
1
|
0
|
857
|
|
POST
|
In this case, there is no url to close. The url variable in the script is just a string. The script never directly interacts with the file-like object returned by urllib2.urlopen. Instead, the json.load method calls urllib2.open and iterates through the returned file-like object. Once json.load returns, everything it created goes out of scope, including objects returned by urllib2.urlopen.
... View more
02-09-2015
12:09 PM
|
1
|
2
|
2737
|
|
POST
|
Asrujit SenGupta, good points of clarification. Taking those points into consideration, it doesn't change my belief that I don't want ArcGIS assuming the first non-null field it finds is the unique identifier for a database view. Embedding special meaning to column ordering doesn't seem like a sound solution.
... View more
02-09-2015
08:52 AM
|
2
|
0
|
3262
|
|
POST
|
No. The strings can be whatever length you specify, I simply chose 12 because looking over the data, it appeared 12 characters was more than enough to hold all the potential values. If you need a 48 character string, either 'S48' or '|S48' would work. If you are working with Unicode, then use a U in place of an S.
... View more
02-09-2015
08:13 AM
|
0
|
0
|
346
|
|
POST
|
I would argue the "fix" shows the limitations of not allowing views to be registered on the server side. Although implementing this fix will make the prompts go away, it is really just changing band-aids and not addressing the core issue. What happens if the first not-null field isn't the unique identifier?
... View more
02-09-2015
08:07 AM
|
2
|
0
|
2696
|
|
POST
|
The above concept can be expanded to download all the information and create a point feature class. import arcpy
import json
import numpy
import urllib2
fc = #feature class location
if arcpy.Exists(fc):
arcpy.Delete_management(fc)
url = "http://api.metro.net/agencies/lametro/vehicles/"
parsed_json = json.load(urllib2.urlopen(url))
sr = arcpy.SpatialReference(4326) #assuming wgs84 coords but didn't verify
ndtype = numpy.dtype([
('id', 'S12'),
('route_id', 'S12'),
('run_id', 'S12'),
('latitude', 'f8'),
('longitude', 'f8'),
('heading', 'f8'),
('seconds_since_report', 'i4'),
('predictable', '?')
])
vehicles = []
for item in parsed_json['items']:
vehicles.append(tuple(item for k in ndtype.names))
narr = numpy.array(vehicles, ndtype)
arcpy.da.NumPyArrayToFeatureClass(narr, fc, ['longitude', 'latitude'], sr)
... View more
02-08-2015
09:33 AM
|
2
|
6
|
2737
|
|
POST
|
Instead of troubleshooting your current approach, I am going to suggest a different one for a couple of reasons. First, there seems to be lines in your code that aren't doing anything, or at least not contributing to building your table. Fortunately your screenshots can be used to figure out the intent of the code. Second, writing the results to an intermediate/temporary CSV file on disk adds extra steps and slows performance. The NumPy conversion functions in the ArcPy Data Access module (arcpy.da) are very robust, high performing, and I would argue designed for situations just like this one. Although I still find NumPy documentation lacking in clarity in many areas, it is well worth learning and using with and without ArcPy. import arcpy
import json
import numpy
import urllib2
tbl = #table location
if arcpy.Exists(tbl):
arcpy.Delete_management(tbl)
url = "http://api.metro.net/agencies/lametro/vehicles/"
parsed_json = json.load(urllib2.urlopen(url))
LatLongs = []
for item in parsed_json['items']:
LatLongs.append((
str(item['latitude']).encode('utf-8'),
str(item['longitude']).encode('utf-8')
))
narr = numpy.array(LatLongs,
numpy.dtype([('latitude', '|S12'), ('longitude', '|S12')]))
arcpy.da.NumPyArrayToTable(narr, tbl)
... View more
02-08-2015
08:22 AM
|
0
|
7
|
2737
|
|
POST
|
Robert, if you could use Syntax highlighting in the advanced editor, it would make reading and discussing your code easier for commenters. You are getting that error because of the del cur statement in the finally section of your code. In Python error handling, the finally clause is always executed before exiting the try statement, even if there was an error. In your case, you had an error either while creating the cursor object or before, and the cursor object was never instantiated. Since it wasn't instantiated, it can't be deleted in the finally clause. Looking at the code, you should have received another error message before the del cur error. What other messages did you receive?
... View more
02-06-2015
02:42 PM
|
0
|
0
|
2972
|
| Title | Kudos | Posted |
|---|---|---|
| 2 | 4 weeks ago | |
| 1 | 05-29-2026 08:22 AM | |
| 1 | a month ago | |
| 3 | a month ago | |
| 1 | 05-22-2026 05:27 AM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|