コード例 #1
0
def main(thisDB, coordSystem, nCrossSections):
    # create feature dataset GeologicMap
    addMsgAndPrint('  Creating feature dataset GeologicMap...')
    try:
        arcpy.CreateFeatureDataset_management(thisDB, 'GeologicMap',
                                              coordSystem)
    except:
        addMsgAndPrint(arcpy.GetMessages(2))

    # create feature classes in GeologicMap
    # poly feature classes
    featureClasses = ['MapUnitPolys']
    for fc in ['DataSourcePolys', 'MapUnitOverlayPolys', 'OverlayPolys']:
        if fc in OptionalElements:
            featureClasses.append(fc)
    for featureClass in featureClasses:
        fieldDefs = tableDict[featureClass]
        if addLTYPE and fc <> 'DataSourcePolys':
            fieldDefs.append(['PTYPE', 'String', 'NullsOK', 50])
        createFeatureClass(thisDB, 'GeologicMap', featureClass, 'POLYGON',
                           fieldDefs)

    # line feature classes
    featureClasses = ['ContactsAndFaults']
    for fc in ['GeologicLines', 'CartographicLines', 'IsoValueLines']:
        if fc in OptionalElements:
            featureClasses.append(fc)
    if debug:
        addMsgAndPrint('Feature classes = ' + str(featureClasses))
    for featureClass in featureClasses:
        fieldDefs = tableDict[featureClass]
        if featureClass in ['ContactsAndFaults', 'GeologicLines'] and addLTYPE:
            fieldDefs.append(['LTYPE', 'String', 'NullsOK', 50])
        createFeatureClass(thisDB, 'GeologicMap', featureClass, 'POLYLINE',
                           fieldDefs)

    # point feature classes
    featureClasses = []
    for fc in [
            'OrientationPoints', 'GeochronPoints', 'FossilPoints', 'Stations',
            'GenericSamples', 'GenericPoints'
    ]:
        if fc in OptionalElements:
            featureClasses.append(fc)
    for featureClass in featureClasses:
        fieldDefs = tableDict[featureClass]
        if addLTYPE:
            fieldDefs.append(['PTTYPE', 'String', 'NullsOK', 50])
        createFeatureClass(thisDB, 'GeologicMap', featureClass, 'POINT',
                           fieldDefs)

    # create feature dataset CorrelationOfMapUnits
    if 'CorrelationOfMapUnits' in OptionalElements:
        addMsgAndPrint('  Creating feature dataset CorrelationOfMapUnits...')
        arcpy.CreateFeatureDataset_management(thisDB, 'CorrelationOfMapUnits')
        fieldDefs = tableDict['CMUMapUnitPolys']
        createFeatureClass(thisDB, 'CorrelationOfMapUnits', 'CMUMapUnitPolys',
                           'POLYGON', fieldDefs)
        fieldDefs = tableDict['CMULines']
        createFeatureClass(thisDB, 'CorrelationOfMapUnits', 'CMULines',
                           'POLYLINE', fieldDefs)
        fieldDefs = tableDict['CMUPoints']
        createFeatureClass(thisDB, 'CorrelationOfMapUnits', 'CMUPoints',
                           'POINT', fieldDefs)

    # create CrossSections
    if nCrossSections > 26:
        nCrossSections = 26
    if nCrossSections < 0:
        nCrossSections = 0
    # note space in position 0
    alphabet = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'

    for n in range(1, nCrossSections + 1):
        xsLetter = alphabet[n]
        xsName = 'CrossSection' + xsLetter
        xsN = 'CS' + xsLetter
        #create feature dataset CrossSectionA
        addMsgAndPrint('  Creating feature data set CrossSection' + xsLetter +
                       '...')
        arcpy.CreateFeatureDataset_management(thisDB, xsName)
        fieldDefs = tableDict['MapUnitPolys']
        if addLTYPE:
            fieldDefs.append(['PTYPE', 'String', 'NullsOK', 100])
        fieldDefs[0][0] = xsN + 'MapUnitPolys_ID'
        createFeatureClass(thisDB, xsName, xsN + 'MapUnitPolys', 'POLYGON',
                           fieldDefs)
        fieldDefs = tableDict['ContactsAndFaults']
        if addLTYPE:
            fieldDefs.append(['LTYPE', 'String', 'NullsOK', 100])
        fieldDefs[0][0] = xsN + 'ContactsAndFaults_ID'
        createFeatureClass(thisDB, xsName, xsN + 'ContactsAndFaults',
                           'POLYLINE', fieldDefs)
        fieldDefs = tableDict['OrientationPoints']
        if addLTYPE:
            fieldDefs.append(['PTTYPE', 'String', 'NullsOK', 100])
        fieldDefs[0][0] = xsN + 'OrientationPoints_ID'
        createFeatureClass(thisDB, xsName, xsN + 'OrientationPoints', 'POINT',
                           fieldDefs)

    # create tables
    tables = ['DescriptionOfMapUnits', 'DataSources', 'Glossary']
    for tb in [
            'RepurposedSymbols', 'StandardLithology', 'GeologicEvents',
            'MiscellaneousMapInformation'
    ]:
        if tb in OptionalElements:
            tables.append(tb)
    for table in tables:
        addMsgAndPrint('  Creating table ' + table + '...')
        try:
            arcpy.CreateTable_management(thisDB, table)
            fieldDefs = tableDict[table]
            for fDef in fieldDefs:
                try:
                    if fDef[1] == 'String':
                        arcpy.AddField_management(thisDB + '/' + table,
                                                  fDef[0], transDict[fDef[1]],
                                                  '#', '#', fDef[3], '#',
                                                  transDict[fDef[2]])
                    else:
                        arcpy.AddField_management(thisDB + '/' + table,
                                                  fDef[0], transDict[fDef[1]],
                                                  '#', '#', '#', '#',
                                                  transDict[fDef[2]])
                except:
                    addMsgAndPrint('Failed to add field ' + fDef[0] +
                                   ' to table ' + table)
                    addMsgAndPrint(arcpy.GetMessages(2))
        except:
            addMsgAndPrint(arcpy.GetMessages())

    ### GeoMaterials
    addMsgAndPrint('  Setting up GeoMaterials table and domains...')
    #  Copy GeoMaterials table
    arcpy.Copy_management(
        os.path.dirname(sys.argv[0]) +
        '/../Resources/GeMS_lib.gdb/GeoMaterialDict',
        thisDB + '/GeoMaterialDict')
    #   make GeoMaterials domain
    arcpy.TableToDomain_management(thisDB + '/GeoMaterialDict', 'GeoMaterial',
                                   'IndentedName', thisDB, 'GeoMaterials')
    #   attach it to DMU field GeoMaterial
    arcpy.AssignDomainToField_management(thisDB + '/DescriptionOfMapUnits',
                                         'GeoMaterial', 'GeoMaterials')
    #  Make GeoMaterialConfs domain, attach it to DMU field GeoMaterialConf
    arcpy.CreateDomain_management(thisDB, 'GeoMaterialConfidenceValues', '',
                                  'TEXT', 'CODED')
    for val in GeoMaterialConfidenceValues:
        arcpy.AddCodedValueToDomain_management(thisDB,
                                               'GeoMaterialConfidenceValues',
                                               val, val)
    arcpy.AssignDomainToField_management(thisDB + '/DescriptionOfMapUnits',
                                         'GeoMaterialConfidence',
                                         'GeoMaterialConfidenceValues')

    #Confidence domains, Glossary entries, and DataSources entry
    if addConfs:
        addMsgAndPrint(
            '  Adding standard ExistenceConfidence and IdentityConfidence domains'
        )
        #  create domain, add domain values, and link domain to appropriate fields
        addMsgAndPrint(
            '    Creating domain, linking domain to appropriate fields')
        arcpy.CreateDomain_management(thisDB, 'ExIDConfidenceValues', '',
                                      'TEXT', 'CODED')
        for item in DefaultExIDConfidenceValues:  # items are [term, definition, source]
            code = item[0]
            arcpy.AddCodedValueToDomain_management(thisDB,
                                                   'ExIDConfidenceValues',
                                                   code, code)
        arcpy.env.workspace = thisDB
        dataSets = arcpy.ListDatasets()
        for ds in dataSets:
            arcpy.env.workspace = thisDB + '/' + ds
            fcs = arcpy.ListFeatureClasses()
            for fc in fcs:
                fieldNames = fieldNameList(fc)
                for fn in fieldNames:
                    if fn in ('ExistenceConfidence', 'IdentityConfidence',
                              'ScientificConfidence'):
                        #addMsgAndPrint('    '+ds+'/'+fc+':'+fn)
                        arcpy.AssignDomainToField_management(
                            thisDB + '/' + ds + '/' + fc, fn,
                            'ExIDConfidenceValues')
        # add definitions of domain values to Glossary
        addMsgAndPrint('    Adding domain values to Glossary')
        ## create insert cursor on Glossary
        cursor = arcpy.da.InsertCursor(
            thisDB + '/Glossary', ['Term', 'Definition', 'DefinitionSourceID'])
        for item in DefaultExIDConfidenceValues:
            cursor.insertRow((item[0], item[1], item[2]))
        del cursor
        # add definitionsource to DataSources
        addMsgAndPrint('    Adding definition source to DataSources')
        ## create insert cursor on DataSources
        cursor = arcpy.da.InsertCursor(thisDB + '/DataSources',
                                       ['DataSources_ID', 'Source', 'URL'])
        cursor.insertRow((
            'FGDC-STD-013-2006',
            'Federal Geographic Data Committee [prepared for the Federal Geographic Data Committee by the U.S. Geological Survey], 2006, FGDC Digital Cartographic Standard for Geologic Map Symbolization: Reston, Va., Federal Geographic Data Committee Document Number FGDC-STD-013-2006, 290 p., 2 plates.',
            'https://ngmdb.usgs.gov/fgdc_gds/geolsymstd.php'))
        del cursor

    # if cartoReps, add cartographic representations to all feature classes
    # trackEdits, add editor tracking to all feature classes and tables
    if cartoReps or trackEdits:
        arcpy.env.workspace = thisDB
        tables = arcpy.ListTables()
        datasets = arcpy.ListDatasets()
        for dataset in datasets:
            addMsgAndPrint('  Dataset ' + dataset)
            arcpy.env.workspace = thisDB + '/' + dataset
            fcs = arcpy.ListFeatureClasses()
            for fc in fcs:
                hasReps, repLyr = cartoRepsExistAndLayer(fc)
                if cartoReps and hasReps:
                    addMsgAndPrint(
                        '    Adding cartographic representations to ' + fc)
                    try:
                        arcpy.AddRepresentation_cartography(
                            fc, fc + '_rep1', 'RuleID1', 'Override1', default,
                            repLyr, 'NO_ASSIGN')
                        """
                            Note the 1 suffix on the representation name (fc+'_rep1') and the RuleID1 and Override1 fields.
                        If at some later time we wish to add additional representations to a feature class, each will
                        require it's own RuleID and Override fields which may be identified, and tied to the appropriate
                        representation, by suffixes 2, 3, ...
                            Naming representations fc+'_rep'+str(n) should be sufficient to identify each representation in a 
                        geodatabase uniquely, and allow for multiple representations within a single feature class.
                            It appears that ArcGIS provides no means of scripting an inventory of representations within
                        feature class or geodatabase. So, the convenience of establishing a coded-value domain that ties
                        representation rule IDs (consecutive integers) to some sort of useful text identifier becomes a
                        necessity for flagging the presence of a representation: One CAN script the inventory of domains
                        in a geodatabase. Run arcpy.da.ListDomains. Check the result for names of the form
                        <featureClassName>_rep??_Rule and voila, you've got a list of representations (and their associated
                        feature classes) in the geodatabase.
                            Moral: If you add a representation, be sure to add an associated coded-value domain and name
                        it appropriately!
                        """
                    except:
                        addMsgAndPrint(arcpy.GetMessages(2))
                if trackEdits:
                    addTracking(fc)
        if trackEdits:
            addMsgAndPrint('  Tables ')
            arcpy.env.workspace = thisDB
            for aTable in tables:
                if aTable <> 'GeoMaterialDict':
                    addTracking(aTable)
コード例 #2
0
        repName = 'FLOWFLG_0'
        ruleField = 'RuleID_FLOWFLG_0'
        overrideField = 'Override_FLOWFLG_0'
        pctRule = [(.25, '25'), (.33, '33'), (.5, '50'), (1, '100')]
    else:
        repName = 'FLOWFLG_1'
        ruleField = 'RuleID_FLOWFLG_1'
        overrideField = 'Override_FLOWFLG_1'
        pctRule = [(.25, '25'), (.33, '33'), (.5, '50'), (.66, '66'),
                   (.75, '75'), (1, '100')]

    arcpy.SetLayerRepresentation_cartography(cascadeFlowTemplate_lyr, repName)
    editingOption = 'STORE_CHANGE_AS_OVERRIDE'
    assignOption = 'NO_ASSIGN'
    arcpy.AddRepresentation_cartography(cascadeFlowFC, repName, ruleField,
                                        overrideField, editingOption,
                                        cascadeFlowTemplate_lyr, assignOption)

    # Execute Calculate Representation Rule for each flow percentage rule
    txt = 'Execute Calculate Representation Rule for each flow percentage rule ({0})...'.format(
        cascadeFlowFCname)
    arcpy.AddMessage(txt)
    arcpy.env.workspace = outGDB
    tempCascadeFlow_lyr = cascadeFlowFCname[:7] + ' ' + cascadeFlowFCname[
        7:11] + ' ' + cascadeFlowFCname[11:18] + ' ' + cascadeFlowFCname[19:]
    arcpy.MakeFeatureLayer_management(cascadeFlowFCname, tempCascadeFlow_lyr)
    for pct, rule in pctRule:
        expression = '\"CASC_PCT\" = ' + str(pct)
        arcpy.SelectLayerByAttribute_management(tempCascadeFlow_lyr,
                                                'NEW_SELECTION',
                                                str(expression))