|
POST
|
If ListFields is indicating a type of OID, then use the name property to delete it. To skip both object ID and geometry fields in your deletion, you might try: field_types = ['OID', 'GEOMETRY'] # field types to ignore
#...
for feild in arcpy.ListFields(Copied_Points): # note spelling of "feild"
if feild.type.upper() not in field_types:
# then delete field.name
... View more
08-29-2019
11:50 AM
|
1
|
2
|
4739
|
|
POST
|
Since you are using ListFields you can also try: if feild.type != "OID" : Do you also wish to delete any geometry?
... View more
08-29-2019
11:30 AM
|
0
|
4
|
4739
|
|
POST
|
Can it be assumed the 'ZipCode' field is text and will not be None, null, blank? If not, you will need to do some checking before line 12. And in line 12, looks like you are asking for the first element, but the dictionary value in the example isn't a list / tuple.
... View more
08-28-2019
04:33 PM
|
1
|
1
|
2450
|
|
POST
|
Or: county = "Prince George's"
query = "COUNTY = '{}'".format(county.replace("'","\\'"))
print query
# COUNTY = 'Prince George\'s'
county = ["Prince George's", "Queen Anne's"]
query = "COUNTY IN ('{}')".format("', '".join("".join(i.replace("'","\\'")) for i in county))
print query
# COUNTY IN ('Prince George\'s', 'Queen Anne\'s')
... View more
07-26-2019
10:30 AM
|
0
|
0
|
3568
|
|
POST
|
Do you want something that would escape the single quote for a query? >>> d = {"Prince George's": "Prince George\\'s" }
>>> print d["Prince George's"]
Prince George\'s
>>> query = "COUNTY = '{}'".format(d["Prince George's"])
>>> print query
COUNTY = 'Prince George\'s'
... View more
07-26-2019
09:10 AM
|
1
|
1
|
3568
|
|
POST
|
What is the workspace? If the optional workspace is not specified, the field name is validated against the current workspace Are you wanting to create a new field and validate a name you are planning to use? Or did you want to use something like ListFields to verify that a certain field exists?
... View more
07-24-2019
04:00 PM
|
0
|
0
|
1262
|
|
POST
|
I had a script that did a similar rename. I made a few changes to work in my earlier comment. I had used the exif tag 'Image DateTime', but it should work with 'EXIF DateTimeOriginal'. You want to add error checking to insure that the exif tag is valid. If you have multiple directories, then use os.walk. Just another approach; hope it helps. import os, glob
import exifread
# info on exifread at https://pypi.org/project/ExifRead/
path = r'C:\Path\to\jpeg\directory'
for filename in glob.glob(os.path.join(path, '*.jpg')):
print '{} - renamed to: '.format(filename)
f = open(filename, 'rb') # open read only, binary
tags = exifread.process_file(f)
f.close()
# print tags['Image DateTime']
# print filename[:-4].replace(' ','_').replace('(','').replace(')','').replace('.','')
# print str(tags['Image DateTime']).replace(':','-').replace(' ','_')[:10]
newname = os.path.join(path, '{}_{}.jpg'.format(
filename[:-4].replace(' ','_').replace('(','').replace(')','').replace('.',''), # reformatted filename
str(tags['Image DateTime']).replace(':','-').replace(' ','_')[:10])) # year-mo-dy from exif
print '{}\n'.format(newname)
os.rename(filename, newname)
... View more
07-23-2019
09:59 PM
|
1
|
0
|
3576
|
|
POST
|
Another approach, just testing file names: fn = [ '7400010 (2).jpg',
'7400010.jpg',
'7400015b.jpg' ]
for f in fn:
print f[:-4].replace(' ','_').replace('(','').replace(')','').replace('.','') + '_' + 'date'
# prints
7400010_2_date
7400010_date
7400015b_date
... View more
07-23-2019
12:58 PM
|
1
|
4
|
3576
|
|
POST
|
I think your 'getParameterInfo' section is ok. You will want to see all the folders, etc. to be able to navigate to the gdb. You can then use 'updateMessages' to display an error message if a file or personal geodatabase is not selected. To clear the error, the user would need to make the proper choice or exit the tool. EDIT: changed line 31 'and' to 'or'. class Tool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Tool"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
param0 = arcpy.Parameter(
displayName = "Input Workspace",
name = "in_workspace",
datatype = "DEWorkspace",
parameterType = "Required",
direction = "Input")
return [param0]
def isLicensed(self):
return True
def updateParameters(self, parameters):
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
if parameters[0].valueAsText is not None:
gdb = parameters[0].valueAsText
desc = arcpy.Describe(gdb)
if ( desc.dataType != "Workspace" ) or ( gdb[-4:].upper() not in ('.GDB', '.MDB') ):
parameters[0].setErrorMessage("Please select a file or personal geodatabase (.gdb or .mdb)")
return
def execute(self, parameters, messages):
"""The source code of the tool."""
return
... View more
07-19-2019
06:34 PM
|
0
|
1
|
2616
|
|
POST
|
It might be worthwhile to ask this as a new question since this thread is 2 years old and is marked as answered. You can link to this question so that everyone knows what you have tried.
... View more
07-19-2019
09:33 AM
|
0
|
0
|
1116
|
|
POST
|
I have had several occasions to need the name of coordinate system, with no underscores, the proper spacing, parenthesis around 'feet', etc. I noticed that ListSpatialReferences appears to provide that if you look at the function's return string. A slight modification of the sample code by inserting line 9: import arcpy
# Get the list of spatial references
srs = arcpy.ListSpatialReferences("*alaska*")
# Create a SpatialReference object for each one and print the
# central meridian
for sr_string in srs:
print sr_string.split('/')[-1] # coordinate system name text
# sr_object = arcpy.SpatialReference(sr_string)
# print "{0.centralMeridian} {0.name}".format(sr_object)
'''
part of the output:
NAD 1983 StatePlane Alaska 1 FIPS 5001 (US Feet)
NAD 1983 StatePlane Alaska 2 FIPS 5002 (US Feet)
NAD 1983 StatePlane Alaska 3 FIPS 5003 (US Feet)
NAD 1983 StatePlane Alaska 4 FIPS 5004 (US Feet)
NAD 1983 StatePlane Alaska 5 FIPS 5005 (US Feet)
NAD 1983 StatePlane Alaska 6 FIPS 5006 (US Feet)
NAD 1983 StatePlane Alaska 7 FIPS 5007 (US Feet)
NAD 1983 StatePlane Alaska 8 FIPS 5008 (US Feet)
NAD 1983 StatePlane Alaska 9 FIPS 5009 (US Feet)
NAD 1983 StatePlane Alaska 10 FIPS 5010 (US Feet)
''' You can see the double spaces after 'Alaska' and the parenthesis around 'feet' in lines 16-24.
... View more
07-12-2019
12:50 PM
|
0
|
0
|
2740
|
|
POST
|
I got this to work in 10.6: import arcpy
x = -101.415206
y = 32.537097
ptGeometry = arcpy.PointGeometry(arcpy.Point(x,y),arcpy.SpatialReference('NAD 1927')).projectAs("NAD 1983 StatePlane Texas N Central FIPS 4202 (US Feet)","NAD_1927_To_NAD_1983_NADCON")
print ptGeometry.firstPoint.X, ptGeometry.firstPoint.Y
# result: 1070116.54144 6890849.30626
It seems that when you use a "transformation_name", the associated "spatial_reference" must be a name (not a factory code). This document ArcGIS 10.7.1 and ArcGIS Pro 2.4 Geographic and Vertical Transformation Tables was helpful.
... View more
07-11-2019
02:30 PM
|
2
|
1
|
6707
|
|
POST
|
I did some testing and can confirm that the tool script and code run in the Python window produce different results. I believe this is due to an automatic transformation that is occurring when the tool is being run. The GCS NA 1927 coordinates appear to be transformed into GCS NA 1983 using NAD 1927 To NAD 1983 NADCON. As an experiment I created two layers: the Texas State Plane that you are working with, and a GCS NA 1927. The state plane was populated with two points located at the positions you highlighted in your results. The GCS 1927 was populated with one point using the lon/lat in your script. The state plane was placed in a new map. When adding the GCS 1927 layer a transformation dialog was presented. If no transformation was selected, the GCS 1927 point was placed over the state plane point located at 1070240.5212705112, 6890805.12915604. If the NAD 1297 To NAD 1983 NADCON transformation was used, the GCS 1927 point was located over the state plane point located at 1070116.54144, 6890849.30626. While experimenting, I noticed that the Add Geometry Attributes tool also automatically included the transformation. I suppose the next question is: Can the transformation be added to the projectAs() function?
... View more
07-11-2019
10:09 AM
|
1
|
3
|
6707
|
|
POST
|
Perhaps if you could share a bit more of what you are doing would be helpful. Here's a bit of an example of working with an mxd document (in this case to make adjustments to the visibility and transparency of some map layers): import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
# or if inside ArcMap:
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "County Maps")[0]
# ListLayers (map_document_or_layer, {wildcard}, {data_frame})
for lyr in arcpy.mapping.ListLayers(mxd, "Lakes", df):
if lyr.description == "USGS Lakes":
lyr.visible = True
lyr.transparency = 50
mxd.save() # save the document with changes
# or
mxd.saveACopy(r"C:\GIS\testfile.mxd") # save the changes to a new document
del mxd In line 3 or 4, you are opening an mxd to work with. This can be a previously saved document, or the current one opened in ArcMap. Then make your changes to the document. And in lines 16 or 18 you are saving the changes to either the original document or a new document.
... View more
07-03-2019
10:20 AM
|
0
|
1
|
2639
|
|
POST
|
Then perhaps: mxd.saveACopy(r"C:\GIS\testfile.mxd") See MapDocument for more info as you can specify the version format. There is also save().
... View more
07-03-2019
09:46 AM
|
0
|
1
|
2639
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-27-2016 02:23 PM | |
| 1 | 09-09-2017 08:27 PM | |
| 2 | 08-20-2020 06:15 PM | |
| 1 | 10-21-2021 09:15 PM | |
| 1 | 07-19-2018 12:33 PM |
| Online Status |
Offline
|
| Date Last Visited |
02-12-2026
07:13 PM
|