POST
|
Thanks, I will change forum; although I did follow the GitHub pages, with no luck. Thanks again
... View more
01-28-2014
11:03 AM
|
0
|
0
|
240
|
POST
|
Hi there, I am just starting out with storytelling and I wanted to test a hosted template; where you able to get a map working on GitHub? Cause, I could fork esri repository on mine, but when I go to index.html ...nothing opens up. thanks for your help
... View more
01-28-2014
08:37 AM
|
0
|
2
|
717
|
POST
|
Hi George, Thanks for your help. I ended up, thank to the help of the forum, I ended up doing a second cursor, I'll attach the code below. Spatial Join is a solution I didn't explore, but I'll try. Cause otherwise I now have to find a way to append the tables... import arcpy
arcpy.env.overwriteOutput = True
arcpy.env.workspace = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Default.gdb'
ws = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Default.gdb'
Comuni = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Sardegna3.gdb\\Comuni'
Linee = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Sardegna3.gdb\\Linee'
rows = arcpy.SearchCursor(Comuni)
for row in rows:
print row.NOME
feat = row.Shape
arcpy.SelectLayerByLocation_management("Linee", "INTERSECT", feat, selection_type="NEW_SELECTION");
out_feature_class = arcpy.ValidateTableName("Linee_Clip_" + row.NOME);
table = arcpy.TableToTable_conversion("Linee", ws, out_feature_class);
arcpy.AddField_management(out_feature_class, 'Comune', 'TEXT', '', '', '60');
arcpy.AddField_management(out_feature_class, 'ISTAT', 'TEXT', '', '', '6');
rows2 = arcpy.UpdateCursor(table)
for row2 in rows2:
row2.Comune = str(row.NOME)
row2.ISTAT = str(row.CODISTAT)
rows2.updateRow(row2)
... View more
09-17-2012
12:31 AM
|
0
|
0
|
235
|
POST
|
First time dealing with cursor. I have lines intersecting polygons, I want to get a table with all attributes of the lines, add a field and calculate the field as the name of the polygon. I was able to get a table for each polygon but I can't get to calculate the field and add the polygon name. How do I do? here is my code: import arcpy
arcpy.env.overwriteOutput = True
arcpy.env.workspace = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Default.gdb'
ws = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Default.gdb'
Comuni = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Sardegna3.gdb\\Comuni'
Linee = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Sardegna3.gdb\\Linee'
rows = arcpy.SearchCursor(Comuni)
for row in rows:
print row.NOME
feat = row.Shape
arcpy.SelectLayerByLocation_management("Linee", "INTERSECT", feat, selection_type="NEW_SELECTION");
out_feature_class = arcpy.ValidateTableName("Linee_Clip_" + row.NOME);
table = arcpy.TableToTable_conversion("Linee", ws, out_feature_class);
arcpy.AddField_management(out_feature_class, 'Clip', 'TEXT', '', '', '60');
expression = arcpy.ValidateTableName(row.NOME);
arcpy.CalculateField_management(table, "Clip", expression); here is the error I get: Empty value for ObjectID = 1 The calculated value is invalid for the row with ObjectID = 1. For example, the calculated value may be too large for the field or you may be trying to add a string to a number field. This row will not be updated.
... View more
09-14-2012
05:32 AM
|
0
|
2
|
844
|
POST
|
New feature dataset in an existing GDB. Still struggling... Apologies, I just found out that I forgot this part in my script: #################
# REPLACE DATASOURCE
new_path = 'I:\\20120208_Backup_disco_E\\'
mxd.findAndReplaceWorkspacePaths('E:\\', new_path)
arcpy.RefreshTOC()
Sorry again
... View more
09-11-2012
04:58 AM
|
0
|
0
|
488
|
POST
|
A new feature dataset or a new GDB? Feature classes with the same name can't exist in two different feature datasets in the same GDB. I.e., all feature classes in a GDB must have a unique name. Jeff New feature dataset in an existing GDB. Still struggling...
... View more
09-11-2012
12:50 AM
|
0
|
0
|
488
|
POST
|
I tried to reproduce your issue by simplifying your code. It works. I tested on 10.1 final. I added two shapefiles to a new MXD. I renamed one of them so it would appear broken in the MXD. I created a new, empty file GDB. Finally I ran the following, simplified code:
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Temp\Shapefiles.mxd")# Create a list of SHP in mxd
list = []
df_list = arcpy.mapping.ListDataFrames(mxd)
for df in df_list:
for fc in arcpy.mapping.ListLayers(mxd, "", df):
if (fc.supports("DATASOURCE")) and (fc.dataSource.endswith(".shp")):
list.append(fc)
print list
# Check for broken datasource
for fc in list:
if arcpy.mapping.ListBrokenDataSources(fc):
list.remove(fc)
print list
# Move fc to gdb
ws = r"C:\Temp\Temp.gdb"
for fc in list:
dsc = arcpy.Describe(fc)
arcpy.FeatureClassToFeatureClass_conversion(fc, ws, fc.name)
fc.replaceDataSource (ws, "FILEGDB_WORKSPACE", fc.name)
# Create a new MXD
mxd.saveACopy(r"C:\Temp\Shapefiles2.mxd")
One possible issue is that you are running the code multiple times and the FCs may already exist in the output GDB. You need to remove those manually ahead of time or check to see if they exist and remove them with code before the FeatureClassToFeatureClass function is called. Jeff Hi Jeff, Thanks a lot for your reply. Layers can't be in the gdb dataset cause, in the first part of the script a I create a new feature dataset.
... View more
09-10-2012
05:43 AM
|
0
|
0
|
488
|
POST
|
In my SHP to GDB toolbox, I create a list of layers in MXD, then I check for those not broken I move them. Despite using ListBrokenDataSources I have errors like this: Runtime error <type 'exceptions.WindowsError'>: [Error 3] Impossibile trovare il percorso specificato: u'J:\\20120208_Backup_disco_E\\Archivio\\ATLArete\\Shape Atlarete 1-1-2008\\miste.shp' I'm desperate at this point, any help???? Following my code: # Create a list of SHP in mxd
list = []
df_list = arcpy.mapping.ListDataFrames (mxd)
for df in df_list:
for fc in arcpy.mapping.ListLayers (mxd, "", df):
if (fc.supports("DATASOURCE")) and (fc.dataSource.endswith(".shp")):
list.append(fc)
print("List created")
# Check for borken datasource
for fc in list:
if arcpy.mapping.ListBrokenDataSources(fc):
list.remove(fc)
print ("Broken data removed from list")
# Move fc to gdb
add_list = []
for fc in list:
fc_date = time.strftime("%Y%m%d", time.gmtime(os.path.getctime(fc.dataSource)))
try:
dsc = arcpy.Describe(fc)
out_temp = '_' + fc_date + '_' + fc.name + '_' + fc_prj
out_name = arcpy.ValidateTableName(out_temp)
print ('Created ' + out_name + ' to ' + gdb_full_path)
except:
out_temp = '_' + fc_date + '_' + fc.name + '_' + 'UNKNOWN'
out_name = arcpy.ValidateTableName(out_temp)
print ('Created ' + out_name + ' to ' + gdb_full_path)
arcpy.FeatureClassToFeatureClass_conversion(fc, fd_path, out_name)
replace_name = fd_path + '\\' + out_name
fc.replaceDataSource (gdb_full_path, "FILEGDB_WORKSPACE", out_name)
print ('Replaced data source ' + out_name + ' in ' + gdb_full_path)
# Create a new MXD
new_mxd = os.path.splitext(gdb_full_path)[0] + '\\' + 'MXD' + '\\' + time.strftime("%Y%m%d", mxd_date )+ '_' + (mxd_name)
mxd.saveACopy(new_mxd)
print ('Created new MXD ' + new_mxd + ' in ' + ws)
... View more
09-06-2012
02:13 AM
|
0
|
8
|
653
|
POST
|
So what you want is a list of broken layers and a list of nonbroken layers? You already have the broken list figured out. To get the list of nonbroken just loop through the layers and check if it's broken or not. nonbrokenList = [] for layerItem in layersList: if not layerItem.isBroken: nonbrokenList.append(layerItem) you could even build the broken list at the same time rather than calling the listBrokenLayers. nonbrokenList = [] brokenList = [] for layerItem in layersList: if layerItem.isBroken: brokenList.append(layerItem) else: nonbrokenList.append(layerItem) Hi thank you for your help! I picked the first solution so I don't have to add a passage to the code. Here is what I did list = []
df_list = arcpy.mapping.ListDataFrames (mxd)
for df in df_list:
for fc in arcpy.mapping.ListLayers (mxd, "", df):
if (fc.supports("DATASOURCE")) and (fc.dataSource.endswith(".shp")):
if not fc.isBroken:
list.append(fc)
print("List created") Unfortunately I have this error: Runtime error <type 'exceptions.AttributeError'>: 'Layer' object has no attribute 'isBroken'
... View more
08-21-2012
10:52 PM
|
0
|
0
|
537
|
POST
|
Are you trying to remove the layer from the mxd or simply the layer in the list from the python list ? If the first, I think you want to use RemoveLayer: http://resources.arcgis.com/en/help/main/10.1/index.html#/RemoveLayer/00s300000039000000/ If you simply want to modify lists built in Python, the ListBrokenDataSources returns an actual layer. So your code is trying to remove a "layer" from the list. In other words, because the ListLayers and FindBrokenDataSources command dont return exactly the same thing, you cant remove the layer in that way. I think if you force NAMES into the list and work directly with those, it'll work. Is this applicable for your workflow, having a list of layer NAMES? ##############################
# LIST ALL SHP IN MXD
list = []
df_list = arcpy.mapping.ListDataFrames (mxd)
for df in df_list:
for fc in arcpy.mapping.ListLayers (mxd, "", df):
if (fc.supports("DATASOURCE")) and (fc.dataSource.endswith(".shp")):
list.append(fc.name)
print("List created")
#############################
# REMOVE BROKEN LINKS FROM LIST
brokenList = arcpy.mapping.ListBrokenDataSources(mxd)
for broken in brokenList:
list.remove(broken.name)
print ("Broken data removed from list") Thanks for your kind reply. I'm trying to remove the layer from the list, but I don't know how ( I am exploring set and so on but no luck). Otherwise I could also remove the layer from the mxd since for my purpose I will create a new mxd. Here is what I'm trying to do, move SHP to GDB. ########################
# IMPORT MODULES
import sys, arcpy, datetime, os, traceback, time
import arcpy.mapping
from arcpy import env
############################
# ADD NECESSARY TOOLBOXES
try:
arcpy.AddToolbox("C:\\Program Files\\ArcGIS\\Desktop10.0\\ArcToolbox\\Toolboxes\\Data Management Tools.tbx");
except (RuntimeError):
arcpy.AddToolbox("C:\\Program Files (x86)\\ArcGIS\\Desktop10.0\\ArcToolbox\\Toolboxes\\Data Management Tools.tbx")
##############################
# SET CURRENT AS MXD
mxd = arcpy.mapping.MapDocument ("CURRENT")
##########################
# SET WORKSPACE
ws = 'C:\\PARK'
arcpy.env.workspace = ws
print("Workspace completed successfully")
installdir = arcpy.GetInstallInfo("desktop")
#################
# CREATE A NEW FEATURE DATASET ON EXISTING GDB
gdb_full_path = 'E:\\PROGETTI\\PROGETTI_SICILIA\\007_SORGENTE_RIZZICONI\\007_SORGENTE_RIZZICONI.gdb'
mxd_date = time.gmtime(os.path.getctime(mxd.filePath))
mxd_name = os.path.basename(mxd.filePath)
fd_temp = '_' + time.strftime("%Y%m%d", mxd_date )+ '_' + (os.path.splitext(mxd_name)[0])
fd_name = arcpy.ValidateTableName(fd_temp)
fd_path = gdb_full_path + '\\' + fd_name
# if arcpy.Exists (fd_path):
# arcpy.AddError ("FEATURE DATASET GIA' ESISTENTE!")
# print ("FEATURE DATASET GIA' ESISTENTE!")
fd = arcpy.CreateFeatureDataset_management(gdb_full_path, fd_name)
arp#################
# REPLACE DATASOURCE
new_path = 'I:\\20120208_Backup_disco_E\\'
mxd.findAndReplaceWorkspacePaths('E:\\', new_path)
##############################
# LIST ALL SHP IN MXD
list = []
df_list = arcpy.mapping.ListDataFrames (mxd)
for df in df_list:
for fc in arcpy.mapping.ListLayers (mxd, "", df):
if (fc.supports("DATASOURCE")) and (fc.dataSource.endswith(".shp")):
list.append(fc)
print("List created")
#############################
# REMOVE BROKEN LINKS FROM LIST
#brokenList = arcpy.mapping.ListBrokenDataSources(mxd)
#for broken in brokenList:
# list.remove(broken)
# print ("Broken data removed from list")
################
# MOVE SHP TO GDB
remove_list = []
for fc in list:
try:
fc_date = time.strftime("%Y%m%d", time.gmtime(os.path.getctime(fc.dataSource)))
desc = arcpy.Describe(fc)
SR = desc.spatialReference
#out_name = arcpy.ValidateTableName('_' + fc_date + '_' + fc.name + '_' + SR.name)
out_name = '_' + fc_date + '_' + fc.name + '_' + SR.name
arcpy.FeatureClassToFeatureClass_conversion(fc, fd_path, out_name)
print ('Created ' + out_name + ' to ' + gdb_full_path)
replace_name = fd_path + '\\' + out_name
fc.replaceDataSource (gdb_full_path, "FILEGDB_WORKSPACE", out_name)
remove_list.append(out_name)
print ('Replaced data source ' + out_name + ' in ' + gdb_full_path)
except:
print ("SKIP")
# REMOVE NEW LAYERS FROM TOC
for layer in remove_list:
arcpy.mapping.RemoveLayer(((df_list)[0]), layer)
# Refresh the Table of Contents to reflect the change
# CREATE A COPY OF THE EXISTING MXD
new_mxd = ws + '\\' + 'MXD' + '\\' + time.strftime("%Y%m%d", mxd_date )+ '_' + (mxd_name)
arcpy.RefreshTOC()
mxd.saveACopy(new_mxd)
... View more
08-21-2012
09:16 AM
|
0
|
0
|
537
|
POST
|
Hello, I create a list of feature in an MXD files, now I'd like to remove the features with broken links. What I did is create two list: 1 features in MXD 2 features in MXD with broken links Now I'd like to subtract...but ain't working. Here is a code sample: ##############################
# LIST ALL SHP IN MXD
list = []
df_list = arcpy.mapping.ListDataFrames (mxd)
for df in df_list:
for fc in arcpy.mapping.ListLayers (mxd, "", df):
if (fc.supports("DATASOURCE")) and (fc.dataSource.endswith(".shp")):
list.append(fc)
print("List created")
#############################
# REMOVE BROKEN LINKS FROM LIST
brokenList = arcpy.mapping.ListBrokenDataSources(mxd)
for broken in brokenList:
list.remove(broken)
print ("Broken data removed from list")
... View more
08-21-2012
08:35 AM
|
0
|
4
|
844
|
POST
|
Set arcpy.env.addOutputsToMap to False at the beginning, then back to True when you're done. How do you do that?? Thank a lot Luca
... View more
08-21-2012
06:35 AM
|
0
|
0
|
592
|
POST
|
Sure there is a way FeatureClassToFeatureClass(in_features=None, out_path=None, out_name=None, where_clause=None, field_mapping=None, config_keyword=None) Notice the third parameter is out_name, this is where you would specify the featureclass name. So, the only way is to use FeatureClassToFeatureClass, there's no way to use FeatureClassToGeodatabase? Other question is, when I use FeatureClassToFeatureClass the Feautures I create have no Spatial Reference, how do I do??
... View more
08-14-2012
10:29 AM
|
0
|
0
|
564
|
POST
|
Use arcpy.FeatureClasstoFeatureClass instead. You can specify the name and location of the output fc. That's what I did. Thanks
... View more
08-13-2012
08:41 AM
|
0
|
0
|
564
|
POST
|
Hi there, For what I am trying to do I create a list of .shp files that I want to import in a gdb, then I use a loop such as: for fc in list: arcpy.FeatureClassToGeodatabase_conversion names problem(fc, out_gdb) It all works smooth except that the feature class created are named "GPL..." why? Is there any way I can specify the featureclass name that I want to have in the gdb? Thanks for your help
... View more
08-13-2012
08:07 AM
|
0
|
5
|
1691
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|