POST
|
Thanks @Brian_Wilson. I only have a single script that I have to run and I don't foresee having to install additional packages so I was hoping to avoid everything related to conda (not sure if that is even possible). That said, I was able to get my script running. Here is how I did it. I had the administrator (the guy that did the install) give up full rwx access to all subdirectories of /opt/arcgis/server Made a copy of /opt/arcgis/server/tools/python (called it python_dam) Removed the code that terminates the script if not being called by the user that did the install Edited the line where wine64 invokes python to call my module cd to /opt/arcgis/server/tools ./python_dam This is what the modified file looks like #!/bin/bash
installDir=$(cd $(dirname $0)/.. && pwd);export installDir
installer=$(stat -c %U $installDir)
arcenv=$installDir/framework/etc/arcenv
if [ -f $arcenv ]; then
. $arcenv
if [ "x$DISPLAY" = "x" ]; then
. $installDir/framework/runtime/xvfb/init_Xvfb.sh
StartXvfb > /dev/null 2>&1
fi
# don't preload libjsig.so for standalone app
unset LD_PRELOAD
export CONDA_PREFIX="C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3"
export CONDA_DEFAULT_ENV="$CONDA_PREFIX"
wine64 "$CONDA_PREFIX\python.exe" "/home/dmorrison/cw/test_linkage_mapper.py"
else
echo "Unable to set up environment. Cannot find $arcenv"
fi
... View more
05-02-2023
02:23 PM
|
0
|
1
|
804
|
POST
|
I have a Python3/ArcPy script that must be moved from Windows to be run on a Linux system. From what I understand the only option is to run it on ArcGIS Server. So I had a system set with with Ubuntu and Arcgis Server 11 (putty/ssh access only). Now I'm trying to figure out how to run my script. Reading the documentation a number of questions came up. I thought a good first step would be to start an interactive Python session from the command line, but I can't find where the interpreter is installed. How can I do that? Must I install conda and create and activate a new environment, or is there already a base Python environment created in the installation? Must I install arcgis-server-py3? Does all of this really have to be done as the user that installed the ArcGIS Server? I tried to run <arcgis_server_installation_directory>/arcgis/server/tools/python3 and it failed for this reason Would it be better to use a python 3.8 environment which is already installed on this system instead of the one installed with ArcGIS Server?
... View more
05-02-2023
09:12 AM
|
0
|
3
|
836
|
POST
|
I added the 'transformation_name' parameter on the projectAs call and now I get the same results in all environments. Thanks for the pointer Dan! pt = arcpy.PointGeometry(arcpy.Point(687577.9340000004, 2134343.1621000003), spatial_reference="USA_Contiguous_Albers_Equal_Area_Conic_USGS_version")
pt_projected = pt.projectAs('4326','WGS_1984_(ITRF00)_To_NAD_1983')
print ("Projected x,y : %s,%s" % (str(pt_projected.firstPoint.X), str(pt_projected.firstPoint.Y)))
... View more
04-30-2023
06:18 AM
|
0
|
0
|
304
|
POST
|
I have some simple code that projects a point. pt = arcpy.PointGeometry(arcpy.Point(687577.9340000004, 2134343.1621000003), spatial_reference="USA_Contiguous_Albers_Equal_Area_Conic_USGS_version")
pt_projected = pt.projectAs('4326')
print ("Projected x,y : %s,%s" % (str(pt_projected.firstPoint.X), str(pt_projected.firstPoint.Y))) It seems to return different results as shown below. This first is produced when running in the ArcGIS Pro 3.1 Python window and also in my Spyder/IPython environment. The second is produced when I run it in a python toolbox (and I think when I run it after publishing the toolbox to an ArcGIS Server). Can anybody explain this difference? Projected x,y : -87.63855949198765,41.938884076168215 Projected x,y : -87.63856525044517,41.93889193970926
... View more
04-29-2023
06:24 PM
|
0
|
2
|
348
|
POST
|
I believe that the defaults are not applied to existing records in your feature class, but the are applied only to new records being added. To update existing records you could run arcpy.management.CalculateField
... View more
04-28-2023
07:19 AM
|
0
|
1
|
382
|
IDEA
|
I'd like to do the same. I see that I can upload a zip as a "Desktop application template" and share it for others to download. So it seems to accomplish what I need but it doesn't feel quite right. Other than the possible confusion(which would be avoided by having a generic "Zip File" item type), could there be a problem doing this?
... View more
04-19-2023
07:29 AM
|
0
|
0
|
358
|
POST
|
I have exactly the same problem, did you find a solution?
... View more
04-13-2023
03:29 PM
|
0
|
0
|
187
|
POST
|
I don't like hard coding the array indexes since they are a pain to adjust if you move around the order of the parameters. So I wrote a function to get them by name and call that at the start of the update and execute functions. # Find the parameter by name (which is set in getParametmerInfo)
def get_parm (parms, name, enforce_not_null = False):
for parm in parms:
if parm.name == name:
if enforce_not_null and (parm.value is None or parm.valueAsText == ''):
raise Exception ("'%s' has an invalid value" % (parm.displayName))
return parm
# At the start of update and execute functions, retrieve the relevant parameters by name instead of index
def execute (self, parameters):
gdbOrFC = get_parm (parameters, "GDBs_or_Feature_Classes?")
inGDBS = get_parm (parameters, "Input_GDBs")
inFCs = get_parm (parameters, "Input_FCs")
... View more
04-13-2023
06:52 AM
|
1
|
0
|
999
|
POST
|
One thing I would check is on line 70, "fields" must be a python list. I can't tell how it is returned on line 62 but I suspect it is a string with a comma-separated set of values and not a true python list - just a guess
... View more
04-09-2023
04:15 PM
|
1
|
1
|
394
|
POST
|
I have had good luck with the "pip install spyder" technique on 2.9 and 3.0.3, described in a little more detail here.
... View more
03-17-2023
04:53 AM
|
1
|
0
|
1053
|
POST
|
I was under the impression that Domains are not relevant to doing an update, but I could be wrong. I would add a print statements in your loop to verify your inputs to updateRow with arcpy.da.UpdateCursor(StSele, "State") as upd_cur:
for upd_row in upd_cur:
print (str(upd_row))
upd_row[0] = place_dict.get(upd_row[0], upd_row[0])
print (str(upd_row))
upd_cur.updateRow(upd_row)
... View more
03-07-2023
04:21 PM
|
0
|
3
|
599
|
POST
|
That's a very nice program @AaronCole1 . I've been doing a lot of scraping recently and have had good luck using FeatureClassToFeatureClass. It only works on one layer at a time, you have to feed it the REST service URL, and doesn't write to JSON like you want.... arcpy.conversion.FeatureClassToFeatureClass(in_url, os.path.dirname(out_fc), os.path.basename(out_fc))
... View more
03-07-2023
04:09 PM
|
2
|
13
|
954
|
POST
|
No, I did not. We have sort of moved on since we ran into this roadblock but I'll try that trick if we get back to it. Thanks!
... View more
01-17-2023
02:28 PM
|
0
|
0
|
1140
|
POST
|
Over the years, I have created a logger component that I copy into each of my python projects and it has worked quite well for me. It is built on top of the standard Python logging support. "info" messages go to both the console and a log file. "debug" messages go only to the log file. It also deletes old log files. The logger is created with this code in logger.py (you can see how you can control which subfolder that logs are stored in and the prefix for the log file name, and the retention time for old log files). I use iPython for debugging so you could ignore/remove that code if it isn't applicable. import os
import sys
import arcpy
import time
import glob
import logging
import logging.handlers
LOG_FILE = os.path.join(arcpy.env.scratchFolder, 'logs', 'fs', 'fs_log_%i.txt' % os.getpid())
# Log handler that forwards messages to ArcGIS
class ArcGisHandler(logging.Handler):
try:
get_ipython()
is_run_from_ipython = True
except NameError:
is_run_from_ipython = False
is_run_from_cmd_line = sys.stdin is not None and sys.stdin.isatty()
def emit(self, record):
if not self.is_run_from_cmd_line and not self.is_run_from_ipython:
arcpy.AddMessage(self.format(record))
# Set up logging
def get(log_name):
# Compute the full path for this process and make sure the directory exists
if not os.path.exists(os.path.dirname(LOG_FILE)):
os.makedirs(os.path.dirname(LOG_FILE))
# Clean up old log files
if not os.path.exists(LOG_FILE):
for file in glob.glob(os.path.join(arcpy.env.scratchFolder, 'logs', 'fs', 'fs_log_*.txt')):
if time.time() - os.path.getmtime(file) > 2 * 60 * 60 * 24:
try:
os.remove(file)
except:
pass
logger = logging.getLogger(log_name)
logger.disabled = False
logger.setLevel(logging.DEBUG)
if len(logger.handlers) == 0:
# File handler for detailed tracing
try:
formatter1 = logging.Formatter('%(asctime)s - %(levelname)s - %(module)s - %(message)s')
fh1 = logging.FileHandler(LOG_FILE)
fh1.setFormatter(formatter1)
fh1.setLevel(logging.DEBUG)
logger.addHandler(fh1)
except:
pass
# Standard out handler
try:
formatter2 = logging.Formatter('%(levelname)s - %(message)s')
fh2 = logging.StreamHandler(sys.stdout)
fh2.setFormatter(formatter2)
fh2.setLevel(logging.INFO)
logger.addHandler(fh2)
except:
pass
# Custom handler to send messages to ArcGIS
try:
if sys.version_info.major > 2:
formatter4 = logging.Formatter('%(asctime)s - %(message)s', '%H:%M:%S')
fh4 = ArcGisHandler()
fh4.setFormatter(formatter4)
fh4.setLevel(logging.INFO)
logger.addHandler(fh4)
except:
pass
return logger In every module I include these two lines: import logger
my_logger = logger.get('fs_log') At my main entry point I spit out where the log file is: my_logger.info ("Logging to %s" % logger.LOG_FILE)
... View more
01-17-2023
02:19 PM
|
0
|
1
|
1403
|
Title | Kudos | Posted |
---|---|---|
1 | 03-06-2024 11:59 AM | |
1 | 12-11-2023 03:20 PM | |
2 | 11-17-2023 06:52 AM | |
1 | 10-12-2023 07:38 AM | |
1 | 10-01-2023 04:02 PM |
Online Status |
Offline
|
Date Last Visited |
2 weeks ago
|