AnsweredAssumed Answered

Interesting results with spatial Join using INTERSECT

Question asked by CCweedcontrol on Jul 15, 2016
Latest reply on Jul 29, 2016 by CCweedcontrol

I am not sure what's is going on here but if use arcpy.SpatialJoin_analysis and with INTERSECT as the match_option with two layers i get something that doesn't look right. The layer Fzon3 has zoning COM, IND or RES i do the spatial join to Taxparcels but the Spatial Join with INTERSECT doesn't look right, see picture. After the script is ran and i add the layers to arcmap and i query the FZon2 layer for "COM"(COM  is the red) you can see that the spatial join didn't spatial join correctly because there should be more parcels with "COM". Any help would be great thanks!

 

#WORKING SCRIPT
# Import arcpy module
import sys, arcpy, traceback, os
from arcpy import env
import win32com.client
from os import path as p
from datetime import datetime as d
startTime = d.now()


# Local variables:
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "C:\TEMP\Test.gdb"
arcpy.env.qualifiedFieldNames = False

if arcpy.Exists("C:\TEMP\Test.gdb\FZon2"):
    arcpy.Delete_management("C:\TEMP\Test.gdb\FZon2")

Tax = r"C:\TEMP\Test|Taxparcels"
Tax1 = "C:\TEMP\Test.gdb"
arcpy.FeatureClassToGeodatabase_conversion(Tax, Tax1)

Padm1 = "C:\TEMP\Test.gdb"
Taxparcels = "C:\TEMP\Test.gdb\Taxparcels"

# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(Taxparcels, "In_memory\TaxPar")
TaxPar1 = "In_memory\TaxPar"
arcpy.MakeFeatureLayer_management("In_memory\TaxPar", TaxPar1)


FZon3 = "C:\TEMP\Test.gdb\FUTURE_LAND_USE_ZONING"

def Layers0(TaxPar1, FZon3):
    FieldMapString = "" \
                + """DXF_TEXT "DXF_TEXT" true true false 18 Text 0 0 ,First,#,""" + TaxPar1 + """,DXF_TEXT,-1,-1;"""\
                + """ACCOUNT "ACCOUNT" true true false 11 Text 0 0 ,First,#,""" + TaxPar1 + """,ACCOUNT,-1,-1;"""\
                + """ACRES "ACRES" true true false 4 Double 10 3 ,First,#,""" + TaxPar1 + """,ACRES,-1,-1;"""\
                + """Instrument "Instrument" true true false 10 Text 0 0 ,First,#,""" + TaxPar1 + """,Instrument,-1,-1;"""\
                + """SiteAddress "SiteAddress" true true false 106 Text 0 0 ,First,#,""" + TaxPar1 + """,SiteAddress,-1,-1;"""\
                + """SiteCity "SiteCity" true true false 32 Text 0 0 ,First,#,""" + TaxPar1 + """,SiteCity,-1,-1;"""\
                + """SiteZip "SiteZip" true true false 10 Text 0 0 ,First,#,""" + TaxPar1 + """,SiteZip,-1,-1;"""\
                + """SubName "SubName" true true false 20 Text 0 0 ,First,#,""" + TaxPar1 + """,SubName,-1,-1;"""\
                + """OwnerName "OwnerName" true true false 100 Text 0 0 ,First,#,""" + TaxPar1 + """,OwnerName,-1,-1;"""\
                + """OwnerSec "OwnerSec" true true false 64 Text 0 0 ,First,#,""" + TaxPar1 + """,OwnerSec,-1,-1;"""\
                + """Address "Address" true true false 64 Text 0 0 ,First,#,""" + TaxPar1 + """,Address,-1,-1;"""\
                + """City "City" true true false 32 Text 0 0 ,First,#,""" + TaxPar1 + """,City,-1,-1;"""\
                + """State "State" true true false 4 Text 0 0 ,First,#,""" + TaxPar1 + """,State,-1,-1;"""\
                + """ZipCode "ZipCode" true true false 10 Text 0 0 ,First,#,""" + TaxPar1 + """,ZipCode,-1,-1;"""\
                + """Legal "Legal" true true false 254 Text 0 0 ,First,#,""" + TaxPar1 + """,Legal,-1,-1;"""\
                + """Sec "Sec" true true false 2 Text 0 0 ,First,#,""" + TaxPar1 + """,Sec,-1,-1;"""\
                + """Twp "Twp" true true false 2 Text 0 0 ,First,#,""" + TaxPar1 + """,Twp,-1,-1;"""\
                + """Rng "Rng" true true false 2 Text 0 0 ,First,#,""" + TaxPar1 + """,Rng,-1,-1;"""\
                + """Quarter "Quarter" true true false 2 Text 0 0 ,First,#,""" + TaxPar1 + """,Quarter,-1,-1;"""\
                + """TaxCode "TaxCode" true true false 7 Text 0 0 ,First,#,""" + TaxPar1 + """,TaxCode,-1,-1;"""\
                + """FireDist "FireDist" true false false 64 Text 0 0 ,First,#,""" + TaxPar1 + """,FireDist,-1,-1;"""\
                + """HighwayDist "HighwayDist" true false false 74 Text 0 0 ,First,#,""" + TaxPar1 + """,HighwayDist,-1,-1;"""\
                + """SchoolDist "SchoolDist" true false false 64 Text 0 0 ,First,#,""" + TaxPar1 + """,SchoolDist,-1,-1;"""\
                + """Acres1 "Acres1" true false false 4 Double 10 3 ,First,#,"""+ TaxPar1 + """,Acres1,-1,-1;"""\
                + """SITE_ADDR "SITE_ADDR" true false false 50 Text 0 0 ,First,#,""" + TaxPar1 + """,SITE_ADDR,-1,-1;"""\
                + """FZONE_CODE "FZONE_CODE" true false false 10 Text 0 0 ,First,#,"""+ FZon3 + """,ZONE_CODE,-1,-1;"""\
                
                
    fieldmappings = arcpy.FieldMappings()
    fieldmappings.loadFromString(FieldMapString)
    return fieldmappings


arcpy.SpatialJoin_analysis(TaxPar1, FZon3, "C:\TEMP\Test.gdb\FZon2", "JOIN_ONE_TO_ONE", "KEEP_ALL",Layers0(TaxPar1, FZon3), "INTERSECT")

try:
    print '(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')'


except Exception, e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message

Attachments

Outcomes