Using ArcGIS 10.3 for desktop.

For our noxious weed surveys, we have some features recorded as polygons, some as lines, and some as points. I would like to convert everything to points, and then merge it all into one feature class for each species. I have minimal python experience, but am willing to try.

It is currently set up so that there are three file geodatabases. NoxiousWeeds_points.gdb, NoxiousWeeds_poly.gdb, and NoxiousWeeds_lines.gdb. Within each geodatabase is a separate feature class for each species. E.g., "HimalayanBlackberry_points" or "ReedCanarygrass_poly," etc. Names are consistent between the three geodatabases, the only thing that varies is the suffix.

What I'm Trying to Do:

I would like to be able to simply point arc to the three geodatabases and have it automatically convert the line and polygon feature classes to points, then merge with the matching point feature class based on the name, and then saved to a fourth, separate geodatabase with a slightly modified name. For example, "Knotweed_poly" and "knotweed_line" would both be converted to points, merged with the existing "knotweed_points," and then saved as "Knotweed_merged" in a fourth, separate geodatabase named "NoxiousWeeds_merged." Ideally I could simply point arc to the geodatabases that contain all these files and it would go through this whole process for each species by itself without me having to manually select each file. Note that I would also like the original source files to remain unaltered.

I suspect this is possible through some combination of python and ModelBuilder. If so, how would you recommend I go about it?

  • Definitely possible...I'd see how much of this post you can follow first and then coming back here if you have a more specific questions or it's not working: gis.stackexchange.com/questions/108113/… – brokev03 Aug 13 '15 at 0:38
  • What do you expect as output when you convert your polys and lines to points? Centroids, vertices...? – user2856 Aug 13 '15 at 1:12
  • try 'spatial join' your line, point and polygon features with features having new names and attributes, without converting their geometry into points. – Ghori Aug 13 '15 at 9:51

I suggest populating a python dictionary. The key would be your category, and the values would be a python list of your feature classes to merge. Use a for loop to iterate through your geodatabases, and another to iterate through your feature classes. Check each feature class to determine if it contains points. If not, perform a Feature To Point conversion. Something like this (untested):


#List of GDBs
gdbs = [r"c:\test\NoxiousWeeds_points.gdb",

#Merge GDB
mergeGdb = r"c:\test\NoxiousWeeds_merged.gdb"

#Use "in_memory" or workspace geodatabase on disk
workspace = "in_memory"

#-End Locals

#Import modules
from arcpy import *
import os

#dictionary to be populated with list of all feature classes
fcsDi = {}

#Garbage for deleting created feature classes
garbage = []

#Iterate through three GDBs
for gdb in gdbs:
    print "Iterating", gdb
    #Set workspace to GDB
    env.workspace = gdb

    #List feature classes in gdb
    fcs = ListFeatureClasses ()

    #Iterate through feature classes
    for fc in fcs:
        #Check if feature class is points
        shape = Describe (fc).shapeType
        if shape != "Point":
            #Feature to point
            outFile = os.path.join (workspace, fc + "_point")
            FeatureToPoint_management (fc, outFile, "INSIDE")
            garbage += [outFile]
            outFile = os.path.join (gdb, fc)

        #Remove unwanted text to determine merge
        fcCategory = fc.replace ("_poly", "").replace ("_lines", "").replace ("_points", "")

        #Check if category is in dictionary
        if fcCategory in fcsDi:
            fcsDi [fcCategory] += [outFile]
        #If not in dictionary
            fcsDi [fcCategory] = [outFile]

#Iterate through dictionary keys
for category in fcsDi:
    print "Merging", category
    #Path to merge feature class
    outFc = os.path.join (mergeGdb, category + "_merged")
    #Get list of feature classes from dictionary
    fcs = fcsDi [category]
    print "Created:", outFc
    Merge_management (fcs, outFc)

#Clean up
for trash in garbage:
    Delete_management (trash)
  • Holy moly! I owe you a beer! I'll try this out tomorrow at work and report back! Thank you! One more component that would be nice to have...do you think there's any easy way for a script/model to merge ONLY new/changed values into an existing _merged.gdb? So, it would take only the values in the regular gdb's that had been changed/added since the the merged.gdb was created/last merged...and then merge those changes - overwriting values in the corresponding _merged feature classes that had changed/adding values that were brand new? We do use editor tracking, if that helps. – Tim Miller Aug 14 '15 at 1:17
  • I hope it works for you! Let us know if you have any issues. It sounds like you have a second question, so that should be addressed in a new post. – Emil Brundage Aug 14 '15 at 15:34
  • Do you know if this script would automatically overwrite any feature classes already in the database if they share a name? – Tim Miller Aug 14 '15 at 19:30
  • That's an environmental setting. arcpy.env.overwriteOutput = True. Setting this variable to true will copy over existing data when procedures such as CopyFeatures_management or FeatureClassToFeatureClass_management are performed. – Emil Brundage Aug 14 '15 at 20:02
  • Thanks! Where would I put this? Near the beginning of the script, not indented? – Tim Miller Aug 14 '15 at 21:26

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.