anyone using ChatGPT yet?

8293
16
12-18-2022 11:30 PM
BertKraan1
Occasional Contributor III

I'm trying AI ChatGPT, impressive:

BertKraan1_0-1671434869517.png

Keep in mind i'm using natural language and this was it's first response. As a single gis person in my company all assistance is welcome.

(https.openai.com)

16 Replies
BertKraan1
Occasional Contributor III

and then I asked: "can you write a python script to backup all layers in an arcgis online organisation"

response was:

 

import requests
import json

# Set the base URL for the ArcGIS REST API
base_url = "https://www.arcgis.com/sharing/rest"

# Set the organization's name and the username and password of an account with privileges to access the organization's content
org_name = "your_organization_name"
username = "your_username"
password = "your_password"

# Use the ArcGIS REST API to authenticate the user and get an access token
auth_url = f"{base_url}/generateToken"
auth_params = {
"username": username,
"password": password,
"client": "referer",
"referer": f"https://{org_name}.maps.arcgis.com",
"f": "json"
}
auth_response = requests.post(auth_url, auth_params)
auth_response_json = auth_response.json()
access_token = auth_response_json["token"]

# Use the ArcGIS REST API to search for all layers in the organization
search_url = f"{base_url}/search"
search_params = {
"q": "type:\"layer\" AND owner:{org_name}",
"token": access_token,
"f": "json"
}
search_response = requests.get(search_url, search_params)
search_response_json = search_response.json()

# Iterate through the search results and download each layer
for result in search_response_json["results"]:
# Get the layer's ID and URL
layer_id = result["id"]
layer_url = result["url"]

# Use the ArcGIS REST API to export the layer as a GeoJSON file
export_url = f"{base_url}/content/items/{layer_id}/data"
export_params = {
"token": access_token,
"f": "geojson"
}
export_response = requests.get(export_url, export_params)

# Save the GeoJSON file to a local file
with open(f"{layer_id}.geojson", "w") as f:
f.write(export_response.text)

 

 

And it ended with 

BertKraan1_0-1671435654652.png

 

 


 


 

0 Kudos
Brian_Wilson
Occasional Contributor III

I am looking forward to playing with it. In your example, it seems like Duck Duck Go!! Does it give links to the pages that it copied the content from or is it like a college student?

Can you ask it for maps?

In a month or so every automated support chat engine will be using ChatGPT and still delivering the same  information. (I want to say "useless information" but I want to be nice, so I don't end up on the Bad Santa List.)

 

0 Kudos
piratecheese
New Contributor III

It's like a college student in that it assumes everything is common knowledge, asserts it already personally knew everything  and wings it without having to reference anything

ChrisJRoss13
New Contributor III

I have been using ChatGPT quite often over the last couple weeks. I find that it is partially a hit or miss with developing python code for GIS (specifically ArcGIS). For example in the arcpy.mp submodule, it will develop code references where the submodule components don't even exist. On the other hand, I have had it assist me with a couple coding problems either to get started and to improve my overall code and I have found it has done a good job.

I imagine this will only get better over time.

Good luck!

piratecheese
New Contributor III

I always told myself I'm lazy but in order to achieve peak laziness and offload coding to chat GPT, I have to log in during off peak hours and remote in from home. I don't know If It's good I'm working more or bad that I'm spending all day at the office wishing I was home so I could get work done.

Currently trying to get it to make a geoprocessing script to run CAD to Geodatabase, then run Spit by Attribute on the resulting feature classes. The biggest issue I'm running into is passing along my parameters to the person using the tool.

UPDATE:

For clarity, I've only ever done Visual Basic, Excel functions and a bit of arcade label engine coding. Importing libraries is a concept that scares me, but I'm familiar with the concept of syntax, variables and looking through documentation. GPT has given me a broken skeleton I can fix and in doing so, I feel more confident that I can code my own expressions from scratch if needed.

This code is mostly generated with chat GPT but I had to do a lot of digging to figure out what it did wrong to get to this point and I know there's a lot of looping that could be done with Feature_Type_Array="Point","Line"...

 

The code (parameters in picture):

 

import arcpy
import os

# Get user-defined parameters
input_cad_dataset = arcpy.GetParameterAsText(0) # CAD dataset
new_gdb_loc = arcpy.GetParameterAsText(1) # Output geodatabase location
prefix_name = arcpy.GetParameterAsText(2) # Prefix for gdb names

# Define placeholder geodatabase
placeholder_gdb = prefix_name + "_PLACEHOLDER.gdb"

# Create a new geodatabase for each feature class
annotation_gdb = prefix_name + "_Annotation"
multipatch_gdb = prefix_name + "_MultiPatch"
point_gdb = prefix_name + "_Point"
polygon_gdb = prefix_name + "_Polygon"
polyline_gdb = prefix_name + "_Polyline"


arcpy.CreateFileGDB_management(new_gdb_loc, annotation_gdb)
arcpy.CreateFileGDB_management(new_gdb_loc, multipatch_gdb)
arcpy.CreateFileGDB_management(new_gdb_loc, point_gdb)
arcpy.CreateFileGDB_management(new_gdb_loc, polygon_gdb)
arcpy.CreateFileGDB_management(new_gdb_loc, polyline_gdb)
arcpy.CreateFileGDB_management(new_gdb_loc, placeholder_gdb)

#make a path for each 
placeholder_gdb_path = os.path.join(new_gdb_loc, placeholder_gdb)

#the results of cad to geodatabase will be here. split by attibute aims here
pre_Annotation_path = os.path.join(placeholder_gdb_path + "\\" + prefix_name, "Annotation")
pre_Point_path = os.path.join(placeholder_gdb_path + "\\" + prefix_name, "Point")
pre_Polyline_path = os.path.join(placeholder_gdb_path + "\\" + prefix_name, "Polyline")
pre_Polygon_path = os.path.join(placeholder_gdb_path + "\\" + prefix_name, "Polygon")
pre_Multipatch_path = os.path.join(placeholder_gdb_path + "\\" + prefix_name, "Multipatch")


#the results of split by attribute dump here into the new databases
post_Annotation_path = os.path.join(new_gdb_loc, prefix_name + "_Annotation.gdb")
post_Point_path = os.path.join(new_gdb_loc, prefix_name + "_Point.gdb")
post_Polyline_path = os.path.join(new_gdb_loc, prefix_name + "_Polyline.gdb")
post_Polygon_path = os.path.join(new_gdb_loc, prefix_name + "_Polygon.gdb")
post_Multipatch_path = os.path.join(new_gdb_loc, prefix_name + "_Multipatch.gdb")


# Convert the CAD file to a feature class
arcpy.CADToGeodatabase_conversion(input_cad_dataset, placeholder_gdb_path, prefix_name,1000)


# Set the workspace to the placeholder geodatabase
arcpy.env.workspace = placeholder_gdb

# Split the feature classes by Layer
arcpy.SplitByAttributes_analysis(pre_Annotation_path, post_Annotation_path, "Layer")
arcpy.SplitByAttributes_analysis(pre_Multipatch_path, post_Multipatch_path, "Layer")
arcpy.SplitByAttributes_analysis(pre_Point_path,post_Point_path , "Layer")
arcpy.SplitByAttributes_analysis(pre_Polyline_path, post_Polyline_path, "Layer")
arcpy.SplitByAttributes_analysis(pre_Polygon_path, post_Polygon_path, "Layer")

 

 

Chat GPT has a few problems. There's the lack of loop awareness, placing default argument inputs from documentation in as an expression within a function's argument, occasional use of variables before they get defined, it stops mid code sometimes and it has difficulty explaining some concepts like setting parameters to new users.

To a user unfamiliar with arcpy and script tools, It can be difficult to know what GPT wants you to set for parameters, or even how to set parameters in Pro (script properties). In fact it's methodology for setting up parameters is wonky. 

example:

 

arcpy.management.CreateFileGDB(out_folder_path, out_name, {out_version})

 

is the given syntax from documentation. The code it gives me is:

 

import arcpy
new_gdb_loc = arcpy.GetParameterAsText(1) # Output geodatabase location
prefix_name = arcpy.GetParameterAsText(2) # Prefix for gdb names

arcpy.management.CreateFileGDB(out_folder_path=new_gdb_loc, out_name=prefix_name, out_version=1000)

 

which gives errors  "out_folder_path variable undefined" which I was able to squish easy once I knew what was wrong.

In conclusion: I'll be using GPT more, but I'm never going to expect it to give me something correct the first time. I need to use my human brain to spot it's mistakes, but once I do, it's a lot more than what I could do by myself before and I can do a lot more by myself after now.

TarigAhmed3
New Contributor II

I found this on LinkedIn the other day, and thought might add to this discussion - Credit: Jeremy Mirmelstein)

Jeremy Mirmelstein• 2ndSr. Solution Architect | Technical Lead | Team Lead @ Esri

1d • 1 day ago
Follow
 
Things are about to get super weird at work... #gis #esri #chatgpt #python #arcgis

Me to ChatGPT: "Please write a python script using the ArcGIS Python API to query for all users in an ArcGIS Online organization"
TarigAhmed3_1-1674687747391.png

 

0 Kudos
MartinPaulMollenhauer
New Contributor II

We are just starting to get familiar with the capabilities of Chat GPT in my organization.

An area where the program has been absolutely excellent in is writing legal disclaimers for our various maps and applications. I have also asked the chat bot to write a GIS strategic plan, give recommendations on the best python IDE for GIS, developing a project timeline for migration from arc map to pro, and much much more. 

Our first experiment with testing it's python skills will be coming up in a week or 2, when we deploy the script it wrote to scan our enterprise geodatabases and generate and xml metadata files for all of our feature classes. I'm feeling cautiously optimistic on the coding experiment so far. Hopefully we will have good news to report back with.

WStreet
New Contributor III

Have you tried this yet?  I was just thinking about this on my 6 hour drive home on Friday.  I am planning on looking into it this month.

0 Kudos
AndrewRegnery
New Contributor

I am also interested in this. Would love to hear the results.

0 Kudos