Replying to Avatar Nunya Bidness

ChatGPT-4 works for getting data out of GIS using SQL.

I'm not surprised but being able to query the databases leveraged by arcGIS, ERDAS etc. in natural language seems . . . useful.

Me: Please write a query for arcGIS that locates all single-family dwellings no more than 1/2 mile from a US Interstate and within 5 miles of a hospital

ChatGPT-4: Certainly! Here's a query for ArcGIS that locates all single-family dwellings within a 1/2 mile radius from a US Interstate and within a 5-mile radius of a hospital:

SELECT single_family_dwellings.*

FROM single_family_dwellings, interstate_roads, hospitals

WHERE ST_Distance(single_family_dwellings.geometry, interstate_roads.geometry) <= 0.5 AND ST_Distance(single_family_dwellings.geometry, hospitals.geometry) <= 5;

In this query, you'll need to replace single_family_dwellings with the name of your single-family dwellings dataset or table, interstate_roads with the name of your US Interstate roads dataset or table, and hospitals with the name of your hospitals dataset or table.

The ST_Distance function is used to calculate the distance between the geometries of the single-family dwellings, interstate roads, and hospitals. The query checks if the distance between the single-family dwelling and the interstate road is less than or equal to 0.5 (indicating it is within a 1/2 mile radius) and if the distance between the single-family dwelling and the hospital is less than or equal to 5 (within a 5-mile radius).

Make sure you have the necessary spatial extensions and spatial data loaded into your ArcGIS environment to execute this query successfully.

Not sure about the ArcGIS implementation because I’ve only ever used OSS GIS tools, but usually ST_Distance is highly dependent on the SRS in use. If you ask ChatGPT about ST_Distance and what SRSs it returns miles for, it knows it is often more complicated. But it often gets these sorts of details wrong when generating specific SQL queries.

Reply to this note

Please Login to reply.

Discussion

That very well may be. I don't have access to arcGIS to test the query out on. I used to . . . and I miss it, but it is what it is.

Still, I think that anytime someone uses CGPT and doesn't test the results and then refine the query, test again (rinse and repeat) then they are not using the tech correctly.

The fact that it returned something I'm used to seeing after a single question and a reference to arcGIS is kind of amazing.

Relying on a single answer will definitely cause problems but that, I think, is fixed with a longer back and forth. By 'fixed' I mean a 'fruitful, ongoing conversation.

Did that make sense? It's late and beer is involved so I'm not sure.

I agree completely. It’s amazing how much it can reduce the friction of getting close to the right answer. And even when it gets a detail wrong it can often help you find the solution. In the rare cases it is completely clueless, it still lets you focus on just the stuff it can’t do rather than all the boilerplate and noise.

I just noticed a mention of ST_Distance and had flashbacks and wanted to warn you in case it was something important.🤣 Didn’t intend to refute your otherwise very good point.

Have you ever used QGIS? If so . . . thoughts? Any other, quality OSS GIS you might recommend?

Yes, we use QGIS instead of Arc for basic GIS debugging and manipulation. My non-technical partners and employees use it to manipulate shape files to make them compatible with formats we support for imports etc. And I regularly use QGIS to help understand random GIS data we get. It lets me overlay GIS data on a Google Map base layer very easily which is often helpful.

Most of the GIS stuff we do uses programming libraries that leverage gdal/ogr/proj - basically the same stuff QGIS is built on.

We also use MySQL and its limited spatial functionality. We use PostGIS and SpatiaLite too. SpatiaLite can be a great way to get a lot of data into QGIS in a form that can be queried pretty efficiently.

The interface reminds me of ESRI and ERDAS stuff so I think I'll dive into it. Thanks for reminding me that there is a FOSS for everything.