|
POST
|
I have a python script which runs fine but takes far too long to run so I'm hoping some of the more experienced python coders can offer suggestions about where I can be more efficient. The script I've written will hopefully be run as a windows task at a given time interval to constantly update a table in SDE which will be consumed by a web map. As I said, the table is in SDE but the source data is a table in an Access database. Due to a daily database maintenance period, the Access database cannot be touched unless the presence/absence of two files is true (hence the conditional statement about the files). If it's ok to proceed, here's what happens: Delete all records from the SDE table Connect to the Access database Step through the records in an Access Query and transfer that information into the SDE table It took roughly 20 minutes to transfer 2200 records. That seems WAY too slow so any suggestions would be greatly appreciated! Here's the code: import sys import os import pyodbc import arcpy from datetime import datetime from arcpy import env file01 = r"\\Path\to\File01" #This file must exist file02 = r"\\Path\to\File02" #This file must NOT exist expression = '1=1' #SQL shorthand which select all records theTable = "tblGageData" # The tables within DIADvisor must not be accessed during its daily database maintenance. # OneRain recommends checking for the existence and non-existence of two specific files. # If both conditions are true, it is safe to proceed with accessing the data within the # dvLive Access database if os.path.exists(file01) and not os.path.exists(file02): print "Processing start time: " + str(datetime.now()) env.workspace = r"Database Connections\SdeConnection.sde" try: # Set some local variables tempTableView = "gageTableView" # Execute MakeTableView arcpy.MakeTableView_management(theTable, tempTableView) # Execute SelectLayerByAttribute to select all records arcpy.SelectLayerByAttribute_management(tempTableView, "NEW_SELECTION", expression) # Execute GetCount and if some records have been selected, then execute # DeleteRows to delete the selected records. if int(arcpy.GetCount_management(tempTableView).getOutput(0)) > 0: arcpy.DeleteRows_management(tempTableView) # Now connect to the DIADvisor access database and import the most recent data # This requires the PYODBC module for Python cstring = r'DRIVER={Microsoft Access Driver (*.mdb)};DBQ=Path\to\Access\Database\Database.mdb;Provider=MSDASQL;' conn = pyodbc.connect(cstring) cursor = conn.cursor() sqlString="SELECT * FROM LAST3DAYS" counter = 0 # Loop through the results returned via the ODBC connection for cRow in cursor.execute(sqlString): curSensorId = cRow.SENSOR_ID curEpoch = cRow.EPOCH curData = cRow.DATA counter += 1 #Insert a new row into the SDE table with the current DIADvisor record's information curSde = arcpy.InsertCursor(r"Database Connections\SdeConnection.sde\tblGageData") row = curSde.newRow() row.SENSOR_ID = curSensorId row.EPOCH = curEpoch row.DATA = curData curSde.insertRow(row) # Close the ODBC connection and perform some variable cleanup cursor.close() conn.close() del row del conn del curSde del cRow del cursor print "Number of record(s) in the DIADvisor database: " + str(counter) print "Processing end time: " + str(datetime.now()) except Exception as e: # If an error occurred, print line number and error message import traceback, sys cursor.close() conn.close() tb = sys.exc_info()[2] print "Line %i" % tb.tb_lineno print str(e) else: sys.exit()
... View more
12-10-2012
08:35 AM
|
0
|
12
|
2172
|
|
POST
|
I can think of one way of doing this but it may not fit in with how you've designed your website. Here it goes- On your webpage, use an IFRAME for the map. In the IFRAME, load an HTML page of your javascript API map that uses 100% of the browser's width and height. In your map initialization javascript, include some code to check the URL to see if any parameters were passed to it. I've done this before and it looked something like this: [INDENT] //Evaluate the URL of this HTML page to determine if any parameters were passed with it
var htmlPagePath = window.location.toString();
var qLocation = htmlPagePath.indexOf('?');
if (qLocation < 1)
{
passedLatLong = false;
}
else
passLatLong = true;
}
.
.
.
//If a coordinate location was passed as a parameter, zoom the map to it
if (passedLatLong)
{
//Extract the lat/long coordinates passed as a parameter with the URL
var coordStr = window.location.toString().substr(qLocation + 1,window.location.toString().length);
var coords = new Array();
coords = coordStr.split(',');
//Create a lat/long point
var bridgeLoc = new esri.geometry.Point(coords[0],coords[1], new esri.SpatialReference({wkid:4326}));
//set the map extent based on the lat/long coordinate passed. The coordinate must be converted
//to Web Mercator since the web services used have been defined with that projection..
map.setExtent(pointToExtent(map,esri.geometry.geographicToWebMercator(bridgeLoc),3));
}
Hopefully you now see where I'm going with this. When your users click on your "external link" on the page, have the onClick event reload the IFRAME but append a parameter to the URL (FID, lat/long, etc) and then your map init() routine will recognize the parameter and respond accordingly.
[/INDENT] Again, this approach may not fit in with what you want to do but it's possible. Good luck! Steve
... View more
11-30-2012
09:44 AM
|
0
|
0
|
554
|
|
POST
|
With respect to your second question, you could accomplish this using a dojo listener event based on a row click event. Here's an example I'm using to zoom to a feature represented by a row in a datagrid: dojo.connect(dijit.byId("grid"), 'onRowClick', function(e) {
var rowdata = grid.getItem(e.rowIndex);
var theId = rowdata.OBJECTID;
theFeatureLayer.clearSelection();
var query = new esri.tasks.Query();
query.objectIds = [theId];
theFeatureLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW,function(features){
var theExtent = features[0].geometry.getExtent().expand(2.5);
map.setExtent(theExtent);
});
});
In your situation, just swap the field name in my example (OBJECTID) for the name of your field containing the URL. The rest of the routine would be pure javascript to open a URL in a new window: //Get the screen resolution and scale it back 10% (for use with the new window)
var theWidth= 0.9 * screen.width;
var theHeight= 0.9 * screen.height;
var theOptions = 'height=' + theHeight + ',left=25,top=25,width=' + theWidth;
window.open(theUrl,'_blank',theOptions);
... View more
11-30-2012
07:31 AM
|
0
|
0
|
709
|
|
POST
|
Are the services coming from SDE? If not, double check the paths for the datasets. I always get tripped up because my map service used network drive letters when they should have been UNC format. Remember, your server won't know what a G, L, or Z drive is so that's one reason that features won't show up in a map service.
... View more
11-29-2012
09:06 AM
|
0
|
0
|
974
|
|
POST
|
Have a look at this sample. It's primary purpose is to demonstrate how to use dojo charts with popups but the sample also shows you an example of using a tabbed container within a popup.
... View more
11-29-2012
07:27 AM
|
0
|
0
|
509
|
|
POST
|
I hope this is the appropriate forum for this- Our organization is trying to convert an old, kludgy stream gage web app to a GIS web app using the javascript API. We're currently running ArcGIS Server version 10 but should upgrade to 10.1 at some point. We're not talking about a lot of data- only 8-12 stream gages. The data itself is stored in an Access database and we'd like the map service to have a refresh interval of 5 or 10 minutes. The map service won't be a GIS dataset per se because I plan to construct a featureLayer on the fly like a JSON feed due to some custom symbology requirements. As such, I'll be publishing a particular table from that Access database which contains the last three days worth of values from each gage since my web map popups will create some hydrographs. From experience, map services based on file based sources (shapefiles, etc) lock up the files which will prevent the update process outside of the GIS realm. SO- how do I publish my data for consumption by a web map that doesn't prohibit any processes outside of GIS from completing an update??
... View more
11-28-2012
08:37 AM
|
0
|
1
|
2241
|
|
POST
|
Hi Alex, Sorry to bump but I'm curious if you ever resolved this for the app you were working on? Steve
... View more
11-14-2012
10:55 AM
|
0
|
0
|
881
|
|
POST
|
Provided by ESRI? No- with one qualification. If you are under maintenance for any of the ArcGIS Desktop applications, you should also have the ESRI Data and Maps bundle of datasets which I believe includes a shaded relief image. These used to be provided as a set of DVDs but now is a download when you download your software. Your best non-ESRI source for this information would be the USGS: http://earthexplorer.usgs.gov/ You might also find additional data at your state or local level depending on your area of interest.
... View more
11-08-2012
01:45 PM
|
0
|
0
|
286
|
|
POST
|
Right you are again, Derek. I've defaulted to using featureLayers due to my need for popup content but this particular layer I'm dealing with would be fine as a dynamicMapService. Thanks for setting me straight! Steve
... View more
11-01-2012
10:39 AM
|
0
|
0
|
542
|
|
POST
|
Like Rich states, maybe you can attempt to access the service before really needing it. Perhaps you can alter the code snippit found in the API documentation for ESRI.Request to verify that the service is up and running: esri.request
... View more
11-01-2012
09:55 AM
|
0
|
0
|
592
|
|
POST
|
Maybe try specifying the field Alias? Whenever I accessed the attributes of results, I used the format of features[0].attributes.<the attribute Field Name>". Note the use of a period instead of array brackets ( [ ] ). Like all things Javascript, the field name WILL be case sensitive. You could also try quoting the field name in your specification: features[0].attributes['<the attribute field name>']
... View more
11-01-2012
09:48 AM
|
0
|
0
|
468
|
|
POST
|
I have a polygon SDE dataset that I have added to my webmap as a feature layer. The layer is a dynamic map service and in the MXD/MSD, I have labeling turned on (standard- not Maplex). If I go to my REST Services directory and click on the "View in Javascript Viewer", the resulting window displays my features and the auto-labels just fine. In my webmap, however, the features will draw but no labels. What could possibly prevent the labels from appearing within my webmap? Steve
... View more
11-01-2012
09:40 AM
|
0
|
2
|
1004
|
|
POST
|
Maybe your service can use the symbology that Jim Mossman created years ago and is discussed in this old ArcUser magazine article?
... View more
10-31-2012
12:01 PM
|
0
|
0
|
904
|
|
POST
|
Thanks, John! I was not aware of that option. Once I did set it, it rendered my features with full detail.
... View more
10-22-2012
06:53 AM
|
0
|
0
|
785
|
|
POST
|
Me again. 😄 I've been steadily knocking down many issues with my app and here's another one that I can't satisfactorily tackle using maxAllowableOffset. My app loads at the full extent of my county. If I select a project from a combo box, the map will then zoom into the extent of the project's feature. The attached screenshot shows you what is returned after the zoom in. The line basically straight lines from end to end instead of following the shape of the road (note the curves at the south end of the project). As the user zooms in and out of the map, the graphic representation of the features gets better and better. Since the feature layers I'm interested in only have ~30 records max, is there a way to specify that the features are ALWAYS drawn at the highest detail possible? I've tried adding a setMaxAllowable tied to the map's onZoomEnd event but it doesn't seem to correct the issue I see: var maxOffset = function maxOffset(map, pixelTolerance) { return Math.floor(map.extent.getWidth() / map.width) * pixelTolerance; }; . . . dojo.connect(map, 'onZoomEnd', function() { dojo.forEach(mapLayers, function(fl) { fl.setMaxAllowableOffset(maxOffset(map,1)); }); }); Steve [ATTACH=CONFIG]18593[/ATTACH]
... View more
10-19-2012
02:29 PM
|
0
|
2
|
1191
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 4 weeks ago | |
| 3 | 11-13-2025 07:55 AM | |
| 1 | 09-11-2025 10:18 AM | |
| 1 | 09-11-2025 08:03 AM | |
| 1 | 08-13-2025 09:16 AM |