Пример #1
0
    # create list of fields to transpose
    all_fields = [f.name for f in arcpy.ListFields(tab_area)]
    exclude_fields = ["TRACT_NAME", "OID", "OBJECTID"]
    transpose_fields = [x for x in all_fields if x not in exclude_fields]
    transpose_fields = [str(x) for x in transpose_fields]
    new_names = [x[-2:] for x in transpose_fields]
    transpose_fields = [
        transpose_fields[i] + " " + new_names[i]
        for i in xrange(len(transpose_fields))
    ]

    # transpose fields
    transpose = arcpy.TransposeFields_management(tab_area,
                                                 ';'.join(transpose_fields),
                                                 "transpose",
                                                 "Tier_Resilience", "Area",
                                                 "TRACT_NAME")

    # get total area
    with arcpy.da.SearchCursor(transpose, "Area") as cursor:
        summed_total = 0
        for row in cursor:
            summed_total = summed_total + int(row[0])

    # convert areas to percentage and round to nearest 1%
    with arcpy.da.UpdateCursor(transpose, "Area") as cursor:
        for row in cursor:
            row[0] = int(row[0]) / float(summed_total) * 100
            row[0] = int(1 * round(float(row[0] / 1)))
            cursor.updateRow(row)
Пример #2
0
			#then use this to construct the dissilove varriables.
			output_dict = [x for x in input_dict if x['fieldName'] == field.name]

			#if field exists in template we will use the field in output ddata.
			#  need to know who we want the table data formated - derieved from tempatle json
			if (output_dict):
				transposeField = output_dict[0]['fieldName']
				temp_transposed = os.path.join(outGDB, 'temp_transposed_' + currentGeographyLevel + '_'  + transposeField)
				# temp_transposed = os.path.join(outGDB,'test')

				#if feature class exists delete
				if arcpy.Exists(temp_transposed):
					arcpy.Delete_management(temp_transposed)

                #normalized data as in database normalization
				arcpy.TransposeFields_management(temp_dissolve, aggreatate_type + "_" + transposeField + " " + aggreatate_type + "_" + transposeField, temp_transposed, "chart_label", "chart_value", currentGeographyLevel + ";FIRST_HUC_12")

				print '  ' + transposeField
				for f in output_dict[0]:
					print '    ' + f

                #add fields from template to the normalized table if they do not exist
				for field in transposedTemplate:
					fieldName = field['fieldname']
					fieldType = field['fieldType']
					fieldLength = field['Length']
					if not FieldExist(temp_transposed,fieldName):
						arcpy.AddField_management(temp_transposed, fieldName, fieldType, "", "", fieldLength, "", "NULLABLE", "NON_REQUIRED", "")

				# Process: calculate_geography_level
				arcpy.CalculateField_management(temp_transposed, "geography_level",   geog['geographyLevel'], "PYTHON", "")
Пример #3
0
			#find matching instance of field on data.
			#then use this to construct the dissilove varriables.
			output_dict = [x for x in input_dict if x['fieldName'] == field.name]

			#if field exists in template we will use the field in output ddata.
			#  need to know who we want the table data formated - derieved from tempatle json
			if (output_dict):
				transposeField = output_dict[0]['fieldName']
				temp_transposed = os.path.join(outGDB, 'temp_transposed_' + currentGeographyLevel + '_'  + transposeField)

				#if feature class exists delete
				if arcpy.Exists(temp_transposed):
					arcpy.Delete_management(temp_transposed)

                #dissovle the geography level
				arcpy.TransposeFields_management(temp_dissolve, aggreatate_type + "_" + transposeField + " " + aggreatate_type +"_" + transposeField, temp_transposed, "chart_label", "chart_value",  geog['fieldName'])

				print '  ' + transposeField
				for f in output_dict[0]:
					print '    ' + f

                #add fields from template to the normalized table if they do not exist
				for field in transposedTemplate:
					fieldName = field['fieldname']
					fieldType = field['fieldType']
					fieldLength = field['Length']
					if not FieldExist(temp_transposed,fieldName):
						arcpy.AddField_management(temp_transposed, fieldName, fieldType, "", "", fieldLength, "", "NULLABLE", "NON_REQUIRED", "")


				# Process: calculate_geography_level