|
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
|
2663
|
|
POST
|
Let's jump over to the other thread to continue the discussion.
... View more
02-09-2015
12:48 PM
|
0
|
0
|
2857
|
|
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
|
899
|
|
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
|
2857
|
|
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
|
3390
|
|
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
|
370
|
|
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
|
2823
|
|
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
|
2857
|
|
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
|
2857
|
|
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
|
3065
|
|
POST
|
That is another approach. Although I like working with SQL, building SQL expressions via Python and passing them to Esri tools seems to be a hang up for lots of folks, so I decided against suggesting a where_clause, but it will work.
... View more
02-05-2015
08:57 AM
|
1
|
1
|
2118
|
|
POST
|
Haven't tested, but try: import arcpy
from arcpy import env
env.workspace = r"C:\SouthA\Bolivia.gdb"
listFCs = arcpy.ListFeatureClasses("*")
for fc in listFCs:
with arcpy.da.UpdateCursor(fc, ["field1", "field2", "field6", "field7"]) as cur:
for row in cur:
if 0 in row:
cur.deleteRow()
... View more
02-05-2015
06:54 AM
|
2
|
3
|
2118
|
|
POST
|
For starters, I encourage you to read up on the Arcpy Data Access module (arcpy.da). The cursors in the data access module are newer, more robust, and higher performing than the older cursors. I gotta step out but will post some code when I get back if someone hasn't already.
... View more
02-05-2015
06:48 AM
|
1
|
4
|
2118
|
|
POST
|
I am using ArcGIS Pro 1.0.0. Yes, it works, I tested it before posting the other day. I just tested it again, and it worked without any issues: arcpy.MakeFeatureLayer_management(r"D:\tmp\test.sqlite\webMerc1","webMerc")
<Result 'webMerc'> It is helpful if you can post specific code and error messages, especially since it keeps not working for you. I am not sure what is different between our machines. I recently re-imaged my machine using Windows 7 64-bit Enterprise Edition. I installed ArcGIS 10.3 before I got around to putting ArcGIS Pro on the machine, but the installations should be compartmentalized from each other. Anyhow, I was loading SQLite databases into Pro with the beta versions and pre-releases before I re-imaged my machine. Have you tried creating a layer file in ArcGIS Desktop that points to a SQLite data source and then load that layer file into ArcGIS Pro? As has been pointed out, SQLite isn't officially supported yet, so the best approach in the interim might be to find an alternate data store.
... View more
02-05-2015
06:44 AM
|
1
|
1
|
6363
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-11-2026 07:04 AM | |
| 1 | 07-17-2026 06:54 AM | |
| 2 | 07-06-2026 12:29 PM | |
| 1 | 07-06-2026 12:00 PM | |
| 2 | 06-05-2026 10:30 AM |
| Online Status |
Offline
|
| Date Last Visited |
Wednesday
|