import arcpyimport sqlite3
# the column namescolumnNames = ["ASSETNUM", "DESCRIPTIO", "INSERVICE", "ENGINEID"]
data = []with arcpy.da.SearchCursor(r'E:\mypathtoshp\Fire_Hydrants.shp', columnNames) as sCursor: for row in sCursor: data.append(row)
# create a connection to your sqlite databaseconn = sqlite3.connect(r'E:\mypathtodb\MyDB.db')cursor = conn.cursor()
# create a table within the databasecursor.execute(''' CREATE TABLE Hydrants_MIS(ASSETNUM text, DESCRIPTIO text, INSERVICE text, ENGINEID text)''')
# insert your new recordsc = ['?' for c in range(len(columnNames))]c = ','.join(c)sql = 'INSERT INTO {} VALUES ({})'.format('Hydrants_MIS', c)cursor.executemany(sql, data)conn.commit()
I have the above code to create a table in SQLite and populate the data from shp file. The SQLite table serves as a MIS repository and the shp serves as GIS repo. My client will induce changes in GIS data.
I want to run a python code every 1 hour to compare the 'ASSETNUM' values from the MIS data(SQLITE) and GIS data(shp), checking whether any data has been modified/added/deleted. If there is any modifications, perform the following operations:
أكثر...
# the column namescolumnNames = ["ASSETNUM", "DESCRIPTIO", "INSERVICE", "ENGINEID"]
data = []with arcpy.da.SearchCursor(r'E:\mypathtoshp\Fire_Hydrants.shp', columnNames) as sCursor: for row in sCursor: data.append(row)
# create a connection to your sqlite databaseconn = sqlite3.connect(r'E:\mypathtodb\MyDB.db')cursor = conn.cursor()
# create a table within the databasecursor.execute(''' CREATE TABLE Hydrants_MIS(ASSETNUM text, DESCRIPTIO text, INSERVICE text, ENGINEID text)''')
# insert your new recordsc = ['?' for c in range(len(columnNames))]c = ','.join(c)sql = 'INSERT INTO {} VALUES ({})'.format('Hydrants_MIS', c)cursor.executemany(sql, data)conn.commit()
I have the above code to create a table in SQLite and populate the data from shp file. The SQLite table serves as a MIS repository and the shp serves as GIS repo. My client will induce changes in GIS data.
I want to run a python code every 1 hour to compare the 'ASSETNUM' values from the MIS data(SQLITE) and GIS data(shp), checking whether any data has been modified/added/deleted. If there is any modifications, perform the following operations:
- If there are any new rows in GIS data, pick the assetnum and update the fields in MIS data. Eg: There is a new asset added by the client in GIS data. I need the script to update this new data in the MIS table.
- If some rows in GIS data were deleted, update the fields in MIS data. Eg: Some assets were not in use and were removed by the client in GIS data. I need the script to update this in the MIS table.
- If there are modifications in the data, the updation should happen at MIS table as well.
أكثر...