POST
|
Haha.. Can i give the points to David please? I just swooped in to fix a dictionary issue and don't deserve the correct answer points.
... View more
02-21-2020
01:54 PM
|
0
|
0
|
626
|
POST
|
Jason, don't forget to give credit to David since he did all of the heavy lifting. Plus I'm sure he would like the points for a correct answer. Have a good weekend!
... View more
02-21-2020
01:44 PM
|
0
|
0
|
626
|
POST
|
David, With your previous code it was updating rows with Null or None Geometry to the matching rows that contained geometry. I updated your code to exclude the "None" geometry type from the dictionary so there wouldn't be an accidental overwrite to features that contained geometry. import arcpy
inFC = r""
inFields = ['Unique_ID', 'SHAPE@']
#valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(inFC, inFields)}
valueDict = {}
for r in arcpy.da.SearchCursor(inFC, inFields):
if r[1] == None:
pass
else:
valueDict[r[0]] = r[1:]
print(valueDict)
with arcpy.da.UpdateCursor(inFC, inFields) as updateRows:
for updateRow in updateRows:
keyValue = updateRow[0]
print(keyValue)
if keyValue in valueDict:
updateRow[1] = valueDict[keyValue][0]
print(valueDict[keyValue][0])
updateRows.updateRow(updateRow)
print("Updated {}".format(keyValue))
... View more
02-21-2020
01:22 PM
|
2
|
0
|
626
|
POST
|
Try this script. I just tested it and it should work for you. However just as a word of warning if you are running this on a large dataset this script will probably start to run pretty slow. The reason for this is because I have nested cursors, which isn't the most pythonic thing to do. I tried to load the information from the search cursor into a dictionary however I was having issues comparing the SHAPE objects from the dictionary. If you are running this on a large dataset let me know and I will change the script to the pythonic way so it wont bog down. Hope this helps: import arcpy
########################################################################################################################
# Variables
########################################################################################################################
print("\nSetting Variables\n")
layerToAddTo = "Path to layer to add matchind Id's"
layerToPullFrom = "Path to other layer with matching geom"
########################################################################################################################
# This finds the matching geom in both featureclass then updates the ID column in the layerToAddTo with the ID's
# from the matching geom features
########################################################################################################################
print("Finding the matching geom and combining the ID's")
for searchCur in arcpy.da.SearchCursor(layerToPullFrom, ["ID", "SHAPE@"]):
with arcpy.da.UpdateCursor(layerToAddTo, ["SHAPE@", "ID"]) as upCursor:
for updateRow in upCursor:
value1 = updateRow[0]
if value1.equals(searchCur[1]):
updateRow[1] = "{}, {}".format(updateRow[1], searchCur[0])
upCursor.updateRow(updateRow)
... View more
02-07-2020
01:46 PM
|
1
|
1
|
949
|
POST
|
Dan you are correct. ArcMap's default install path ( At least on my machine ) is: C:\Python27\ArcGIS10.5\python.exe For Pro, the path to python for my machine is: C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe Yves, have you tried a full uninstall and reinstall of arcmap?
... View more
02-06-2020
07:00 AM
|
0
|
0
|
3664
|
POST
|
So I figured out the issue. I had a bonehead moment. I try to test every script I give to people to make sure it works. So after pulling the needed code out of one of my other scripts and editing it to give to you. I forgot to save the completed version that worked and ended up copying over the non-working version. I just retested it and fixed the issue. My apologies about that. If you want to revisit the code again below is the working version. import arcgis
########################################################################################################################
# Variables
########################################################################################################################
agoLogin = arcgis.GIS(url=None,
username="Your ArcGIS Online Login Name",
password="Your Paassword")
itemToDownload = agoLogin.content.get("Add the Item ID of the feature layer for the survey")
exportLoc = r"Path to the folder where you want to save the excel file"
itemExportName = "Name of the excel file. Make it unique"
########################################################################################################################
# Export the ArcGIS Online Item
########################################################################################################################
itemToDownload.export(title=itemExportName,
export_format="Excel",
parameters=None,
wait=True)
########################################################################################################################
# Search for and get the Newly Exported Item
########################################################################################################################
searchForExportedItem = agoLogin.content.search(query=itemExportName)
exportedItemID = searchForExportedItem[0].id
getTheExportedItem = agoLogin.content.get(exportedItemID)
########################################################################################################################
# Download the Newly Exported Item
########################################################################################################################
getTheExportedItem.download(save_path=exportLoc,
file_name="{}.xlsx".format(itemExportName))
... View more
01-31-2020
10:43 AM
|
1
|
2
|
5634
|
POST
|
So it looks like you are inputting the Item ID for the actual survey form. When you create and publish a survey to ArcGIS Online it will create a folder for your survey. Within that folder you will see a "Form" and a "Feature Layer" that should have the exact same name. You want to use the Item ID for the feature layer. You probably already know how to find the feature layer's Item ID but just in case, Go to ArcGIS Online and login. Then go to "Content" then on the left hand side under "Folders" double click on the Folder for the survey you would like to export the Excel File from. Within that folder you should see a "Form" and "Feature Layer" that have matching names. Click on the feature layer to open its "Overview" page. The Item ID will be located at the end of the URL in your web browser. Here is an example of the full url: https://yourpage.arcgis.com/home/item.html?id=642f9c5b85e64788a6b2b5418dd61320 You want all of the numbers and letters after the equals sign and your Item ID should look something like this: 642f9c5b85e64788a6b2b5418dd61320 Hope This Helps
... View more
01-31-2020
09:23 AM
|
0
|
1
|
5634
|
POST
|
I'm sorry I thought I renamed all of the variables. it should be itemToDownload.export(title="Title / Name of the export. This will show up in ArcGIS Online",
export_format="Excel",
parameters=None,
wait=True)
... View more
01-30-2020
01:33 PM
|
0
|
3
|
5634
|
POST
|
Python 3x, arcpy and all of its necessary modules should have already been installed on the machine when you installed ArcGIS Pro. You can check this by launching ArcGIS Pro, go to settings then to python and you can see the installed packages and also the path to the python environment. To download an item from ArcGIS Online you will need to use the ArcGIS API for python. Essentially all you do is create a GIS connection (To ArcGIS Online): arcgis.gis module — arcgis 1.7.0 documentation Then you will get the service item by using content.get and the item ID: arcgis.gis module — arcgis 1.7.0 documentation Then you will export the item to an excel compatible format like CSV or xls by using .export: arcgis.gis module — arcgis 1.7.0 documentation Next you will download the exported item: arcgis.gis module — arcgis 1.7.0 documentation Then you can use XlsXWriter or CSV module to edit and change things around to how you want it. Below is an example on how to export from ArcGIS Online. I didn't add in any code for the editing of the excel. import arcgis
########################################################################################################################
# Variables
########################################################################################################################
agoLogin = arcgis.GIS(url="URL to your ArcGIS Portal use none if to ArcGIS Online",
username="Your User Name",
password="Your Password")
itemToDownload = agolLogin.content.get("The Item ID")
exportLoc = r"The path where you want the file to download to"
itemExportName = "The Name of the Exported Item"
########################################################################################################################
# Export the ArcGIS Online Item
########################################################################################################################
farmParcelLayer.export(title="Title / Name of the export. This will show up in ArcGIS Online",
export_format="Excel",
parameters=None,
wait=True)
########################################################################################################################
# Search for and get the Newly Exported Item
########################################################################################################################
searchForExportedItem = agolLogin.content.search(query=itemExportName)
exportedItemID = searchForExportedItem[0].id
getTheExportedItem = agolLogin.content.get(exportedItemID)
########################################################################################################################
# Download the Newly Exported Item
########################################################################################################################
getTheExportedItem.download(save_path=exportLoc)
... View more
01-30-2020
11:38 AM
|
0
|
5
|
5634
|
POST
|
I have created a simple script and tool. Let me know if this produces the results you are looking for. If not then we will get more complex in the processes. Below is the source code and I will post a link for you to download the toolbox with the code when I get home tonight. import arcpy
########################################################################################################################
# Variables
########################################################################################################################
layerToAppendGeom = arcpy.GetParameterAsText(0)
layerWithNewGeom = arcpy.GetParameterAsText(1)
newGeomDict = {r[0]:[r[1]] for r in arcpy.da.SearchCursor(layerWithNewGeom, ["APN", "SHAPE@"])}
########################################################################################################################
with arcpy.da.UpdateCursor(layerToAppendGeom, ["APN", "SHAPE@"]) as upCursor:
for updateRow in upCursor:
value1 = updateRow[0]
if value1 in newGeomDict:
updateRow[1] = newGeomDict[value1][0]
upCursor.updateRow(updateRow)
exit()
... View more
01-28-2020
12:39 PM
|
1
|
0
|
553
|
POST
|
Sounds good. When you get a chance can you post the field names for Layer A from the file geodatabase.
... View more
01-28-2020
10:17 AM
|
0
|
3
|
553
|
POST
|
You can append to a CSV file using python. There are quite a few tutorials you can find on google that will walk you through how to work with CSV files. https://realpython.com/python-csv/ Not sure if that answers your question.
... View more
01-28-2020
09:41 AM
|
0
|
0
|
2733
|
POST
|
Are you able to export the information in the SQL database to a File Geodatabase? The reason why I'm asking is because I'm reluctant to write code to change information in a SQL database that could be a production database that other services or applications might depend on. If you were able to export the information into a File Geodatabase we could essentially use that as a test / development database that wouldn't impact anything if something goes wrong. Then once all of the changes have been made and deemed correct you could talk to your DBA about pushing those updates to the SQL database. Maybe I'm over reacting, however this is how we set up things like this where I work. We setup a Development / Staging Environment then push it to the production environment once everything has been vetted as correct.
... View more
01-28-2020
09:22 AM
|
1
|
5
|
991
|
POST
|
Do you by any chance know what flavor of DB layer A is stored in? MS SQL?
... View more
01-27-2020
12:40 PM
|
0
|
7
|
991
|
POST
|
Alright. So the attribute information for the polygon with the largest area after the clip is what you would still keep. If it feels like we are talking in circles, my apologies. Just wanted to make sure I fully understand and to make sure there wasn't possibly an easier solution. Are you able to share the field names for original layer and the new boundary layer? Tonight Ill start writing up a tool for you to use in pro.
... View more
01-27-2020
10:22 AM
|
0
|
9
|
991
|
Title | Kudos | Posted |
---|---|---|
1 | 10-28-2019 12:03 PM | |
2 | 10-28-2019 10:47 AM | |
1 | 01-31-2020 10:43 AM | |
1 | 12-20-2019 10:37 AM | |
2 | 01-24-2020 01:33 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|