コード例 #1
0
def rebuild_locator(locator_loc):

    # Define Global Variables
    global error_count
    global error_message

    # Set Variables
    error_message = ''
    error_count = 0

    for locator in locator_loc:

        # Begin rebuild process.  On error set conditions for e-mail.
        try:
            arcpy.RebuildAddressLocator_geocoding(in_address_locator=locator)
            error_count = 0
            error_message = 'Locator Rebuild Success:  {0} \n'.format(locator)
        except Exception as error_check:
            print('Status:  Failure to rebuild!')
            error_message = 'Locator Rebuild Failure:  {0} \n{1}'.format(
                locator, error_check.args[0])
            print(error_message)
            error_count += 1

        sendmailmsg(email_target, error_count, error_message, mail_server,
                    mail_from)

    return ()
コード例 #2
0
    def rebuild_locator(self, locator):
        self.logger.logMsg('rebuilding {}'.format(locator))
        arcpy.env.workspace = settings.LOCATORS_FGDB
        arcpy.RebuildAddressLocator_geocoding(locator)
        sdFile = '{}\{}.sd'.format(sddraftsFolder, locator)

        # clear out any old .sd files
        if arcpy.Exists(sdFile):
            arcpy.Delete_management(sdFile)
        sddraftFile = '{}\{}.sddraft'.format(sddraftsFolder, locator)
        if arcpy.Exists(sddraftFile):
            arcpy.Delete_management(sddraftFile)

        # delete existing locator service
        service = r'Geolocators/' + locator
        serviceType = 'GeocodeServer'
        self.logger.logMsg('deleting existing service')
        self.agsAdmin.deleteService(service, serviceType)

        # need to make a copy of the .sddraft file
        # since StateService deletes it
        self.logger.logMsg('publishing new service')
        arcpy.Copy_management(
            '{}\{}\{}.sddraft'.format(sddraftsFolder,
                                      settings.ORIGINALS_FOLDER,
                                      locator),
            sddraftFile)
        arcpy.StageService_server(sddraftFile, sdFile)
        arcpy.UploadServiceDefinition_server(sdFile,
                                             settings.GIS_SERVER_CONNECTION)

        self.logger.logMsg('validating service status')
        if (not self.agsAdmin.getStatus(service, serviceType)['realTimeState']
                == 'STARTED'):
            raise '{} was not restarted successfully!'.format(service)
コード例 #3
0
def rebuildLocator(locator):
    print "Rebuilding the locator: " + locator + "."
    try:
        arcpy.RebuildAddressLocator_geocoding(locator)
        print "Succcesfully Rebuilt the locator: " + locator + "!"
    except:
        print 'Error rebuilding geoccoder : ' + locator + '.'
        print arcpy.GetMessages(2)
        logger.error('Error rebuilding geoccoder : ' + locator + '.')
        logger.error(arcpy.GetMessages(2))
コード例 #4
0
ファイル: LocatorsPallet.py プロジェクト: ZachBeck/warehouse
    def rebuild_locator(self, locator):
        sddraftsFolder = path.join(path.dirname(__file__), 'sddrafts')

        self.log.info('rebuilding {}'.format(locator))
        arcpy.RebuildAddressLocator_geocoding(path.join(
            self.locators, locator))
        sdFile = '{}\\{}.sd'.format(sddraftsFolder, locator)

        #: clear out any old .sd files
        if arcpy.Exists(sdFile):
            arcpy.Delete_management(sdFile)
        sddraftFile = '{}\\{}.sddraft'.format(sddraftsFolder, locator)
        if arcpy.Exists(sddraftFile):
            arcpy.Delete_management(sddraftFile)

        #: delete existing locator service
        service = 'Geolocators/' + locator
        serviceType = 'GeocodeServer'
        self.log.info('deleting existing service')
        try:
            self.agsAdmin.deleteService(service, serviceType)
        except Exception:
            pass

        #: need to make a copy of the .sddraft file
        #: since StageService deletes it
        copy_location = '{}\\{}\\{}.sddraft'.format(sddraftsFolder,
                                                    'originals', locator)
        self.log.info('publishing new service')

        arcpy.Copy_management(copy_location, sddraftFile)
        self.log.info('copy done')
        arcpy.StageService_server(sddraftFile, sdFile)
        self.log.info('stage done')
        gis_server_connection = path.join(path.dirname(__file__), 'server')
        arcpy.UploadServiceDefinition_server(sdFile, gis_server_connection)
        self.log.info('upload done')

        self.log.info('validating service status')
        if (not self.agsAdmin.getStatus(service, serviceType)['realTimeState']
                == 'STARTED'):
            raise '{} was not restarted successfully!'.format(service)
コード例 #5
0
print "starting script"

import arcpy
import pprint
from datetime import datetime
import xml.dom.minidom as DOM
import smtplib

# overwrite feature classes already created
arcpy.env.workspace = "<path to scratch fgdb>"
arcpy.env.overwriteOutput = True

# rebuild locator
print "rebuilding locator"
arcpy.RebuildAddressLocator_geocoding(
    "\\\\<path to address locator>\Addresses_Locator_Wake\MAR_Wake_Addresses")
# http://enterprise.arcgis.com/en/server/10.3/administer/linux/scripting-service-publishing-with-arcpy.htm
# http://enterprise.arcgis.com/en/server/10.3/administer/linux/scripting-with-the-arcgis-rest-api.htm

# initialize errorCounter to count successful publishes
errorCounter = 0

# publish to prd 3
locator_path = "//<path to address locator>/Addresses_Locator_Wake/MAR_Wake_Addresses"
sddraft_file = "//<path to address locator>/Addresses_Locator_Wake/FacilitiesGeo.sddraft"
sd_file = "//<path to address locator>/Addresses_Locator_Wake/MAR_Wake_Geocoder.sd"
service_name = "MAR_Wake_Geocoder"
summary = "Address locator for Facilities and Ops"
tags = "address, locator, geocode"
gis_server_connection_file = "//<path to address locator>/Addresses_Locator_Wake/<.ags connection file to arcgis server>"
コード例 #6
0
#-------------------------------------------------------------------------------
# Name:        RebuildLocators.py
# Purpose:     Rebuild Address Locators
# Author:      gbunce
# Created:     04/09/2018
#-------------------------------------------------------------------------------
import arcpy
# from arcpy import env

# env.workspace = "Database Connections\SGID_Transportation@[email protected]"
# env.workspace = "D:\Rebuild Address Locators"

# Locators
AGRC_AddressPointLocator = "D:\Rebuild Address Locators\AGRC_AddressPointLocator"
AGRC_RoadsLocator = "D:\Rebuild Address Locators\AGRC_RoadsLocator"
AGRC_CompositeLocator = "D:\Rebuild Address Locators\AGRC_CompositeLocator"

# Rebuild Locaotrs
print "start rebuilding AGRC_AddressPointLocator"
arcpy.RebuildAddressLocator_geocoding(AGRC_AddressPointLocator)
print "done rebuilding AGRC_AddressPointLocator"
print "start rebuilding AGRC_RoadsLocator"
arcpy.RebuildAddressLocator_geocoding(AGRC_RoadsLocator)
print "done rebuilding AGRC_RoadsLocator"
print "start rebuilding AGRC_CompositeLocator"
arcpy.RebuildAddressLocator_geocoding(AGRC_CompositeLocator)
print "done rebuilding AGRC_CompositeLocator"

print "done rebuilding all locators"
print "recreate the 3 locator packages and copy to K:\AGRC Projects\Locators"
print "Done!  Press any key to close."
コード例 #7
0
def publish_service(
    service_name,
    service_type,
    source_dir,
    ags_instance,
    ags_connection,
    service_folder=None,
    service_properties=None,
    service_prefix='',
    service_suffix=''
):
    import arcpy
    arcpy.env.overwriteOutput = True

    original_service_name = service_name
    service_name = '{}{}{}'.format(service_prefix, service_name, service_suffix)

    log.info(
        'Publishing {} service {} to ArcGIS Server instance {}, Connection File: {}, Service Folder: {}'
        .format(service_type, service_name, ags_instance, ags_connection, service_folder)
    )

    tempdir = tempfile.mkdtemp()
    log.debug('Temporary directory created: {}'.format(tempdir))
    try:
        sddraft = os.path.join(tempdir, service_name + '.sddraft')
        sd = os.path.join(tempdir, service_name + '.sd')
        log.debug('Creating SDDraft file: {}'.format(sddraft))

        if service_type == 'MapServer':
            mxd_path = os.path.join(source_dir, original_service_name + '.mxd')
            mxd = open_mxd(mxd_path)
            arcpy.mapping.CreateMapSDDraft(
                mxd,
                sddraft,
                service_name,
                'FROM_CONNECTION_FILE',
                ags_connection,
                False,
                service_folder
            )
            modify_sddraft(sddraft, service_properties)
            log.debug('Analyzing SDDraft file: {}'.format(sddraft))
            analysis = arcpy.mapping.AnalyzeForSD(sddraft)

        elif service_type == 'GeocodeServer':
            locator_path = os.path.join(source_dir, original_service_name)
            if service_properties.get('rebuild_locators'):
                log.info('Rebuilding locator {}'.format(locator_path))
                arcpy.RebuildAddressLocator_geocoding(locator_path)
            analysis = arcpy.CreateGeocodeSDDraft(
                locator_path,
                sddraft,
                service_name,
                'FROM_CONNECTION_FILE',
                ags_connection,
                False,
                service_folder
            )
            modify_sddraft(sddraft, service_properties)

        else:
            raise RuntimeError('Unsupported service type {}!'.format(service_type))

        for key, log_method in (('messages', log.info), ('warnings', log.warn), ('errors', log.error)):
            log.info('----' + key.upper() + '---')
            items = analysis[key]
            for ((message, code), layerlist) in items.iteritems():
                log_method('    {} (CODE {:05d})'.format(message, code))
                log_method('       applies to:')
                for layer in layerlist:
                    log_method('           {}'.format(layer.longName if hasattr(layer, 'longName') else layer.name))
                log_method('')

        if analysis['errors'] == {}:
            log.debug('Staging SDDraft file: {} to SD file: {}'.format(sddraft, sd))
            arcpy.StageService_server(sddraft, sd)
            log.debug('Uploading SD file: {} to AGS connection file: {}'.format(sd, ags_connection))
            arcpy.UploadServiceDefinition_server(sd, ags_connection)
            log.info(
                'Service {}/{} successfully published to {} at {:%#m/%#d/%y %#I:%M:%S %p}'
                .format(service_folder, service_name, ags_instance, datetime.datetime.now())
            )
        else:
            error_message = 'Analysis failed for service {}/{} at {:%#m/%#d/%y %#I:%M:%S %p}' \
                .format(service_folder, service_name, datetime.datetime.now())
            log.error(error_message)
            raise RuntimeError(error_message, analysis['errors'])
    except StandardError:
        log.exception(
            'An error occurred while publishing service {}/{} to ArcGIS Server instance {}'
            .format(service_folder, service_name, ags_instance)
        )
        raise
    finally:
        log.debug('Cleaning up temporary directory: {}'.format(tempdir))
        rmtree(tempdir, ignore_errors=True)
arcpy.FeatureClassToFeatureClass_conversion(
    sgidAddressPoints, rebuildLocators_Folder + "/RoadGrinder.gdb",
    "SgidAddrPnts")

#### Copy the three locators from hnas to the rebuild folder. ####
print "Copying the 3 locators from HNAS to the rebuild folder..."
arcpy.Copy_management(hnasLocators_Folder + "/" + addressPointLocator,
                      rebuildLocators_Folder + "/" + addressPointLocator)
arcpy.Copy_management(hnasLocators_Folder + "/" + roadsLocator,
                      rebuildLocators_Folder + "/" + roadsLocator)
arcpy.Copy_management(hnasLocators_Folder + "/" + compositeLocator,
                      rebuildLocators_Folder + "/" + compositeLocator)

#### Rebuild the locators in the rebuild folder. ####
print "start rebuilding AGRC_AddressPointLocator in rebuild folder..."
arcpy.RebuildAddressLocator_geocoding(rebuildLocators_Folder + "/" +
                                      addressPointLocator)
print "done rebuilding AGRC_AddressPointLocator in rebuild folder"
print "start rebuilding AGRC_RoadsLocator..."
arcpy.RebuildAddressLocator_geocoding(rebuildLocators_Folder + "/" +
                                      roadsLocator)
print "done rebuilding AGRC_RoadsLocator in rebuild folder"
print "start rebuilding AGRC_CompositeLocator..."
arcpy.RebuildAddressLocator_geocoding(rebuildLocators_Folder + "/" +
                                      compositeLocator)
print "done rebuilding AGRC_CompositeLocator"

#### Create the locator packages ####
print "Creating address locator packages...."
arcpy.PackageLocator_geocoding(addressPointLocator,
                               addressPointLocator + '.gcpk', "COPY_ARCSDE",
                               "#", "AGRC AddressPoint Locator",