Exemplo n.º 1
0
def calcHotspots(paths,states,segl):
    import arcpy

    shpath = paths["Shapefiles"]

    for state in states:
        input_fc = shpath + "{0}_TractsWData.shp".format(state)
        tpath = shpath + "Centroids/"
        if not os.path.exists(tpath):
            os.makedirs(tpath)
        output_fc = tpath + "{0}_Hotspot.shp".format(state)
        print ("Calculating hotspot for ")
        for segy in segl:
            arcpy.HotSpots_stats(input_fc, segy, output_fc)
Exemplo n.º 2
0
point_count = int(arcpy.GetParameterAsText(4))
boundary = arcpy.GetParameterAsText(5)
workspace = arcpy.GetParameterAsText(6)

buffer_l = workspace + "\\buffered.shp"
buffer_erased = workspace + "\\buffer_erased.shp"
HotSpots_l = workspace + "\\HotSpots.shp"
HotSpots_signif = workspace + "\\HotSpots_sig.shp"
HotSpots_signif_buffer =  workspace + "\\HotSpots_sig_buff.shp"
buffer_erased_final = workspace + "\\buffer_erased_final.shp"
outFC = workspace + "\\absence_samples.shp"

arcpy.Buffer_analysis(point_layer,buffer_l, "%s Meters"%buffer, "FULL", "ROUND", "NONE", "")
arcpy.Erase_analysis(boundary, buffer_l, buffer_erased,'#')

arcpy.HotSpots_stats(point_layer, weight_field, HotSpots_l,"FIXED_DISTANCE_BAND", "EUCLIDEAN_DISTANCE", "NONE","#", "#", "#","NO_FDR")
my_addfield(HotSpots_l, "buff_dis", type="n")
with arcpy.da.UpdateCursor(HotSpots_l, ["GiPValue", "GiZScore","buff_dis"]) as cursor:
	for row in cursor:
		if row[1] > 1.96 and row[0] < 0.05:
			row[2] = float(1)
		cursor.updateRow(row)

try:
	arcpy.AddField_management(inFeatures, "temp7788", "DOUBLE",18 ,11)
	arcpy.DeleteField_management(inFeatures, "temp7788")
except:
	pass

arcpy.Select_analysis(HotSpots_l, HotSpots_signif, "\"buff_dis\" = 1")
arcpy.Buffer_analysis(HotSpots_signif,HotSpots_signif_buffer, "%s Meters"%HotSpots_buffer, "FULL", "ROUND", "NONE", "")
Exemplo n.º 3
0
		arcpy.MakeFeatureLayer_management(urban_areas_2010_shp, urban_area, name_select, "", "FID FID VISIBLE NONE;Shape Shape VISIBLE NONE;UACE10 UACE10 VISIBLE NONE;AFFGEOID10 AFFGEOID10 VISIBLE NONE;GEOID10 GEOID10 VISIBLE NONE;NAME10 NAME10 VISIBLE NONE;NAMELSAD10 NAMELSAD10 VISIBLE NONE;LSAD10 LSAD10 VISIBLE NONE;UATYP10 UATYP10 VISIBLE NONE;ALAND10 ALAND10 VISIBLE NONE")
		
		print "- Area clip of Census Tracts"
		# Process: Clip (2)
		arcpy.Clip_analysis(state_tracts_clip, urban_area, ua_tracts_00, "")
		
		print "- Join DEC Data"
		# Process: Feature Layer
		arcpy.MakeFeatureLayer_management (ua_tracts_00,  layer_dec)
		# Process: Add Join
		arcpy.AddJoin_management(layer_dec, "CTIDFP00", dec, "geoid2", "KEEP_COMMON")
		arcpy.CopyFeatures_management(layer_dec, ua_dec)		
		
		print "- Income and Race Clusters - 2500 m"
		# Process: Hot Spot Analysis (Getis-Ord Gi*)
		arcpy.HotSpots_stats(ua_dec, "income_hh_", uat_inc_hspt00, "ZONE_OF_INDIFFERENCE", "EUCLIDEAN_DISTANCE", "NONE", "2500", "", "")
		arcpy.HotSpots_stats(ua_dec, "perc_white", uat_pw_hspt00, "ZONE_OF_INDIFFERENCE", "EUCLIDEAN_DISTANCE", "NONE", "2500", "", "")
		
		#2012
		
		#Generate state, urban area lists (for projections, etc.)
				
		print "[2012]"
		
		st_list = []
		for s in range(len(st)):
			st_list = st_list + [tract_12 + st[s] + "_tracts_12.shp"]		
				
		print "- Merge for Multi-state Areas"
		# Process: Merge
		#arcpy.Union_analysis(st_list[:len(st)], state_tracts_union_shp, "ALL", "", "GAPS")
Exemplo n.º 4
0
import arcpy
import os
from arcpy import env
from arcpy.sa import *

try:
    # Get parameters
    features = arcpy.GetParameter(0)

    # Do outlier
    out_features = arcpy.CreateUniqueName('results',
                                          arcpy.env.scratchWorkspace)
    arcpy.AddMessage('Output directory: ' + out_features)
    arcpy.HotSpots_stats(Input_Feature_Class=features,
                         Input_Field='VALUE',
                         Output_Feature_Class=out_features)
    arcpy.AddMessage('Outlier analysis complete')

    # Write raster as result
    arcpy.SetParameter(1, out_features)

except Exception as e:
    arcpy.AddError(str(e))

finally:
    arcpy.Delete_management('in_memory')
Exemplo n.º 5
0
                          field_type='FLOAT')
arcpy.CalculateField_management(census_prj, 'area_true',
                                "float(!SHAPE.AREA!) / 1E6", "PYTHON")

#compare total population to mean NDVI normalized by population density
arcpy.AddField_management(census_prj, field_name='ageNDVI', field_type='FLOAT')
arcpy.CalculateField_management(census_prj, 'ageNDVI',
                                '(!MEAN! / !DP0010006!)', "PYTHON")

#compare male population to mean NDVI normalized by total population
arcpy.AddField_management(census_prj,
                          field_name='maleNDVI',
                          field_type='FLOAT')
arcpy.CalculateField_management(census_prj, 'maleNDVI',
                                '(!MEAN! / !DP0030002! )', "PYTHON")

#compare total hispanic ethnicity to mean NDVI normalized by total population
arcpy.AddField_management(census_prj,
                          field_name='his_NDVI',
                          field_type='FLOAT')
arcpy.CalculateField_management(census_prj, 'his_NDVI',
                                '(!MEAN! / !DP0180002!)', "PYTHON")

#hotspot analysis
out_ageNDVI = workspace + 'out_ageNDVI.shp'
out_maleNDVI = workspace + 'out_maleNDVI.shp'
out_hisNDVI = workspace + 'out_hisNDVI.shp'
arcpy.HotSpots_stats(census_prj, 'ageNDVI', out_ageNDVI)
arcpy.HotSpots_stats(census_prj, 'maleNDVI', out_maleNDVI)
arcpy.HotSpots_stats(census_prj, 'his_NDVI', out_hisNDVI)
Exemplo n.º 6
0
    raster_loc = arcpy.GetParameter(0)

    # save raster cellsize
    cellsize = arcpy.GetRasterProperties_management(raster_loc, 'CELLSIZEX')

    # convert raster to points
    arcpy.AddMessage('Converting to points: ' + str(raster_loc))
    in_point_mem = 'in_memory\\raster_points'
    arcpy.RasterToPoint_conversion(raster_loc, in_point_mem, "VALUE")
    arcpy.AddMessage('Conversion to points complete')

    # Do hot spot
    out_features = 'in_memory\\out_group'
    arcpy.AddMessage('Output directory: ' + out_features)
    arcpy.HotSpots_stats(Input_Feature_Class=in_point_mem,
                         Input_Field='grid_code',
                         Output_Feature_Class=out_features)
    arcpy.AddMessage('Hot spot analysis complete')

    # add field to use for classification
    arcpy.AddField_management(out_features, 'COLOR', 'SHORT')
    codeblock = '''
def getColor(pval, zscore):
    if pval <= 0.01 and zscore > 0:
        return 1
    elif pval <= 0.01 and zscore <= 0:
        return -1
    elif pval <= 0.05 and zscore > 0:
        return 2
    elif pval <= 0.05 and zscore <= 0:
        return -2
Exemplo n.º 7
0
    years = ['1970', '1980', '1990', '2000', '2010']

    no_seventy = ['75', '78', '98']

    for y in years:

        minc = "minc" + y
        shrwht = "shrwht" + y
        pop = "pop" + y
        op = "[" + pop + "]/[AREA]"

        uat_inc_hspt = "uat_inc_hspt_" + str(c) + "_" + y + ".shp"
        uat_pw_hspt = "uat_pw_hspt_" + str(c) + "_" + y + ".shp"

        print "- Compute Pop Dens " + y
        # Process: Calculate Field
        arcpy.CalculateField_management(ua_ncdb, "pdens", op, "VB", "")

        print "- Income and Race Clusters - 1250 m [" + y + "]"
        # Process: Hot Spot Analysis (Getis-Ord Gi*)
        arcpy.HotSpots_stats(ua_ncdb, minc, uat_inc_hspt,
                             "FIXED_DISTANCE_BAND", "EUCLIDEAN_DISTANCE",
                             "NONE", "1250", "", "")
        arcpy.HotSpots_stats(ua_ncdb, shrwht, uat_pw_hspt,
                             "FIXED_DISTANCE_BAND", "EUCLIDEAN_DISTANCE",
                             "NONE", "1250", "", "")

    stop = timeit.default_timer()

    print "Time:" + str((stop - start) / 60)
Exemplo n.º 8
0
    # Process: Add Join
    arcpy.AddJoin_management(layerName, "GEOID", wac, "trct", "KEEP_COMMON")
    arcpy.CopyFeatures_management(layerName, urban_area_join)

    print "- Limit to Non-Truncated Tracts"
    # Process: Make Feature Layer
    thr = 0.01
    name_select = "\"AREA\" > " + str(thr)
    #print name_select
    # Process: Make Feature Layer
    arcpy.MakeFeatureLayer_management(
        urban_area_join, valid_trcts, "\"AREA\" > 0.01", "",
        "FID FID VISIBLE NONE;Shape Shape VISIBLE NONE;STATEFP STATEFP VISIBLE NONE;COUNTYFP COUNTYFP VISIBLE NONE;TRACTCE TRACTCE VISIBLE NONE;GEOID GEOID VISIBLE NONE;NAME NAME VISIBLE NONE;NAMELSAD NAMELSAD VISIBLE NONE;MTFCC MTFCC VISIBLE NONE;FUNCSTAT FUNCSTAT VISIBLE NONE;ALAND ALAND VISIBLE NONE;AWATER AWATER VISIBLE NONE;INTPTLAT INTPTLAT VISIBLE NONE;INTPTLON INTPTLON VISIBLE NONE;AREA AREA VISIBLE NONE;state state VISIBLE NONE;trct trct VISIBLE NONE;trctname trctname VISIBLE NONE;ca01 ca01 VISIBLE NONE;ca02 ca02 VISIBLE NONE;ca03 ca03 VISIBLE NONE;ce01 ce01 VISIBLE NONE;ce02 ce02 VISIBLE NONE;ce03 ce03 VISIBLE NONE;cns01 cns01 VISIBLE NONE;cns02 cns02 VISIBLE NONE;cns03 cns03 VISIBLE NONE;cns04 cns04 VISIBLE NONE;cns05 cns05 VISIBLE NONE;cns06 cns06 VISIBLE NONE;cns07 cns07 VISIBLE NONE;cns08 cns08 VISIBLE NONE;cns09 cns09 VISIBLE NONE;cns10 cns10 VISIBLE NONE;cns11 cns11 VISIBLE NONE;cns12 cns12 VISIBLE NONE;cns13 cns13 VISIBLE NONE;cns14 cns14 VISIBLE NONE;cns15 cns15 VISIBLE NONE;cns16 cns16 VISIBLE NONE;cns17 cns17 VISIBLE NONE;cns18 cns18 VISIBLE NONE;cns19 cns19 VISIBLE NONE;cns20 cns20 VISIBLE NONE;cr01 cr01 VISIBLE NONE;cr02 cr02 VISIBLE NONE;cr03 cr03 VISIBLE NONE;cr04 cr04 VISIBLE NONE;cr05 cr05 VISIBLE NONE;cr07 cr07 VISIBLE NONE;ct01 ct01 VISIBLE NONE;ct02 ct02 VISIBLE NONE;cd01 cd01 VISIBLE NONE;cd02 cd02 VISIBLE NONE;cd03 cd03 VISIBLE NONE;cd04 cd04 VISIBLE NONE;cs01 cs01 VISIBLE NONE;cs02 cs02 VISIBLE NONE;cfa01 cfa01 VISIBLE NONE;cfa02 cfa02 VISIBLE NONE;cfa03 cfa03 VISIBLE NONE;cfa04 cfa04 VISIBLE NONE;cfa05 cfa05 VISIBLE NONE;cfs01 cfs01 VISIBLE NONE;cfs02 cfs02 VISIBLE NONE;cfs03 cfs03 VISIBLE NONE;cfs04 cfs04 VISIBLE NONE;cfs05 cfs05 VISIBLE NONE;emp_dens emp_dens VISIBLE NONE"
    )

    print "- Add Emp Dens Field"
    # Process: Add Field
    arcpy.AddField_management(valid_trcts, "EMP_DENS", "DOUBLE", "", "", "",
                              "", "NULLABLE", "NON_REQUIRED", "")

    print "- Compute Emp Dens"
    # Process: Calculate Field
    arcpy.CalculateField_management(valid_trcts, "emp_dens", "[ca01]/ [AREA]",
                                    "VB", "")

    print "- Employment Clusters - 500 m"
    # Process: Hot Spot Analysis (Getis-Ord Gi*)
    arcpy.HotSpots_stats(valid_trcts, "emp_dens", uat_emp_hspt,
                         "FIXED_DISTANCE_BAND", "EUCLIDEAN_DISTANCE", "NONE",
                         "500", "", "")
# Process: Generate Spatial Weights Matrix
arcpy.GenerateSpatialWeightsMatrix_stats(LondonWards, "ID", contig_swm,
                                         "CONTIGUITY_EDGES_CORNERS",
                                         "EUCLIDEAN", "1", "", "0",
                                         "ROW_STANDARDIZATION", "", "", "", "")

# Process: Cluster and Outlier Analysis (Anselin Local Morans I)
arcpy.ClustersOutliers_stats(LondonWards, "AvgGCSE201", MoransContig,
                             "GET_SPATIAL_WEIGHTS_FROM_FILE",
                             "EUCLIDEAN_DISTANCE", "NONE", "", contig_swm,
                             "NO_FDR")

# Process: Hot Spot Analysis (Getis-Ord Gi*)
arcpy.HotSpots_stats(LondonWards, "AvgGCSE201", Gearys_Contig,
                     "GET_SPATIAL_WEIGHTS_FROM_FILE", "EUCLIDEAN_DISTANCE",
                     "NONE", "", "", contig_swm, "NO_FDR")

# Process: Generate Spatial Weights Matrix (3)
arcpy.GenerateSpatialWeightsMatrix_stats(LondonWards, "ID", invidist_swm,
                                         "INVERSE_DISTANCE", "EUCLIDEAN", "1",
                                         "", "0", "ROW_STANDARDIZATION", "",
                                         "", "", "")

# Process: Hot Spot Analysis (Getis-Ord Gi*) (2)
arcpy.HotSpots_stats(LondonWards, "AvgGCSE201", Geary_Individist,
                     "GET_SPATIAL_WEIGHTS_FROM_FILE", "EUCLIDEAN_DISTANCE",
                     "NONE", "", "", invidist_swm, "NO_FDR")

# Process: Generate Spatial Weights Matrix (2)
arcpy.GenerateSpatialWeightsMatrix_stats(LondonWards, "ID", neighbour_swm,
Exemplo n.º 10
0
        #arcpy.CopyFeatures_management(layer_acs, ua_lehd_acs)

        print "- Add Emp Dens Field"
        # Process: Add Field
        arcpy.AddField_management(ua_lehd_acs, "EMP_DENS", "DOUBLE", "", "",
                                  "", "", "NULLABLE", "NON_REQUIRED", "")

        print "- Compute Emp Dens"
        # Process: Calculate Field
        arcpy.CalculateField_management(ua_lehd_acs, "emp_dens",
                                        "[ca01]/ [AREA]", "VB", "")

        print "- Employment Clusters - 500 m"
        # Process: Hot Spot Analysis (Getis-Ord Gi*)
        arcpy.HotSpots_stats(ua_lehd_acs, "emp_dens", uat_emp_hspt,
                             "FIXED_DISTANCE_BAND", "EUCLIDEAN_DISTANCE",
                             "NONE", "500", "", "")

        #print "- Income and Race Clusters - 2500 m"
        # Process: Hot Spot Analysis (Getis-Ord Gi*)
        #arcpy.HotSpots_stats(valid_trcts, "income_hh_", uat_inc_hspt, "ZONE_OF_INDIFFERENCE", "EUCLIDEAN_DISTANCE", "NONE", "2500", "", "")
        #arcpy.HotSpots_stats(valid_trcts, "perc_white", uat_pw_hspt, "ZONE_OF_INDIFFERENCE", "EUCLIDEAN_DISTANCE", "NONE", "2500", "", "")

        ##MODULE 3

        print "- High Density Select"

        name_select = "\"GiZScore\" > 2.58"
        arcpy.MakeFeatureLayer_management(uat_emp_hspt, uat_hspt_hi,
                                          name_select)