|
POST
|
Try using "projectAs" as illustrated in line 11 below. A bit more of this example is shown here. import arcpy
# WGS 1984 : (4326) Lat/Lon
x = -122.478470
y = 37.819369
# If you know the reference numbers, you can use this:
# WGS 1984 : (4326) Lat/Lon
# WGS 1984 Web Mercator (auxiliary sphere) : (102100) or (3857)
ptGeometry = arcpy.PointGeometry(arcpy.Point(x,y),arcpy.SpatialReference(4326)).projectAs(arcpy.SpatialReference(3857))
print ptGeometry.JSON
print ptGeometry.firstPoint.X, ptGeometry.firstPoint.Y
... View more
04-03-2017
09:43 AM
|
0
|
0
|
1401
|
|
POST
|
My thoughts on your code is to replace lines 14 and 15 jData = json.dumps(output)
json.dump(output, jsonfile, indent=2, sort_keys=True) with this: # create a dictionary of features
jData = { "features" : None }
# output is a list of dictionaries, in this case features
# insert the list into the jData dictionary
jData["features"] = output
# save the jData dictionary to a json file
json.dump(jData, jsonfile, indent=2, sort_keys=True) You could combine the scripts, basically starting with the first 12 lines of your script (with the includes, etc.), then the six lines above, and finally including my script starting with line 12. You would end up with something like this: import csv
import json
csvfile = open('MyFile.csv', 'r')
reader = csv.DictReader(csvfile)
fieldnames = ('Name', 'Flow', 'Arrow Size', 'Date', 'Lat', 'Long', 'Heading', 'Color', 'Desciption', 'table')
output = []
for each in reader:
row = {}
for field in fieldnames:
if not field == 'Coords':
row[field] = each[field]
output.append(row)
jData = { "features" : None }
jData["features"] = output
# start the geojson file
geo = {
"type" : "FeatureCollection",
"crs" : { "type" : "name",
"properties" : {
"name" : "EPSG:4326"
}
},
"features" : None
}
feature_list = []
# loop through json
fCount = 0
for feature in jData['features']:
fCount +=1
features = {
"type" : "Feature",
"id" : fCount,
"geometry" : { "type" : "Point",
"coordinates" : [
float(feature["Lat"]), float(feature["Long"]) ]
},
"properties" : { "OBJECTID" : fCount,
"Name" : feature["Name"],
"Lat" : float(feature["Lat"]),
"Long" : float(feature["Long"]),
"Heading" : int(feature["Heading"])
}
}
feature_list.append(features)
# this part would be exported to tab/csv file
# for k, v in feature['table']:
# print str(fCount)+ '\t' + k + '\t' + v
geo["features"] = feature_list
# to write to a file
with open('result2.json', 'w') as fp:
json.dump(geo, fp)
... View more
03-31-2017
11:31 PM
|
1
|
1
|
9331
|
|
POST
|
I saved the json in your first message as a text file. In my code on line 7, I use json.loads to read the file into the jData variable. But as I am reading it, I appended '{ "features" : ' to the beginning and a closing '}' (with your json in the middle). This makes it a listing of features that one can easily loop through using "for feature in features". I'll explore the code in your last message when I have some additional time. I did make a modification on my code that uses dictionaries. It was a chance to do some exploring. import json
filename = r'input.json'
with open(filename, 'r') as fp:
# read json and add "features"
jData = json.loads('{ "features" : ' + fp.read().decode("utf-8-sig").encode("utf-8") + '}')
# dump the json data
# print json.dumps(jData, indent=4, sort_keys=False)
# start the geojson file
geo = {
"type" : "FeatureCollection",
"crs" : { "type" : "name",
"properties" : {
"name" : "EPSG:4326"
}
},
"features" : None
}
feature_list = []
# loop through json
fCount = 0
for feature in jData['features']:
fCount +=1
features = {
"type" : "Feature",
"id" : fCount,
"geometry" : { "type" : "Point",
"coordinates" : [
float(feature["Lat"]), float(feature["Long"]) ]
},
"properties" : { "OBJECTID" : fCount,
"Name" : feature["Name"],
"Lat" : float(feature["Lat"]),
"Long" : float(feature["Long"]),
"Heading" : int(feature["Heading"])
}
}
feature_list.append(features)
# this part would be exported to tab/csv file
# for k, v in feature['table']:
# print str(fCount)+ '\t' + k + '\t' + v
geo["features"] = feature_list
print json.dumps(geo)
# to write to a file
# with open('result.json', 'w') as fp:
# json.dump(geo, fp)
... View more
03-31-2017
02:26 PM
|
1
|
5
|
7076
|
|
POST
|
Here is some very rough code to give you an idea. import json
filename = r'input.json'
with open(filename, 'r') as fp:
# read json and add "features"
jData = json.loads('{ "features" : ' + fp.read().decode("utf-8-sig").encode("utf-8") + '}')
# print len(jData['features'])
# start the geojson file
print '{'
print ' "type" : "FeatureCollection",'
print ' "crs" :'
print ' {'
print ' "type" : "name",'
print ' "properties" :'
print ' {'
print ' "name" : "EPSG:4326"'
print ' }'
print ' },'
print ' "features" : ['
# loop through json
fCount = 0
for feature in jData['features']:
fCount +=1
print ' {'
print ' "type" : "Feature",'
print ' "id" : '+str(fCount)+','
print ' "geometry" :'
print ' {'
print ' "type" : "Point",'
print ' "coodinates" : ['
print ' '+feature["Lat"]+', '+feature["Long"]
print ' ]'
print ' },'
print ' "properties" : {'
print ' "OBJECTID" : '+str(fCount)+','
print ' "Name" : "'+feature["Name"]+'",'
print ' "Lat" : "'+feature["Lat"]+'",'
print ' "Long" : "'+feature["Long"]+'",'
print ' "Heading" : "'+feature["Heading"]+'"'
print ' }'
if fCount != len(jData['features']):
print ' },'
else:
print ' }'
# this part would be exported to tab/csv file
for k, v in feature['table']:
print str(fCount)+ '\t' + k + '\t' + v
# close geojson
print ' ]'
print '}'
... View more
03-31-2017
11:50 AM
|
1
|
9
|
7076
|
|
POST
|
I think you can loop through the json and create a well-formed geojson file. While doing the loop, you could pull out the table information and send it to a tab/csv file so it could be imported into your project as a related table.
... View more
03-31-2017
10:19 AM
|
1
|
10
|
7076
|
|
POST
|
Is this the tool you are wanting to use? Change Version
... View more
03-29-2017
01:11 PM
|
1
|
2
|
3768
|
|
POST
|
AGOL uses UTC time by default. Collector will convert the date/time using the computer or phone's date settings. But to correct the date and time in the downloaded data, you will need to add/subtract your time offset from UTC. Search AGOL or ArcMap help documentation for "geodatabase time". You also indicated that the field name is "DATE". Field names should not use SQL reserved words. If you want it to show up in Collector as "DATE", you can use the description/alias for this purpose.
... View more
03-28-2017
05:31 PM
|
1
|
0
|
970
|
|
POST
|
See the script in this thread for an idea: query-minimum-date-using-rest-service. Note the comment on line 35. You would use the EditDate field. Have you checked this page: Sync workflow examples? The topic Workflow Example 4: Setting up sync using LayerQueries contains this: "layerQueries": {
"1": {
"queryOption": "useFilter",
"useGeometry": false,
"where": "region = 'Southwest'"
}
}, The "where" would be edited to something like: "where" : "EditDate >= DATE '2016-05-29 18:30:00'"
... View more
03-28-2017
11:46 AM
|
0
|
0
|
948
|
|
POST
|
I'm sorry. I have not used Portal. For AGOL the path to the layer definition update page uses something like: http<s>://services.arcgis.com/<abc123>/arcgis/rest/admin/services/<featuer layer>/FeatureServer/<layer id>/updateDefinition Should you be using a slash instead of a dash? 'UAT_FieldObsCapture/FeatureServer'
... View more
03-24-2017
10:25 AM
|
0
|
0
|
4128
|
|
POST
|
What script/code are you using? Something like: mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
print "\n\nLayer Name: " + lyr.name
# Create a describe object
desc = arcpy.Describe(lyr)
# If a feature layer, continue
if desc.dataType == "FeatureLayer":
# Create a fieldinfo object
field_info = desc.fieldInfo
# Use the count property to iterate through all the fields
for index in range(0, field_info.count):
# Print fieldinfo properties
print("Field Name: {0}".format(field_info.getFieldName(index)))
print("\tNew Name: {0}".format(field_info.getNewName(index)))
print("\tSplit Rule: {0}".format(field_info.getSplitRule(index)))
print("\tVisible: {0}".format(field_info.getVisible(index)))
Based on FieldInfo page. It does appear that some fields like OBJECTID, SHAPE will show as VISIBLE even if turned off. Perhaps it relates to geometry properties and the @ token??
... View more
03-23-2017
10:23 PM
|
1
|
1
|
2364
|
|
POST
|
In your code in line 11: with arcpy.da.UpdateCursor(fc, "Count", sql) as ucur:
"Count" is an SQL reserved word and should not be used as a field/column name.
... View more
03-23-2017
03:07 PM
|
1
|
0
|
3783
|
|
POST
|
Perhaps creating a dictionary for the domain might help. There is some discussion in this old thread: How can I get the description value of a field that has a domain? Then you might be able to replace domain descriptions used in the VB code block with the equivalent domain code.
... View more
03-21-2017
09:59 AM
|
0
|
1
|
3749
|
|
POST
|
You should see json in the text box. Again, I am using AGOL, so my screen is slightly different. Where yours says "Input", mine says "Update Layer Definition". On the preceding page (the one with the link "Update Definition" at the bottom), is there text that describes the feature/table? At the top of that page, is there a link for "JSON"?
... View more
03-20-2017
09:52 AM
|
0
|
0
|
9838
|
|
POST
|
I've used this code in the Python window inside ArcMap. You may need to adjust around lines 40-41 if the VB code from the label expression isn't well formatted. mxd = arcpy.mapping.MapDocument("CURRENT") # reference document open in ArcMap
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("LABELCLASSES"):
print "\n\nProcessing Layer: " + lyr.name
# check for label class expression
lblExp = ""
lblType = "Other"
for lblClass in lyr.labelClasses:
lblExp = lblClass.expression
if len(lblExp):
if "Function FindLabel" in lblExp:
lblType = "VB"
print "VB expression found"
elif "def FindLabel" in lblExp:
lblType = "PYTHON_9.3" # assuming later version of ArcMap
print "Python expression found"
elif "function FindLabel" in lblExp:
lblType = "JScript" # Field Calculator does not use JScript
print "JScript expression found"
if lblType == "VB": # just working with VB for now
add_field = True # plan to add field for TextLabel
layerFields = arcpy.ListFields(lyr)
for fld in layerFields:
if fld.name in ['TextLabel']:
add_field = False # no need to add field
if add_field:
print "Adding field: TextLabel"
arcpy.AddField_management(in_table=lyr,
field_name="TextLabel",
field_type="TEXT",
field_length="50",
field_alias="Text Label",
field_is_nullable="NULLABLE",
field_is_required="NON_REQUIRED")
# delete first and last line of VB code block
lblExp = lblExp.strip()
calcExp = lblExp[lblExp.find('\n')+1:lblExp.rfind('\n')].strip()
print calcExp
arcpy.CalculateField_management(in_table=lyr,
field="TextLabel",
expression="FindLabel",
expression_type="VB",
code_block=calcExp)
... View more
03-18-2017
09:45 PM
|
3
|
4
|
3749
|
|
POST
|
When a pop-up is configured in AGOL to display date and 24 hour time with seconds, the time does not display in Collector. Time will display if set-up for 24 hour without seconds or using an AM/PM display with seconds. I have experienced this bug with previous versions of Collector with both iOS and Android systems. The current bug is with Collector 10.4.2 build 1026 for Android. I have not tested other versions at this time.
... View more
03-18-2017
07:42 PM
|
0
|
0
|
795
|
| 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
|