|
POST
|
Haha, you're killing me! So if it should look like B3_SULC33U and you want to parse on the first underscore, then you can replace that last section with this (untested): # Create folders and export features to shapefiles for each UTM value
for utm in distinct_utm:
delim = "_"
utm_parse = utm.split(delim, 1)
if len(utm_parse) == 2:
block, sheet = utm_parse
sheet_path = os.path.join(root_dir, block, sheet)
if not os.path.exists(sheet_path):
os.makedirs(sheet_path)
arcpy.FeatureClassToFeatureClass_conversion(
feature_class, ## in_features
sheet_path, ## out_path
"{}_{}_{}".format(block, sheet, os.path.basename(feature_class)), ## out_name
"FOL_250K = '{}'".format(utm) ## where_clause
)
else:
raise ValueError("Could not parse {} with {}".format(utm, delim))
... View more
04-28-2016
04:22 PM
|
0
|
0
|
2718
|
|
POST
|
Is this close? I'm assuming that you can parse based on the index of "S" in FOL_250K. I'm also assuming you want all fields in the feature class exported to the shapefile. import arcpy
import os
def main():
# local variables
root_dir = r"C:\temp\Msg605039"
gdb = os.path.join(root_dir, "gdb2shp_selected_fields.gdb")
feature_class = os.path.join(gdb, "gab_und_crt_dic")
# Get list of distinct UTM values
utm_field = "FOL_250K"
sql_prefix = "DISTINCT {}".format(utm_field)
sql_suffix = None
distinct_utm = [
i[0] for i in arcpy.da.SearchCursor(
feature_class, utm_field, sql_clause=(sql_prefix, sql_suffix)
)
]
# Create folders and export features to shapefiles for each UTM value
for utm in distinct_utm:
delim = "S"
delim_index = utm.find(delim)
if delim_index == -1:
raise Exception("Could not parse {} with {}".format(utm, delim))
else:
block = utm[0:delim_index]
sheet = utm[delim_index:len(utm)]
sheet_path = os.path.join(root_dir, block, sheet)
if not os.path.exists(sheet_path):
os.makedirs(sheet_path)
arcpy.FeatureClassToFeatureClass_conversion(
feature_class, ## in_features
sheet_path, ## out_path
"{}_{}_{}".format(block, sheet, os.path.basename(feature_class)), ## out_name
"FOL_250K = '{}'".format(utm) ## where_clause
)
if __name__ == "__main__":
main()
... View more
04-28-2016
03:18 PM
|
2
|
0
|
6082
|
|
POST
|
So the value in the FOL_250K field of the sample data you uploaded is not correct? It's hard to parse a value when you don't know what the value is supposed to look like. Are you saying instead of the value being BLOCO1 - SULD33T - Chibia, it should be B1SULD33T? How do you parse that into block and sheet? At the first S?
... View more
04-28-2016
01:56 PM
|
0
|
2
|
3364
|
|
POST
|
Sorry, I still don't quite follow. I don't see a UTM_grid field in the data you uploaded, nor do I see any lists of OIDs. Do you have some other Python function that dissolves the FOL_250K field into OIDs? It looks like there are four distinct values in FOL_250K: BLOCO1 - SULD33S - Namibe BLOCO1 - SULD33T - Chibia BLOCO1 - SULE33B - Oncócua BLOCO3 - SULC33U Should it make output folders and shapefiles like this? BLOCO1 .. SULD33S .... Namibe.shp .. SULD33T .... Chibia.shp .. SULD33B .... Oncócua.shp BLOCO3 .. SULC33U .... None.shp
... View more
04-28-2016
11:28 AM
|
0
|
5
|
3364
|
|
POST
|
This got posted to the Python section. You're better off in ArcGIS API for JavaScript EDIT: Just noticed your other similar thread. Can python GP services returns json data to client through REST?
... View more
04-28-2016
11:06 AM
|
0
|
0
|
3503
|
|
POST
|
So you're iterating a list of feature classes, opening the search cursor on each one, and exporting certain ObjectIDs in the whole feature class based on the ObjectIDs listed in the UTM_Grid field of each record? Seems like that would be ripe for duplicates. Could you upload some sample data?
... View more
04-28-2016
10:27 AM
|
0
|
0
|
3364
|
|
POST
|
I think Dan Patterson is asking how you find the feature class to export? In other words, how do we know where to go to export the OIDs for each sheet. Is there something in the UTM grid data that identifies the feature class to export?
... View more
04-27-2016
04:59 PM
|
1
|
1
|
3364
|
|
POST
|
Thanks for the comment, Joshua. I dug a little deeper and found that about one third of our views describe as canVersion True. I checked the sde.table_registry and all of those are also registered. None of the ones that describe as canVersion False are registered in sde.table_registry. Most of these views are very old and were created (before my time) with sde comand lines so I guess that makes sense. Maybe it's time to recreate all of these views with the right click option in ArcCatalog.
... View more
04-19-2016
03:28 PM
|
0
|
1
|
1465
|
|
POST
|
jay kapalczynski You should really post this question in the ArcGIS API for JavaScript area.
... View more
04-19-2016
09:22 AM
|
1
|
1
|
4781
|
|
POST
|
When Walking an Oracle 11g Enterprise Geodatabase, is there a way to tell if the table or feature class you're on is actually a view? I was hoping that the canVersion dataset describe property would work, but apparently ArcGIS still thinks some views can be registered as versioned. EDIT: I did stumble across this SQL to find all the views in the (Oracle) database. select owner||'.'||object_name as view_name
from all_objects
where object_type = 'VIEW' I suppose I could just run that with arcpy.ArcSDESQLExecute() and then check if each object being walked is in the SQL result. Still interested in other options though.
... View more
04-19-2016
09:05 AM
|
0
|
3
|
3478
|
|
POST
|
Here's the query I'm using to identify which tables have edits (and who made the edits). SELECT DISTINCT
tr.owner as TABLE_OWNER, tr.table_name,
COUNT (mm.registration_id) AS STATE_COUNT,
s.owner AS STATE_OWNER
FROM sde.mvtables_modified mm
LEFT OUTER JOIN sde.states s
ON mm.state_id = s.state_id
LEFT OUTER JOIN sde.table_registry tr
ON mm.registration_id = tr.registration_id
GROUP BY tr.owner, tr.table_name, s.owner
ORDER BY tr.owner, tr.table_name, s.owner Turns out the slowness I was experiencing with rebuild indexes and analyze datasets was from excessive geoprocessing history logged in the geodatabase metadata. Using arcpy.SetLogHistory(False) will prevent the geoprocessing history generated in the script to be logged. Here's the script I used to clean out the geoprocessing history from the geodatabase. Once the geoprocessing history was cleaned up, our maintenance script ran very quickly again. import arcpy
from contextlib import contextmanager
import os
import shutil
import tempfile
def main():
sde_sdeconn = r"C:\GISConnections\[email protected]"
xslt_path = r"C:\arcgis\Desktop10.2\Metadata\Stylesheets\gpTools\remove geoprocessing history.xslt"
try:
arcpy.ClearWorkspaceCache_management()
if os.path.exists(xslt_path):
with makeTempDir() as temp_dir:
## Get unique temporary XML file name
with tempfile.NamedTemporaryFile(
dir=temp_dir, suffix=".xml", delete=True
)as temporary_file:
temporary_file_name = temporary_file.name
## Export metadata without geoprocessing history
arcpy.XSLTransform_conversion(
sde_sdeconn, ## source
xslt_path, ## xslt
temporary_file_name ## output
)
print arcpy.GetMessages()
print ""
## Import metadata that has geoprocessing history removed
arcpy.MetadataImporter_conversion(
temporary_file_name, ## source
sde_sdeconn ## target
)
print arcpy.GetMessages()
else:
raise IOError("File not found.\n{}".format(xslt_path))
except Exception as err:
if err.message in arcpy.GetMessages(2):
## All of the messages returned by the last ArcPy tool
displayErr = arcpy.GetMessages()
else:
## Non-ArcPy error message
displayErr = unicode(err).encode("utf-8")
print displayErr
finally:
# Cleanup
arcpy.ClearWorkspaceCache_management()
@contextmanager
def makeTempDir():
"""Creates a temporary folder and returns the full path name.
Use in with statement to delete the folder and all contents on exit.
Requires contextlib contextmanager, shutil, and tempfile modules.
"""
temp_dir = tempfile.mkdtemp()
try:
yield temp_dir
finally:
shutil.rmtree(temp_dir)
if __name__ == '__main__':
main()
Geoprocessing history is also logged in the metadata of feature datasets and feature classes, and tables. You can modify this script to walk the geodatabase and remove the geoprocessing history for each of those things if you like. Here is some further reading from Esri Support: Editing metadata for many ArcGIS items http://resources.arcgis.com/en/help/main/10.1/index.html#//003t00000026000000 XSLT Transformation (Conversion) http://resources.arcgis.com/en/help/main/10.1/index.html#//001200000017000000 Automate the process of deleting geoprocessing history http://support.esri.com/en/knowledgebase/techarticles/detail/41026
... View more
03-25-2016
01:34 PM
|
2
|
2
|
8588
|
|
POST
|
I second Darren Wiens in using startswith() if row[0] == "Boston College":
# [code here]
elif row[0].startswith("University of "):
# [code here]
else:
# [code here] Just make sure the field you're doing this on has only strings (text). The code above will error if it hits a number or date value.
... View more
03-17-2016
04:48 PM
|
0
|
0
|
2529
|
|
POST
|
Just for future reference, you can format your code with syntax highlighting so it looks like it does in the IDE and is easier to read. Posting Code blocks in the new GeoNet
... View more
03-16-2016
12:35 PM
|
0
|
1
|
623
|
|
POST
|
That error means it's trying to get the fifth thing in the row split. Looking at your example, it probably means there were only three instances of your split text '<br>' I recommend you print row[0] before you start splitting it so you know which one it chokes on. If you really just want to skip this error, you could use a try, except block. import arcpy
ap.env.workspace = "...\\path\\to\\gdb"
update_fields = ["PopupInfo", "Type", "Phone", "Address", "Lat", "Long"]
with arcpy.da.UpdateCursor('Places', update_fields) as cursor:
for row in cursor:
try:
row[1] = row[0].split('<br>')[0]
row[2] = row[0].split('<br>')[1]
row[3] = row[0].split('<br>')[2]
row[4] = row[0].split('<br>')[3]
row[5] = row[0].split('<br>')[4]
cursor.updateRow(row)
except IndexError as iErr:
print "Error processing {}\n{}".format(row[0], iErr)
pass This will only pass on that specific exception (IndexError). If something else happens, the script will still stop.
... View more
03-03-2016
01:45 PM
|
1
|
1
|
3779
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 4 weeks ago | |
| 1 | 10-23-2025 03:53 PM | |
| 1 | 04-28-2026 07:25 AM | |
| 1 | 03-19-2026 08:59 AM | |
| 1 | 02-12-2026 01:37 PM |