2

I'm trying to create a national.shp to cover the entire countries land. I made index called "province" to help me update the information in my attribute table from the national shapefile.

The idea is to create each provincial polygon files first and then merge into the national file.

The problem is that after the data merging, I found that an overlap exists for my file, (same polygon, two values). Is there a way to get rid of one of the values?

enter image description here

I tried to use dissolve tool, but that way I will have to lose my "province" field, which will be needed if I want to update my national.shp... I tried to trace the province value back, just can't seem to find a method.

  • 1
    Welcome to GIS:SE Max_Guo! Could you please mention which ArcGIS version and licence you are using? If you have an advanced licence, you could use the Find Identical Tool and the Delete Identical Tool. – Joseph Jun 12 '15 at 13:48
  • Could you use 2 da cursors and compare SHAPE@ values and then save one of the features to be deleted after the comparison? Basically, a loop in a loop. Check geometry but also compare a unique identifier field so you don't delete all your features. So different unique identifiers, same geometry, add to a list to be deleted. – Branco Jun 12 '15 at 13:50
  • I was building this from a GUI, so the "Province" identifier was built to be given by the user, from that point, should I ask for another data ID? Also by compare SHAPE@, do you mean that I should use select by location to compare the polygons? @Branco – MaxG Jun 12 '15 at 14:06
  • 1
    The find/delete identical tool will find the part with the same filed name, though there they have different names for the "province" @Joseph – MaxG Jun 12 '15 at 14:07
  • 1
    @Max_Guo Please consider adding your solution as an answer so that this question can be considered resolved. – Aaron Jun 12 '15 at 16:18
3

The easiest way is to use the "erase" tool from the arcpy. So basically what happens is, the "erase" tool will find the union part of two layers and take off the overlap areas from the input layer. Then you can apply the merge process(the merged file will not have duplicates). My sample code is below:

        #-------------------Delete the duplicate areas --------------

        from arcpy import env
        env.workspace = strFolder
        eraseinput = "national.shp"
        erasefeature = newProvince +".shp"
        eraseOutput = strFolder + "/" + "national2.shp"
        arcpy.Erase_analysis(eraseinput, erasefeature, eraseOutput)


        #--------------- merge the polygons together ---------------- 

        # feature classes to be merged
        oldPoly = "national2.shp"
        newPoly = newProvince +".shp"

        # Create FieldMappings object to manage merge output fields
        fieldMappings = arcpy.FieldMappings()

        # Add all fields from both oldpolygon and polygon
        fieldMappings.addTable(oldPoly)
        fieldMappings.addTable(newPoly)

        # Add input fields "GRIDCODE" into new output field
        fldMap_lclass = arcpy.FieldMap()
        fldMap_lclass.addInputField(oldPoly,"GRIDCODE")
        fldMap_lclass.addInputField(newPoly,"GRIDCODE")
        # Set name of new output field "Land_Class"
        lclass = fldMap_lclass.outputField
        lclass.name = "LandClass"
        fldMap_lclass.outputField = lclass
        # Add output field to field mappings object
        fieldMappings.addFieldMap(fldMap_lclass)


        uptodatePoly = strFolder + "/new_national"
        arcpy.Merge_management([oldPoly, newPoly], uptodatePoly,fieldMappings)


        print ("The new national file is now created")
  • 1
    You should really copy/paste the code. Having an image of code is not exactly user friendly. – ianbroad Jun 12 '15 at 16:30
0

I may be misunderstanding you, but you currently have x number of individual feature classes, one for each province, and want to merge them into one feature class with x number of features? Ignore below if that's not what you meant.

One way to do that would be to create an empty national.shp feature class and use the Simple Data Loader to add the individual province files in. Or just copy/paste. There are probably other methods as well, just thinking of a quick and easy way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.