import arcpy
import random
import math


arcpy.env.overwriteOutput = True
InputPoint = "C:\Users\ww410490\Desktop\Python\GeogMask\TestPoint.shp"
sc = arcpy.SearchCursor(InputPoint)
row = sc.next()

p_x = []
p_y = []
while row:
    p_x.append(row.x)
    p_y.append(row.y)
    row = sc.next()
    


mask = (max(p_x) - min(p_x)) / 20  # 10 E11

p2_x = []
p2_y = []
sc = arcpy.SearchCursor(InputPoint)
row = sc.next()

while row:
    
    
    p2_x.append(row.x + mask)
    p2_y.append(row.y + mask)
    row = sc.next()


# check point outside area
i =0
num = len(p_x)

InsideIndex = []

while i < num:
    output = r"D:\\Data\\" + 'test' + str(i) + '.shp'
    ptList = [ [ p2_x[i], p2_y[i] ] ]
    pt = arcpy.Point()
    ptGeoms = []
    for p in ptList:
        pt.X = p[0]
        pt.Y = p[1]
        ptGeoms.append(arcpy.PointGeometry(pt) )
        arcpy.CopyFeatures_management(ptGeoms, output )

    join_features = output
    target_features = "C:\Users\ww410490\Desktop\Python\GeogMask\TestArea.shp"
    out_feature_class = "D:\\Data\\AreaJoinPoints" + str(i) + '.shp'
    arcpy.SpatialJoin_analysis(target_features, join_features, out_feature_class)

    sc2 = arcpy.SearchCursor(out_feature_class)
    row2 = sc2.next()
    while row2:
        InsideIndex.append(row2.Join_Count)
        row2 = sc2.next()
         

    

    i += 1
    

    
# area location
#target_features = "C:\Users\ww410490\Desktop\Python\GeogMask\TestArea.shp"

j = 0
ptList2 = []

while j <  len(InsideIndex):
    if InsideIndex[j] == 1:
        ptList2.append([ p2_x[j], p2_y[j] ])

    if InsideIndex[j] == 0: # use original xy
        ptList2.append([ p_x[j], p_y[j] ])
        
        
        



    j += 1

# ptList2
pt2 = arcpy.Point()
ptGeoms2 = []
for p in ptList2:
    pt2.X = p[0]
    pt2.Y = p[1]
    ptGeoms2.append(arcpy.PointGeometry(pt2))

arcpy.CopyFeatures_management(ptGeoms2, r"D:\\Data\\" + 'final' +  '.shp')
    



print 'Finish'
