|
POST
|
Hi Andrew, Yes, I haven't made any progress. Sure, here's the link: https://willcountygis.maps.arcgis.com/apps/CrowdsourceReporter/index.html?appid=b3c9cb95a838496ea499ef64dd14a11c
... View more
12-05-2019
01:12 PM
|
0
|
3
|
2538
|
|
POST
|
Thanks all, I cleaned it up thanks to your observations and it works great. '''Import folder of MXD(s) into an ArcGIS Pro Project and save the project in a folder.
'''
import arcpy, os
#List full path location of MXD(s) in workspaceMXD
workspaceMXD = r"C:\gisfile\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder"
arcpy.env.workspace = workspaceMXD
mxdlist = arcpy.ListFiles("*.mxd")
for mxd in mxdlist:
#aprx project that MXD(s) are being imported into
aprx = arcpy.mp.ArcGISProject(r"C:\gisfile\GISmaps\AtlasMaps\MXDtoAPRX_tempdelete\MXDtoAPRX.aprx")
fullpath = os.path.join(workspaceMXD, mxd)
print("Importing: {}".format(fullpath))
#import the MXD(s) into Pro
aprx.importDocument(fullpath)
#the count of the maps
m = aprx.listMaps()
print("Currently {0} maps in Project file.".format(len(m)))
#name the maps
aprx.listMaps()[-1].name = mxd.split("\\")[-1][:-4]
#save a copy of the project in the workspace folder
aprx.saveACopy(fullpath)
print("----done----")
del aprx
... View more
12-02-2019
07:30 AM
|
0
|
0
|
7372
|
|
POST
|
At the end of this script that imports MXDs into an ArcGIS Pro Project I'm using the saveACopy function. '''Import folder of MXD(s) into an ArcGIS Pro Project and save the project in a folder.
'''
import arcpy, os
#List full path location of MXD(s) in workspaceMXD
workspaceMXD = r"C:\gisfile\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder"
arcpy.env.workspace = workspaceMXD
mxdlist = arcpy.ListFiles("*.mxd")
#aprx project that MXD(s) are being imported into
aprx = arcpy.mp.ArcGISProject(r"C:\gisfile\GISmaps\AtlasMaps\MXDtoAPRX_tempdelete\MXDtoAPRX.aprx")
for mxd in mxdlist:
arcpy.env.overwriteOutput = True
fullpath = os.path.join(workspaceMXD, mxd)
print("Importing: {}".format(fullpath))
aprx.importDocument(fullpath) #import the MXD(s) into Pro
#the count of the maps
print("Currently {0} maps in Project file.".format(len(aprx.listMaps())))
#name the maps
aprx.listMaps()[-1].name = mxd.split("\\")[-1][:-4]
#save a copy of the project in the workspace folder
aprx.saveACopy(fullpath)
print("----done----") Output Importing: C:\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder\Union_Elem_81_B.mxd
Currently 2 maps in Project file.
Importing: C:\gisfile\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder\ValleyView_Unit_365U_B.mxd
Currently 4 maps in Project file.
Importing: C:\gisfile\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder\WillCounty_Elem_92_B.mxd
Currently 6 maps in Project file.
Importing: C:\gisfile\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder\Wilmington_Unit_209U_B.mxd
Currently 8 maps in Project file.
----done---- It saves an APRX file from the workspace folder for each imported MXD. But, a copy of the map is imported in each consecutive project. So, as seen here and in the Test Folder, by the fourth saved APRX file maps for the other three projects are also there. That's why the file size of the APRXs increases by 400+ KB as the script loops through the folder. I've also tried taking aprx.saveACopy(fullpath) out of the for loop. But, that only saves one APRX file with all maps in that one project. How do I loop through the Test Folder and save a copy of the APRX file with it's corresponding map only? As discussed at the bottom of my other post, ArcGISProject saveACopy seems only to allow full paths as a parameter. importDocument() OSError
... View more
11-27-2019
01:36 PM
|
0
|
3
|
7628
|
|
POST
|
@jeremy If I give it a full path, file name and extension it will save one APRX with that file name. The best results I can get so far is by putting the fullpath variable in the saveACopy() function. This saves the six APRX files individually in the folder. However, now some of the maps are imported twice? For example: Since my original question was already answered by Dan, I'll go ahead and mark it as such. Thanks for the help.
... View more
11-27-2019
11:41 AM
|
0
|
0
|
4009
|
|
POST
|
Hi Arne, When you saveACopy were you able to save an individual aprx file for each map? That would be ideal. I have a script largely based off yours but it's saving all six of my test maps in one project (aprx). I put the saveACopy in the for loop and left it out, but same difference. import arcpy, os
#List MXDs in workspaceMXD
workspaceMXD = r"C:\gisfile\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder"
arcpy.env.workspace = workspaceMXD
arcpy.env.overwriteOutput = True
mxdlist = arcpy.ListFiles("*.mxd")
#aprx project
aprx = arcpy.mp.ArcGISProject(r"C:\gisfile\GISmaps\AtlasMaps\MXDtoAPRX_tempdelete\MXDtoAPRX_tempdelete.aprx")
for mxd in mxdlist:
fullpath = os.path.join(workspaceMXD, mxd)
print("Importing: {}".format(fullpath))
aprx.importDocument(fullpath)
#the count of the maps
print("Currently {0} maps in Project file.".format(len(aprx.listMaps())))
#name the maps
aprx.listMaps()[-1].name = mxd.split("\\")[-1][:-4]
aprx.saveACopy(r"C:\gisfile\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder.aprx")
... View more
11-26-2019
12:36 PM
|
0
|
1
|
2615
|
|
POST
|
Oops, I forgot to add the fullpath variable to the importDocument function. So, I did that just now and it worked: aprx.importDocument(fullpath) The problem is now it's saving all the maps in one project instead of 6 individual ones? I put aprx.saveACopy in the for loop and I left it out of the for loop, but same difference?
... View more
11-26-2019
12:12 PM
|
0
|
3
|
4009
|
|
POST
|
Dan, I set it up with the full path and did not include the Layout parameter, but it's giving me the same error. for mxd in mxdlist:
fullpath = os.path.join(workspaceMXD, mxd)
print("Importing: {}".format(fullpath))
aprx.importDocument(mxd)
... View more
11-26-2019
11:52 AM
|
0
|
4
|
4009
|
|
POST
|
For some reason my Citizen Problem Reporter app will not load. All necessary maps and feature layers are shared with the Citizen Problem Reporter Group. I created this a couple months ago and for some reason yesterday it stopped working. I'm using Firefox and have tried opening it in different browsers too. I can't figure out why.
... View more
11-26-2019
11:31 AM
|
0
|
5
|
2751
|
|
POST
|
I'm attempting to convert MXDs to APRXs using the MXD filenames in a stand alone script. I'm basically using this code from a prior post: How to assign name to map layer in APRX when importing from MXD? I have a test folder with six MXDs in it. The script gets as far as beginning to loop through the folder but then throws an OSError on the first MXD. The error is pointing towards the importDocument line (line 14 below). import arcpy
#List MXDs in workspaceMXD
workspaceMXD = r"C:\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder"
arcpy.env.workspace = workspaceMXD
arcpy.env.overwriteOutput = True
mxdlist = arcpy.ListFiles("*.mxd")
#aprx project
aprx = arcpy.mp.ArcGISProject(r"C:\GISmaps\AtlasMaps\MXDtoAPRX_tempdelete\MXDtoAPRX_tempdelete.aprx")
for mxd in mxdlist:
print("Importing: {0}".format(mxd.split("\\")[-1]))
aprx.importDocument(mxd,include_layout=True)
#the count of the maps
print("Currently {0} maps in Project file.".format(len(aprx.listMaps())))
#name the maps
aprx.listMaps()[-1].name = mxd.split("\\")[-1][:-4]
aprx.saveACopy(r"C:\GISmaps\AtlasMaps\ATLAS_MAPS_20\TestFolder") Error Importing: Beecher_Unit_200U_B.mxd
Traceback (most recent call last):
File "C:\GISstaff\Jared\Python Scripts\ArcGISPro\MxdToAprx.py", line 14, in <module>
aprx.importDocument(mxd,include_layout=False)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 223, in importDocument
return convertArcObjectToPythonObject(self._arc_object.importDocument(*gp_fixargs((document_path, include_layout, reuse_existing_maps), True)))
OSError: Beecher_Unit_200U_B.mxd If I import one MXD at a time and save it as an APRX as seen in the code sample on the the ArcGISProject page, it works fine. But, I'm working with multiple MXDs. Does anyone know what this error is referring to?
... View more
11-25-2019
12:00 PM
|
0
|
6
|
4250
|
|
POST
|
Dan, Yes, this question is related to that question. I responded to that thread, by the way. Pertaining to my thread here, the SMTP Server parameter in the Send Emails tool needs to include the port number. In my case I'm using Gmail. So, it should be: smtp.gmail.com:587
... View more
10-15-2019
11:51 AM
|
0
|
0
|
2119
|
|
POST
|
Hi Dan, Thanks for the info. "send_email" isn't a module but a separate script included in the ServiceSupport zip folder of the ServiceFunctions toolbox. It's accessible in this document: https://www.esri.com/content/dam/esrisites/en-us/media/pdf/learn-arcgis/configuring-citizen-problem-reporter.pdf The script I was running was servicefunctions.py found in the same folder as send_email.py.
... View more
10-15-2019
11:44 AM
|
0
|
1
|
4957
|
|
POST
|
Long story short, I'm setting up the Citizen Problem Reporter app so that the public can ask questions and have them routed to specific departments within the county. I'm setting it up via this PDF: https://www.esri.com/content/dam/esrisites/en-us/media/pdf/learn-arcgis/configuring-citizen-problem-reporter.pdf The servicefunctions.py script is an addition to the Send Emails geoprocessing tool. I'm attempting to run the script in the Python environment that comes with ArcGIS Pro-- Python 3.6.8. When I run the Send Emails tool it seems to run fine. The tool sets the parameters in the JSON. But, the script is what actually sends the emails. I'm not sure what's causing the errors (below). # ------------------------------------------------------------------------------
# Name: calculateids.py
# Purpose: generates identifiers for features
# Copyright 2017 Esri
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------
from send_email import EmailServer
import re
from datetime import datetime as dt
from os import path, sys
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
import json
#id_settings = {}
#modlists = {}
def _add_message(msg, ertype='ERROR'):
print("{}: {}".format(ertype, msg))
with open(path.join(sys.path[0], 'id_log.log'), 'a') as log:
log.write("{} -- {}: {}".format(dt.now(), ertype, msg))
return
def _report_failures(results):
for result in results['updateResults']:
if not result['success']:
_add_message('{}: {}'.format(result['error']['code'], result['error']['description']))
return
def _get_features(feature_layer, where_clause, return_geometry=False):
"""Get the features for the given feature layer of a feature service. Returns a list of json features.
Keyword arguments:
feature_layer - The feature layer to return the features for
where_clause - The expression used in the query"""
total_features = []
max_record_count = feature_layer.properties['maxRecordCount']
if max_record_count < 1:
max_record_count = 1000
offset = 0
while True:
if not where_clause:
where_clause = "1=1"
features = feature_layer.query(where=where_clause,
return_geometry=return_geometry,
result_offset=offset,
result_record_count=max_record_count).features
total_features += features
if len(features) < max_record_count:
break
offset += len(features)
return total_features
def add_identifiers(lyr, seq, fld):
"""Update features in an agol/portal service with id values
Return next valid sequence value"""
# Get features without id
value = id_settings[seq]['next value']
fmt = id_settings[seq]['pattern']
interval = id_settings[seq]['interval']
rows = _get_features(lyr, """{} is null""".format(fld))
# For each feature, update id, and increment sequence value
for row in rows:
row.attributes[fld] = fmt.format(value)
value += interval
if rows:
results = lyr.edit_features(updates=rows)
_report_failures(results)
return value
def enrich_layer(source, target, settings):
wkid = target.properties.extent.spatialReference.wkid
# Query for target features
rows = _get_features(target, "1=1", return_geometry=True)
for row in rows:
# Perform spatial query to get attributes of intersecting feature
ptgeom = {'geometry': row.geometry,
'spatialRel': 'esriSpatialRelIntersects',
'geometryType': 'esriGeometryPoint',
'inSR': wkid
}
sourcefeat = source.query(geometry_filter=ptgeom)
try:
# Only first feature is processed
source_val = sourcefeat.features[0].attributes[settings['source']]
row.attributes[settings['target']] = source_val
except IndexError:
continue # no intersecting feature found
if rows:
results = target.edit_features(updates=rows)
_report_failures(results)
return
def build_expression(words, match_type, subs):
"""Build an all-caps regular expression for matching either exact or
partial strings"""
re_string = ''
for word in words:
new_word = ''
for char in word.upper():
# If listed, include substitution characters
if char in subs.keys():
new_word += "[" + char + subs[char] + "]"
else:
new_word += "[" + char + "]"
# Filter using only exact matches of the string
if match_type == 'EXACT':
re_string += '\\b{}\\b|'.format(new_word)
# Filter using all occurances of the letter combinations specified
else:
re_string += '.*{}.*|'.format(new_word)
# Last character will always be | and must be dropped
return re_string[:-1]
def moderate_features(lyr, settings):
rows = _get_features(lyr, settings['sql'])
for row in rows:
for field in settings['scan fields'].split(';'):
try:
text = row.get_value(field)
text = text.upper()
except AttributeError: # Handles empty fields
continue
if re.search(modlists[settings['list']], text):
row.attributes[settings['field']] = settings['value']
break
if rows:
results = lyr.edit_features(updates=rows)
_report_failures(results)
return
def _get_value(row, fields, sub):
val = row.attributes[sub]
if val is None:
val = ''
elif type(val) != str:
for field in fields:
if field['name'] == sub and 'Date' in field['type']:
try:
val = dt.fromtimestamp(
row.attributes[sub]).strftime('%c')
except OSError: # timestamp in milliseconds
val = dt.fromtimestamp(
row.attributes[sub] / 1000).strftime('%c')
break
else:
val = str(val)
return val
def build_email(row, fields, settings):
email_subject = ''
email_body = ''
if settings['recipient'] in row.fields:
email = row.attributes[settings['recipient']]
else:
email = settings['recipient']
try:
html = path.join(path.dirname(__file__), settings['template'])
with open(html) as file:
email_body = file.read()
email_subject = settings['subject']
if substitutions:
for sub in substitutions:
if sub[1] in row.fields:
val = _get_value(row, fields, sub[1])
email_body = email_body.replace(sub[0], val)
email_subject = email_subject.replace(sub[0], val)
else:
email_body = email_body.replace(sub[0], str(sub[1]))
email_subject = email_subject.replace(sub[0], str(sub[1]))
except:
_add_message('Failed to read email template {}'.format(html))
return email, email_subject, email_body
def main(configuration_file):
try:
with open(configuration_file) as configfile:
cfg = json.load(configfile)
gis = GIS(cfg['organization url'], cfg['username'], cfg['password'])
# Get general id settings
global id_settings
id_settings = {}
for option in cfg['id sequences']:
id_settings[option['name']] = {'interval': int(option['interval']),
'next value': int(option['next value']),
'pattern': option['pattern']}
# Get general moderation settings
global modlists
modlists = {}
subs = cfg['moderation settings']['substitutions']
for modlist in cfg['moderation settings']['lists']:
words = [str(word).upper().strip() for word in modlist['words'].split(',')]
modlists[modlist['filter name']] = build_expression(words, modlist['filter type'], subs)
# Get general email settings
server = cfg['email settings']['smtp server']
username = cfg['email settings']['smtp username']
password = cfg['email settings']['smtp password']
tls = cfg['email settings']['use tls']
from_address = cfg['email settings']['from address']
if not from_address:
from_address = ''
reply_to = cfg['email settings']['reply to']
if not reply_to:
reply_to = ''
global substitutions
substitutions = cfg['email settings']['substitutions']
# Process each service
for service in cfg['services']:
try:
lyr = FeatureLayer(service['url'], gis=gis)
# GENERATE IDENTIFIERS
idseq = service['id sequence']
idfld = service['id field']
if id_settings and idseq and idfld:
if idseq in id_settings:
new_sequence_value = add_identifiers(lyr, idseq, idfld)
id_settings[idseq]['next value'] = new_sequence_value
else:
_add_message('Sequence {} not found in sequence settings'.format(idseq), 'WARNING')
# ENRICH REPORTS
if service['enrichment']:
# reversed, sorted list of enrichment settings
enrich_settings = sorted(service['enrichment'], key=lambda k: k['priority'], reverse=True)
for reflayer in enrich_settings:
source_features = FeatureLayer(reflayer['url'], gis)
enrich_layer(source_features, lyr, reflayer)
# MODERATION
if modlists:
for query in service['moderation']:
if query['list'] in modlists:
moderate_features(lyr, query)
else:
_add_message('Moderation list {} not found in moderation settings'.format(modlist), 'WARNING')
# SEND EMAILS
if service['email']:
with EmailServer(server, username, password, tls) as email_server:
for message in service['email']:
rows = _get_features(lyr, message['sql'])
for row in rows:
address, subject, body = build_email(row, lyr.properties.fields, message)
if address and subject and body:
try:
email_server.send(from_address=from_address,
reply_to=reply_to,
to_addresses=[address],
subject=subject,
email_body=body)
row.attributes[message['field']] = message['sent value']
except:
_add_message('email failed to send for feature {} in layer {}'.format(row.attributes, service['url']))
if rows:
results = lyr.edit_features(updates=rows)
_report_failures(results)
except Exception as ex:
_add_message('Failed to process service {}\n{}'.format(service['url'], ex))
except Exception as ex:
_add_message('Failed. Please verify all configuration values\n{}'.format(ex))
finally:
new_sequences = [{'name': seq,
'interval': id_settings[seq]['interval'],
'next value': id_settings[seq]['next value'],
'pattern': id_settings[seq]['pattern']} for seq in id_settings]
if not new_sequences == cfg['id sequences']:
cfg['id sequences'] = new_sequences
try:
with open(configuration_file, 'w') as configfile:
json.dump(cfg, configfile)
except Exception as ex:
_add_message('Failed to save identifier configuration values.\n{}\nOld values:{}\nNew values:{}'.format(ex, cfg['id sequences'], new_sequences))
if __name__ == '__main__':
main(path.join(path.dirname(__file__), 'servicefunctions.json'))
ERROR: Failed to process service https://services.arcgis.com/fGsbyIOAuxHnF97m/arcgis/rest/services/CitizenProblems_landuse/FeatureServer/0
[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
ERROR: Failed to process service https://services.arcgis.com/fGsbyIOAuxHnF97m/arcgis/rest/services/CitizenProblems_bb0fbdc850114e6f8c11c32b9768e643/FeatureServer/0
[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
... View more
10-08-2019
01:57 PM
|
0
|
2
|
2277
|
|
POST
|
Here's the result: ERROR: Failed to process service https://services.arcgis.com/fGsbyIOAuxHnF97m/arcgis/rest/services/CitizenProblems_landuse/FeatureServer/0
'FeatureLayer' object has no attribute '_lazy_properties'
ERROR: Failed to process service https://services.arcgis.com/fGsbyIOAuxHnF97m/arcgis/rest/services/CitizenProblems_bb0fbdc850114e6f8c11c32b9768e643/FeatureServer/0
[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
... View more
10-03-2019
07:17 AM
|
0
|
0
|
3237
|
|
POST
|
Chris, Looks like the variable 'path' needs defined: Traceback (most recent call last):
File "<string>", line 11, in <module>
NameError: name 'path' is not defined
... View more
10-03-2019
06:54 AM
|
0
|
2
|
3297
|
|
POST
|
Chris, Ok, that makes sense. I put the code in Pro. Here's the result: <FeatureLayer url:"https://services.arcgis.com/fGsbyIOAuxHnF97m/arcgis/rest
/services/CitizenProblems_landuse/FeatureServer/0 ">
... View more
10-01-2019
12:57 PM
|
0
|
4
|
2448
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 2 weeks ago | |
| 1 | 05-04-2026 08:45 AM | |
| 1 | 04-20-2026 01:20 PM | |
| 1 | 07-24-2025 01:27 PM | |
| 1 | 11-13-2025 08:22 AM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|