|
POST
|
Did this work - using a projection file? sr = arcpy.SpatialReference(r"S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Projects_2018\Smart_T_Line_Model\geodata\templateUTM.prj")
featureClassList = arcpy.ListFeatureClasses()
for featureClass in featureClassList:
arcpy.management.CalculateGeometryAttributes(featureClass, "X_coord POINT_X;Y_coord POINT_Y", None, None, sr)
... View more
10-26-2018
10:20 AM
|
0
|
1
|
2110
|
|
POST
|
When you query your feature specifiy: "outSR" : "4326", # 4326 = WGS 1984 lat/lon See 'outSR' in the request parameters section of this page: Query (Feature Service). You can also convert after retrieving your data using projectAs: # 4326: WGS 1984 (Lat/Lon)
# 32631: WGS 84 / UTM zone 31N
ptGeometry = arcpy.PointGeometry(arcpy.Point(x,y),arcpy.SpatialReference(32632)).projectAs(arcpy.SpatialReference(4326))
print ptGeometry.firstPoint.X, ptGeometry.firstPoint.Y
... View more
10-26-2018
09:26 AM
|
2
|
1
|
3184
|
|
POST
|
Maybe this code: 32165 fc = r'C:\path\to\feature\using\sr\file.gdb\feature'
sr = arcpy.Describe(fc).spatialReference
print sr.name
# u'NAD_1983_BLM_Zone_15N_ftUS'
print sr.factoryCode
# 32165
... View more
10-25-2018
02:11 PM
|
0
|
0
|
2081
|
|
POST
|
I think it is 32065. https://epsg.io/32065 sr = arcpy.SpatialReference(32065)
... View more
10-25-2018
12:39 PM
|
0
|
3
|
2081
|
|
POST
|
Line 24 is referencing 'FileGDB', a file geodatabase; and MasterGDB is a personal geodatabase (.mdb). I wonder if this could be your issue.
... View more
10-25-2018
10:14 AM
|
2
|
1
|
2267
|
|
POST
|
In addition to using 'domain.name', I would move the line to just after the 'if domainType == CodedValue' line; you only need to sort it once. import arcpy
domains = arcpy.da.ListDomains("Database Connections\\Server DB Owner.sde")
for domain in domains:
print('Domain name: {0}'.format(domain.name))
if domain.domainType == 'CodedValue':
arcpy.SortCodedValueDomain_management("Database Connections\\Server DB Owner.sde", domain.name, "CODE", "ASCENDING")
coded_values = domain.codedValues
for val, desc in coded_values.items():
print('{0} : {1}'.format(val, desc))
elif domain.domainType == 'Range':
print('Min: {0}'.format(domain.range[0]))
print('Max: {0}'.format(domain.range[1])) EDIT: I'm not sure if it will print the domain sorted within the loop. You could change lines 8-9: for val, desc in sorted(coded_values.items()):
print('{0} : {1}'.format(val, desc))
... View more
10-25-2018
09:30 AM
|
2
|
1
|
3099
|
|
POST
|
SortCodedValueDomain_management (in_workspace, domain_name, sort_by, sort_order) You need the domain name. I would try 'domain.name' : arcpy.SortCodedValueDomain_management("Database Connections\\Server DB Owner.sde", domain.name, "CODE", "ASCENDING")
... View more
10-25-2018
09:14 AM
|
1
|
0
|
3099
|
|
POST
|
No doubt, you have been experimenting. I've queried using something like this for a polygon: and for an extent (xmin, ymin, xmax, ymax): For a little documentation see: Query (Feature Service) and esriGeometryType Constants. For me, it's mostly been some experimenting.
... View more
10-24-2018
11:49 AM
|
1
|
0
|
4219
|
|
POST
|
If the filename format is consistent, you could use a couple of splits: filename = 'Bermuda Rd MP 0_26 102017_TestTable.xlsx'
f = filename.split(' MP ')
address = f[0]
mile = f[1].split(' ')[0]
print address
# Bermuda Rd
print mile
# 0_26
# and if the underscore in mile represents a decimal point
print '.'.join(mile.split('_'))
# 0.26
# or
mile = '.'.join(f[1].split(' ')[0].split('_')) And using listdir to get filenames in directory: import os
path = r"C:\Users\anthonyv\Downloads\Upload"
files = os.listdir(path)
for filename in files:
f = filename.split(' MP ')
address = f[0]
# mile = f[1].split(' ')[0] # keep underscore
mile = '.'.join(f[1].split(' ')[0].split('_')) # convert underscore to period
print address, mile
... View more
10-22-2018
05:18 PM
|
0
|
3
|
5954
|
|
POST
|
Currently the grouping is by year then month. Instead of grouping by month, you could grab the day and group by day, so you would be able to combine Jan 1, Feb 1, March 1, etc. into a file. You would structure your dictionary with 1 to 31 for days of the month instead of 1 to 12 for months of the year. If you just want to rename/copy files with a YMD in the name, you could just loop through your directory list and extract the date from the Julian day for your rename. This wouldn't involve a dictionary. This code still groups by month, but it may give you some ideas on how to do what you want. It uses the tuple idea I mentioned previously and follows the flow of an earlier example. from datetime import datetime
def extractJulian(filename):
jdate = filename.split(".")[1][1:] # get date portion, splitting on periods
dt = datetime.strptime(jdate, '%Y%j').date()
return(filename, dt.year, dt.month, dt.day, jdate[4:]) # return a tuple
def someFunction(aTupleList):
for aTuple in aTupleList: # print each tuple in list of tuples
print
print "Old file: {}".format(aTuple[0]) # filename
print "Newname_{}_{}_{}_{}.tif".format(aTuple[1],aTuple[2],aTuple[3],aTuple[4]) # Year, Month, Day, DayNumber
return None
# lstrasters = glob.glob(di + os.sep + "*Corrected_Optical_Depth_Land_2-Corrected_Optical_Depth_Land.tif")
lstrasters = [ # list from your directory search
'MOD04_3K.A20161.mosaic.061.2017271115004.pssgmcrpgs_000501268215.Corrected_Optical_Depth_Land_2-Corrected_Optical_Depth.Land.tif',
'MOD04_3K.A20162.mosaic.061.2017271115004.pssgmcrpgs_000501268215.Corrected_Optical_Depth_Land_2-Corrected_Optical_Depth.Land.tif',
'MOD04_3K.A2017152.mosaic.061.2017271115004.pssgmcrpgs_000501268215.Corrected_Optical_Depth_Land_2-Corrected_Optical_Depth.Land.tif',
'MOD04_3K.A2017153.mosaic.061.2017271115004.pssgmcrpgs_000501268215.Corrected_Optical_Depth_Land_2-Corrected_Optical_Depth.Land.tif',
'MOD04_3K.A2017254.mosaic.061.2017271115004.pssgmcrpgs_000501268215.Corrected_Optical_Depth_Land_2-Corrected_Optical_Depth.Land.tif',
'MOD04_3K.A2017255.mosaic.061.2017271115004.pssgmcrpgs_000501268215.Corrected_Optical_Depth_Land_2-Corrected_Optical_Depth.Land.tif',
'MOD04_3K.A2018356.mosaic.061.2017271115004.pssgmcrpgs_000501268215.Corrected_Optical_Depth_Land_2-Corrected_Optical_Depth.Land.tif',
'MOD04_3K.A2018357.mosaic.061.2017271115004.pssgmcrpgs_000501268215.Corrected_Optical_Depth_Land_2-Corrected_Optical_Depth.Land.tif'
] # these rasters are for months 6 and 9 in 2017, and 12 in 2018
rasters = { 2017: {1:[],2:[],3:[],4:[],5:[],6:[],7:[],8:[],9:[],10:[],11:[],12:[]},
2018: {1:[],2:[],3:[],4:[],5:[],6:[],7:[],8:[],9:[],10:[],11:[],12:[]}
} # starting dictionary
for r in lstrasters:
ej = extractJulian(r)
# ej[0] = filename (same as r), ej[1] = year, ej[2] = month, ej[3] = day
if ej[1] in rasters.keys():
rasters[ej[1]][ej[2]].append(ej)
else:
print "ERROR year {}: {}\n".format(ej[1], r)
print rasters # take a look at the dictionary
for k1,v1 in rasters.iteritems():
year =k1
for k2,v2 in v1.iteritems():
if len(v2):
month =k2
print "\n\nYear: {} Month: {}".format(year, month)
rtn = someFunction(v2) # function prints v2 (tuples in a list) and returns None
... View more
10-07-2018
03:55 PM
|
1
|
2
|
1117
|
|
POST
|
To work with Julian days: >>> from datetime import datetime
>>> jdate = '2017152' # julian day extracted from filename
>>> datetime.strptime(jdate, '%Y%j').date().strftime("%Y") # 4 digit year
'2017'
>>> datetime.strptime(jdate, '%Y%j').date().strftime("%y") # 2 digit year
'17'
>>> datetime.strptime(jdate, '%Y%j').date().strftime("%m") # month
'06'
>>> datetime.strptime(jdate, '%Y%j').date().strftime("%d") # day
'01'
>>> datetime.strptime(jdate, '%Y%j').date() # as a datetime object
datetime.date(2017, 6, 1)
>>> Since you may need to convert dates in several places in your code, you could make it a function. You can pass a Julian day or the filename. from datetime import datetime
def parseJulian(jdate):
dt = datetime.strptime(jdate, '%Y%j').date()
return(dt.year, dt.month, dt.day)
def extractJulian(filename):
jdate = filename.split(".")[1][1:] # get date portion, splitting on periods
dt = datetime.strptime(jdate, '%Y%j').date()
return(dt.year, dt.month, dt.day)
x = parseJulian('2017152')
print x[0] #year: 2017
print x[1] #month: 6
print x[2] #day: 1
x = extractJulian('MOD04_3K.A2017152.mosaic.061.2017271115004.pssgmcrpgs_000501268215.Corrected_Optical_Depth_Land_2-Corrected_Optical_Depth.Land.tif')
print x[0] #year: 2017
print x[1] #month: 6
print x[2] #day: 1 You could store this in your dictionary, with some code modification. Basically you would insert the filename with the date information as a tuple. Dictionary would look something like: { 2017: { 0 : [('longfilename', year, month, day),...],...}...}
... View more
10-07-2018
01:51 PM
|
1
|
0
|
3541
|
|
POST
|
Commas are needed at the end of the lines (for 2015, 2016 and 2017 - not needed for 2018 as this is the end of the dictionary), but this should work if the files are found in the directory search. rasters = { 2015: {1:[],2:[],3:[],4:[],5:[],6:[],7:[],8:[],9:[],10:[],11:[],12:[]},
2016: {1:[],2:[],3:[],4:[],5:[],6:[],7:[],8:[],9:[],10:[],11:[],12:[]},
2017: {1:[],2:[],3:[],4:[],5:[],6:[],7:[],8:[],9:[],10:[],11:[],12:[]},
2018: {1:[],2:[],3:[],4:[],5:[],6:[],7:[],8:[],9:[],10:[],11:[],12:[]}
} You can pass the year and month in the function call, but isn't out1 the name for the output file? See line 14 below, and it is being passed to the function. Its format is including the month and year. def Null_sc(input,output, year, month):
for ds in input:
# some code to process data
savename = "filename{}_{}".format(year,month)
# save data
# ........
for k1,v1 in rasters.iteritems():
year =k1
for k2,v2 in v1.iteritems():
if len(v2):
month =k2
out1= '{}Month{}_{}.img'.format(m3,month,year)
# print out1
mon1 = Null_sc_mean(v2, out1, year, month) # also pass year, month
... View more
10-07-2018
12:15 PM
|
1
|
0
|
3541
|
|
POST
|
See InsertCursor for some code examples. I agree with Joshua Bixby; you probably want to iterate through a dictionary to insert the keys/values into a shape file or feature. The flow would go like this: rhinoDict = {}
# read csv into rhino dictionary
for row in csvReader:
# code to build dictionary
# open an insert cursor
cursor = arcpy.da.InsertCursor(feature, fields)
# loop through the dictionary
for rhino in rhinoDict.iteritems():
# retrieve data from the dictionary
# organize and insert it into feature/shapefile
cursor.insertRow((data))
# delete cursor object
del cursor
# other steps to finish Be sure to include some print statements for debugging. You will probably want to print your rhino dictionary to see that it is in the expected format, that you are reading the correct values from it, etc.
... View more
10-06-2018
03:07 PM
|
1
|
0
|
3512
|
|
POST
|
The traceback error suggests that the "from datetime import datetime" did not execute properly. It may be a Python version, so I would suggest checking documentation for your version. Also, "from datetime import datetime" also imports only a section of the datetime module; so you wouldn't want to also "import datetime". This line takes a Julian date in the format YYYYJJJ and converts it to a date, then the month is extracted from the date before being converted to an integer. The section of code that it is in uses the year and month to insert the data into a dictionary of dictionaries. month = int(datetime.strptime(jdate, '%Y%j').date().strftime("%m")) This section reads the nested dictionary. The outer keys are the years, and the value are the dictionaries containing the months. When you iterate through the items in these values, you get the month keys and their corresponding values. In your case, it looks like you will pass the v2 list to your Null_sc_mean function. for k1,v1 in rasters.iteritems(): # k1 outer key (year), v1 outer values (month dictionaries)
print "Year: {}".format(k1)
for k2,v2 in v1.iteritems(): # k2 inner key (month), v2 inner values (file list)
if len(v2):
print "\tMonth: {}".format(k2)
for r in v2:
print '\t\t{}'.format(r) I haven't tested it yet, but the above section should become something like this: m3 = "G:\\ANFIS_FINAL\\AOD\\3KM_AOD\\01_18\\"
for k1,v1 in rasters.iteritems():
year =k1
for k2,v2 in v1.iteritems():
if len(v2):
month =k2
out1= '{}Month{}_{}.img'.format(m3,month,year)
# print out1
mon1 = Null_sc_mean(v2,out1) # not sure if mon1 is what you need I'm not sure what you intend to do with the variable mon1. As you will be looping through the months and years in file folder, this variable will be overwritten with each iteration. But since the Null_sc_mean returns None (there is no return value in that section of code) it is not important. However, you may want the function to return a success/fail code that you can check in this section. I haven't looked at the workings of the function that is being called. I'm still studying your code and it looks like you are trying to get the filenames organized into a series of lists. The dictionary approach simplifies it. I also noticed that you are trying to go through those lists at line 102, but I think you are missing some brackets. for ls in M01,M02,M03,M04,M05,M06,M07,M08,M09,M10,M11,M12:
# try (note the brackets):
for ls in [M01,M02,M03,M04,M05,M06,M07,M08,M09,M10,M11,M12]: When I am writing new code, I will have lots of print statements that will show the values of variables, etc. at various points in the code. As testing progresses, I will comment out the print statements and add additional code for testing. Hope this helps.
... View more
10-06-2018
11:56 AM
|
1
|
0
|
3541
|
| 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
|